import{__assign as e,__spreadArray as r}from"tslib";import{version as t}from"eslint/package.json";import{isJsxNode as n,arrayify as s,DEFAULT_EXTENSIONS as i,MARKDOWN_EXTENSIONS as o,last as a}from"eslint-mdx";import c from"eslint/lib/rules/no-unused-expressions";import l from"path";import u from"vfile";import{cosmiconfigSync as m}from"cosmiconfig";import f from"remark-mdx";import p from"remark-parse";import d from"remark-stringify";import g from"unified";var v={parser:"eslint-mdx",plugins:["mdx"],processor:"mdx/remark"},x={parserOptions:{ecmaFeatures:{impliedStrict:!0}},rules:{"eol-last":"off","no-undef":"off","no-unused-expressions":"off","no-unused-vars":"off","padded-blocks":"off",strict:"off","unicode-bom":"off"}},h=e(e({},v),{globals:{React:"readonly"},rules:{"lines-between-class-members":0,"react/jsx-no-undef":[2,{allowGlobals:!0}],"react/react-in-jsx-scope":0}}),y=+t.split(".").slice(0,2).join("."),k=e(e({},v),{rules:{"mdx/no-jsx-html-comments":2,"mdx/no-unused-expressions":2,"mdx/remark":1,"no-unused-expressions":0}});if(y>=6.4){var b=[{files:"*.mdx",extends:"plugin:mdx/overrides"},{files:"**/*.{md,mdx}/**",extends:"plugin:mdx/code-blocks"}];try{require.resolve("prettier"),require.resolve("eslint-plugin-prettier"),b.push({files:"*.md",rules:{"prettier/prettier":[2,{parser:"markdown"}]}})}catch(e){}Object.assign(k,{overrides:b})}var j,S=function(e,r){return void 0===r&&(r={}),(Array.isArray(e)?e:Object.keys(e)).reduce((function(e,r){var t;return Object.assign(e,((t={})[r]=!1,t))}),r)},w={base:v,"code-blocks":x,codeBlocks:x,overrides:h,recommended:k},I={meta:{type:"problem",docs:{description:"Forbid invalid html style comments in jsx block",category:"SyntaxError",recommended:!0},messages:{jsxHtmlComments:"html style comments are invalid in jsx: {{ origin }}"},fixable:"code"},create:function(e){return{ExpressionStatement:function(r){var t=e.parserServices.JSXElementsWithHTMLComments;if(n(r.expression)&&"Program"===r.parent.type&&t&&0!==t.length){var s=t.shift();if(!s.data.inline)for(var i=function(t,n,s){e.report({messageId:"jsxHtmlComments",data:{origin:s},loc:n,node:r,fix:function(e){return e.replaceTextRange([n.start.offset,n.end.offset],t)}})},o=0,a=s.data.comments;o<a.length;o++){var c=a[o];i(c.fixed,c.loc,c.origin)}}}}}},C=e(e({},c),{create:function(e){var r=c.create(e);return{ExpressionStatement:function(e){n(e.expression)&&"Program"===e.parent.type||r.ExpressionStatement(e)}}}}),O=function(e,r,t){t&&/^\.\.?([/\\]|$)/.test(e)&&(e=l.resolve(l.dirname(t),e)),r=r.endsWith("-")?r:r+"-";for(var n,s=0,i=[e,e.startsWith("@")?e.replace("/","/"+r):r+e];s<i.length;s++){var o=i[s];try{return require(o)}catch(e){n||(n=e)}}throw n},E=g().use(p).freeze(),L=function(e,t){var n;j||(j=m("remark",{packageProp:"remarkConfig"}).search);try{n=j(e)}catch(r){if("ENOTDIR"!==r.code||!/[/\\]\d+_[^/\\]*\.[\da-z]+$/i.test(e))throw r;try{n=j(l.dirname(e))}catch(e){throw r}}var i=(null==n?void 0:n.config)||{},o=i.plugins,a=void 0===o?[]:o,c=i.settings;try{a.push([require.resolve("remark-lint-file-extension"),!1])}catch(e){}var u=E().use({settings:c}).use(d);return t&&u.use(f),a.reduce((function(e,t){var i=s(t),o=i[0],a=i.slice(1);return e.use.apply(e,r(["string"==typeof o?O(o,"remark",n.filepath):o],a))}),u).freeze()},M={meta:{type:"layout",docs:{description:"Linter integration with remark plugins",category:"Stylistic Issues",recommended:!0},fixable:"code"},create:function(r){var t=r.getFilename(),n=l.extname(t),s=r.getSourceCode(),a=r.parserOptions,c=i.concat(a.extensions||[]).includes(n),m=o.concat(a.markdownExtensions||[]).includes(n);return{Program:function(n){if(c||m){var i=s.getText(n),o=L(t,c),a=u({path:t,contents:i});try{o.processSync(a)}catch(e){a.messages.includes(e)||(a.message(e).fatal=!0)}for(var l=function(t,s,a,c,l,u){var m=c?2:null==c?0:1;if(!m)return"continue";var f={reason:s,source:t,ruleId:a,severity:m};r.report({message:JSON.stringify(f),loc:{start:e(e({},l),{column:l.column-1}),end:e(e({},u),{column:u.column-1})},node:n,fix:function(e){if(null==l.offset)return null;var r=[l.offset,null==u.offset?l.offset+1:u.offset],t=i.slice.apply(i,r),n=o.processSync(t).toString();return e.replaceTextRange(r,t.endsWith("\n")?n:n.slice(0,-1))}})},f=0,p=a.messages;f<p.length;f++){var d=p[f],g=d.source,v=d.reason,x=d.ruleId,h=d.fatal,y=d.location;l(g,v,x,h,y.start,y.end)}}}}}},q={"no-jsx-html-comments":I,"no-unused-expressions":C,noJsxHtmlComments:I,noUnusedExpressions:C,remark:M},T=new Set(["eol-last","unicode-bom"]),A={};function H(e,r,t){if(r[e.type]&&r[e.type](e,t),void 0!==e.children)for(var n=e,s=0,i=n.children;s<i.length;s++){H(i[s],r,n)}}function J(e){var r="\x3c!--",t="--\x3e";if(e.slice(0,r.length)!==r||e.slice(-t.length)!==t)return"";var n=e.slice(r.length,-t.length);return/^(eslint\b|global\s)/u.test(n.trim())?n:""}var N=/^[>\s]*/u;function P(e){return e.position.start.offset-e.position.start.column+1}function R(e,r){return N.exec(e.slice(P(r)))[0]}function W(e,r,t){for(var n=P(r),s=e.slice(n,r.position.end.offset).split("\n"),i=R(e,r).length,o=[{js:0,md:0}],a=t.reduce((function(e,r){return e+r.length+1}),0),c=n+s[0].length+1,l=0;l+1<s.length;l++){var u=s[l+1],m=N.exec(u)[0].length,f=Math.min(i,m);o.push({js:a,md:c+f-a}),c+=u.length+1,a+=u.length-f+1}return o}function z(e){return e&&!T.has(e.ruleId)}var B={preprocess:function(t,n){var s=E.parse(t),i=[];return A[n]=i,H(s,{code:function(r,n){var s=[];if(r.lang){for(var o=n.children.indexOf(r)-1,a=n.children[o];a&&"html"===a.type;){var c=J(a.value);if(!c)break;if("eslint-skip"===c.trim())return;s.unshift("/*"+c+"*/"),o--,a=n.children[o]}i.push(e(e({},r),{baseIndentText:R(t,r),comments:s,rangeMap:W(t,r,s)}))}}}),i.map((function(e,t){return{filename:t+"."+e.lang,text:r(r([],e.comments),[e.value,""]).join("\n")}}))},postprocess:function(r,t){var n,s=A[t]||[];return(n=[]).concat.apply(n,r.map((function(r,t){var n=s[t];if(!n)return r;var i=function(r){var t=r.comments.reduce((function(e,r){return e+r.split("\n").length}),0),n=r.position.start.line;return function(s){var i=s.line-t;if(i<1)return null;var o={line:i+n,column:s.column+r.position.indent[i-1]-1};Number.isInteger(s.endLine)&&(o.endLine=s.endLine-t+n);var a={};return s.fix&&(a.fix={range:s.fix.range.map((function(e){for(var t=1;t<r.rangeMap.length&&r.rangeMap[t].js<=e;)t++;return e+r.rangeMap[t-1].md})),text:s.fix.text.replace(/\n/gu,"\n"+r.baseIndentText)}),e(e(e({},s),o),a)}}(n);return r.map(i).filter(z)})))},supportsAutofix:!0},F={javascript:"js",javascriptreact:"jsx",typescript:"ts",typescriptreact:"tsx",markdown:"md",mdown:"md",mkdn:"md"};function $(r,t){var n=a(r.split("."));if(!1===t)return n;t=e(e({},F),t);var s=n.toLowerCase();return t[n]||t[s]||s}var D={},G=Object.keys(require.cache).find((function(e){return/([/\\])eslint\1lib(?:\1linter){2}\.js$/.test(e)}));if(!G)throw new Error("Could not find ESLint Linter in require cache");var U=require(G).Linter,X=U.prototype.verify;U.prototype.verify=function(e,r,t){var n=r&&("function"==typeof r.extractConfig?r.extractConfig(void 0===t||"string"==typeof t?t:t.filename):r).settings||{};return D.lintCodeBlocks=!0===n["mdx/code-blocks"],D.languageMapper=n["mdx/language-mapper"],X.call(this,e,r,t)};var _={supportsAutofix:!0,preprocess:function(e,t){return D.lintCodeBlocks?r(r([],B.preprocess(e,t).map((function(e){var r=e.text,t=e.filename;return{text:r,filename:t.slice(0,t.lastIndexOf("."))+"."+$(t,D.languageMapper)}}))),[e]):[e]},postprocess:function(r,t){return B.postprocess(r,t).map((function(r){var t=r.message,n=r.ruleId,s=r.severity;if("mdx/remark"!==n)return r;var i=JSON.parse(t),o=i.source,a=i.ruleId,c=i.reason,l=i.severity;return e(e({},r),{ruleId:o+"-"+a,message:c,severity:Math.max(s,l)})}))}},K={markdown:B,remark:_};export{F as DEFAULT_LANGUAGE_MAPPER,v as base,x as codeBlocks,w as configs,S as getGlobals,L as getRemarkProcessor,$ as getShortLang,I as noJsxHtmlComments,C as noUnusedExpressions,h as overrides,D as processorOptions,K as processors,k as recommended,M as remark,E as remarkProcessor,O as requirePkg,q as rules};
