eslint-cli-bundle 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +10 -1
- package/dist/api.d.ts +32 -11
- package/dist/api.js +7 -7
- package/dist/babel.cjs +38 -27
- package/dist/config.d.ts +10 -2
- package/dist/config.js +1 -1
- package/dist/eslint-C-fkO7XK.js +166 -0
- package/dist/eslint-helpers-4m3QC9jt.js +370 -0
- package/dist/eslint.js +11 -8
- package/dist/jiti-CaIpDikP.js +15 -0
- package/dist/naming-BtEmRC_V.js +1 -0
- package/dist/rolldown-runtime-C7uQZ-1I.js +1 -0
- package/dist/shared/translate-cli-options.js +1 -0
- package/dist/src-Bnjf7phB.js +1 -0
- package/dist/types/config-helpers.d.ts +1473 -0
- package/dist/{types-CXey2reC.d.ts → types/core.d.ts} +62 -5
- package/dist/types/estree.d.ts +527 -0
- package/dist/types/plugin-kit.d.ts +1732 -0
- package/dist/worker.js +1 -0
- package/package.json +20 -15
- package/dist/chunk-qnHZjHhP.js +0 -1
- package/dist/eslint-BTrx12MV.js +0 -256
- package/dist/jiti-BvM1NyiB.js +0 -9
- package/dist/src-D7slgxDU.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) silverwind
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
17
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
18
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
19
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
20
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
21
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
# eslint-cli-bundle
|
|
2
|
+
[](https://www.npmjs.org/package/eslint-cli-bundle) [](https://www.npmjs.org/package/eslint-cli-bundle) [](https://packagephobia.com/result?p=eslint-cli-bundle)
|
|
2
3
|
|
|
3
|
-
Bundled version of [`eslint`](https://github.com/eslint/eslint)
|
|
4
|
+
> Bundled version of [`eslint`](https://github.com/eslint/eslint)
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm dlx eslint-cli-bundle .
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
© [silverwind](https://github.com/silverwind), distributed under BSD licence
|
package/dist/api.d.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* SOFTWARE
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import * as ESTree from "estree";
|
|
28
|
+
import * as ESTree from "./types/estree.js";
|
|
29
29
|
import type {
|
|
30
30
|
DeprecatedInfo,
|
|
31
31
|
LanguageOptions as GenericLanguageOptions,
|
|
@@ -69,12 +69,12 @@ import type {
|
|
|
69
69
|
SuggestedEdit,
|
|
70
70
|
ViolationReport,
|
|
71
71
|
MessagePlaceholderData,
|
|
72
|
-
} from "
|
|
72
|
+
} from "./types/core.js";
|
|
73
73
|
import type {
|
|
74
74
|
CustomRuleDefinitionType,
|
|
75
75
|
CustomRuleTypeDefinitions,
|
|
76
76
|
CustomRuleVisitorWithExit,
|
|
77
|
-
} from "
|
|
77
|
+
} from "./types/plugin-kit.js";
|
|
78
78
|
|
|
79
79
|
//------------------------------------------------------------------------------
|
|
80
80
|
// Exports
|
|
@@ -663,8 +663,7 @@ export namespace Rule {
|
|
|
663
663
|
interface NodeListener extends CustomRuleVisitorWithExit<
|
|
664
664
|
{
|
|
665
665
|
[Node in Rule.Node as Node["type"]]?:
|
|
666
|
-
|
|
667
|
-
| undefined;
|
|
666
|
+
((node: Node) => void) | undefined;
|
|
668
667
|
} & {
|
|
669
668
|
// A `Program` visitor's node type has no `parent` property.
|
|
670
669
|
Program?: ((node: AST.Program) => void) | undefined;
|
|
@@ -723,6 +722,22 @@ export namespace Rule {
|
|
|
723
722
|
| "class-field-initializer"
|
|
724
723
|
| "class-static-block";
|
|
725
724
|
|
|
725
|
+
interface CodePathSegmentTraversalController {
|
|
726
|
+
skip(): void;
|
|
727
|
+
break(): void;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
type CodePathSegmentTraversalCallback = (
|
|
731
|
+
this: CodePath,
|
|
732
|
+
segment: CodePathSegment,
|
|
733
|
+
controller: CodePathSegmentTraversalController,
|
|
734
|
+
) => void;
|
|
735
|
+
|
|
736
|
+
interface CodePathTraversalOptions {
|
|
737
|
+
first?: CodePathSegment | undefined;
|
|
738
|
+
last?: CodePathSegment | undefined;
|
|
739
|
+
}
|
|
740
|
+
|
|
726
741
|
interface CodePath {
|
|
727
742
|
id: string;
|
|
728
743
|
origin: CodePathOrigin;
|
|
@@ -732,12 +747,19 @@ export namespace Rule {
|
|
|
732
747
|
thrownSegments: CodePathSegment[];
|
|
733
748
|
upper: CodePath | null;
|
|
734
749
|
childCodePaths: CodePath[];
|
|
750
|
+
traverseSegments(callback: CodePathSegmentTraversalCallback): void;
|
|
751
|
+
traverseSegments(
|
|
752
|
+
options: CodePathTraversalOptions,
|
|
753
|
+
callback: CodePathSegmentTraversalCallback,
|
|
754
|
+
): void;
|
|
735
755
|
}
|
|
736
756
|
|
|
737
757
|
interface CodePathSegment {
|
|
738
758
|
id: string;
|
|
739
759
|
nextSegments: CodePathSegment[];
|
|
740
760
|
prevSegments: CodePathSegment[];
|
|
761
|
+
allNextSegments: CodePathSegment[];
|
|
762
|
+
allPrevSegments: CodePathSegment[];
|
|
741
763
|
reachable: boolean;
|
|
742
764
|
}
|
|
743
765
|
|
|
@@ -946,7 +968,7 @@ export namespace Linter {
|
|
|
946
968
|
*/
|
|
947
969
|
impliedStrict?: boolean | undefined;
|
|
948
970
|
/**
|
|
949
|
-
* Enable [JSX](https://
|
|
971
|
+
* Enable [JSX](https://react.github.io/jsx/).
|
|
950
972
|
*
|
|
951
973
|
* @default false
|
|
952
974
|
*/
|
|
@@ -964,11 +986,9 @@ export namespace Linter {
|
|
|
964
986
|
filename?: string | undefined;
|
|
965
987
|
preprocess?: ((code: string) => string[]) | undefined;
|
|
966
988
|
postprocess?:
|
|
967
|
-
|
|
968
|
-
| undefined;
|
|
989
|
+
((problemLists: LintMessage[][]) => LintMessage[]) | undefined;
|
|
969
990
|
filterCodeBlock?:
|
|
970
|
-
|
|
971
|
-
| undefined;
|
|
991
|
+
((filename: string, text: string) => boolean) | undefined;
|
|
972
992
|
disableFixes?: boolean | undefined;
|
|
973
993
|
allowInlineConfig?: boolean | undefined;
|
|
974
994
|
reportUnusedDisableDirectives?: boolean | undefined;
|
|
@@ -1105,8 +1125,9 @@ export namespace Linter {
|
|
|
1105
1125
|
interface TimePass {
|
|
1106
1126
|
/**
|
|
1107
1127
|
* The parse object containing all parse time information.
|
|
1128
|
+
* If no parsing was performed, the property is omitted.
|
|
1108
1129
|
*/
|
|
1109
|
-
parse
|
|
1130
|
+
parse?: { total: number };
|
|
1110
1131
|
|
|
1111
1132
|
/**
|
|
1112
1133
|
* The rules object containing all lint time information for each rule.
|
package/dist/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{r as e,t}from"./
|
|
2
|
-
`).slice(r-1);t[0]=t[0].slice(Math.max(0,i-1)),t=t.map(e=>e.trim().replace(/\s*\/\/.*$(?<!,)/u,``));let a=t.findIndex(e=>/\bvalid\s*:/u.test(e)),o=t.findIndex(e=>/\binvalid\s*:/u.test(e));n.valid=`${e}:${r+a}`,n.invalid=`${e}:${r+o}`;let s=a<o?o:t.length,c=a<o?t.length:a,l=t.slice(a,s),u=t.slice(o,c),d=0,f=l.map((e,t)=>(/^(?:\w+\s*:\s*)?\{/u.test(e)&&d++,d>0?((e.endsWith(`}`)||e.endsWith(`},`))&&d--,d<=1&&e.includes(`code:`)?t:null):e.endsWith(`,`)?t:null)).filter(Boolean),p=u.map((e,t)=>e.trimStart().startsWith(`errors:`)?t:null).filter(Boolean);Object.assign(n,{"valid[0]":`${e}:${r+a}`},Object.fromEntries(f.map((t,n)=>[`valid[${n}]`,`${e}:${r+a+t}`])),Object.fromEntries(p.map((t,n)=>[`invalid[${n}]`,`${e}:${r+o+t}`]))),p.push(u.length);for(let t=0;t<p.length-1;t++){let i=p[t],a=p[t+1],s=u.slice(i,a),c=0,l=s.map((e,t)=>e.startsWith(`{`)||e.endsWith(`{`)?(c++,(e.endsWith(`}`)||e.endsWith(`},`))&&c--,c<=1?t:null):c>0?((e.endsWith(`}`)||e.endsWith(`},`))&&c--,null):e.endsWith(`,`)?t:null).filter(Boolean);Object.assign(n,Object.fromEntries(l.map((n,a)=>[`invalid[${t}].errors[${a}]`,`${e}:${r+o+i+n}`])))}}}return n[e]||`unknown source`}}let X=Symbol(`describe`),Z=Symbol(`it`),Q=Symbol(`itOnly`);function
|
|
3
|
-
`);throw Error([`Schema for rule ${e} is invalid:`,
|
|
4
|
-
`))}else f=o;return{messages:S,output:f,beforeAST:p,afterAST:
|
|
5
|
-
`)),g.strictEqual(u,n.output,`Expected the applied suggestion fix to match the test suggestion output for suggestion at index: ${r} on error with message: "${l.message}"`),g.notStrictEqual(n.output,e.code,`The output of a suggestion should differ from the original source code for suggestion at index: ${r} on error with message: "${l.message}"`)})):g.fail(`Test error object property 'suggestions' should be an array or a number`))}}}catch(e){throw e instanceof Error&&(e.errorIndex=r),e}}
|
|
6
|
-
`))),e}finally{c(r,`after`)}})})}),n.invalid.length>0&&this.constructor.describe(`invalid`,()=>{let t
|
|
7
|
-
`))}throw e}finally{c(a,`after`)}})})})})}};$[X]=$[Z]=$[Q]=null,
|
|
1
|
+
import{r as e,t}from"./rolldown-runtime-C7uQZ-1I.js";import{a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,o as f,u as p}from"./eslint-helpers-4m3QC9jt.js";import{t as m}from"./eslint-C-fkO7XK.js";var h=/* @__PURE__ */ t(((e,t)=>{function n(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`||typeof e==`object`&&e.constructor===Object||Array.isArray(e)}function r(e,t=/* @__PURE__ */ new Set){if(!n(e))return!1;if(typeof e==`object`&&e){if(t.has(e))return!1;for(let i in e)if(Object.hasOwn(e,i)&&(!n(e[i])||typeof e[i]==`object`&&e[i]!==null&&!r(e[i],/* @__PURE__ */ new Set([...t,e]))))return!1}return!0}t.exports={isSerializable:r}})),g=/* @__PURE__ */ t(((t,m)=>{let g=e(`node:assert`),{existsSync:_,readFileSync:v}=e(`node:fs`),y=e(`node:util`),b=e(`node:path`),x=a(),S=r(),{Config:C}=u(),{Linter:w,SourceCodeFixer:T}=n(),{interpolate:E,getPlaceholderMatcher:ee}=f(),te=l(),{isSerializable:ne}=h(),{FlatConfigArray:re}=i(),{defaultConfig:D,defaultRuleTesterConfig:ie}=d(),O=Symbol.for(`eslint.RuleTester.parser`),{ConfigArraySymbol:k}=o(),ae=c(),{SourceCode:A}=s(),j={rules:{}},M,N={rules:{}},oe=[`name`,`code`,`filename`,`options`,`before`,`after`,`errors`,`output`,`only`],P=/* @__PURE__ */ new Set([`message`,`messageId`,`data`,`line`,`column`,`endLine`,`endColumn`,`suggestions`]),se=`[${[...P].map(e=>`'${e}'`).join(`, `)}]`,F=/* @__PURE__ */ new Set([`desc`,`messageId`,`data`,`output`]),ce=`[${[...F].map(e=>`'${e}'`).join(`, `)}]`,I=[`applyInlineConfig`,`applyLanguageOptions`,`finalize`],le=new Map(I.map(e=>[e,/* @__PURE__ */ new WeakSet])),L=Function.call.bind(Object.hasOwnProperty);function ue(){return M||=p()({strictDefaults:!0}),M}function R(e){if(typeof e==`object`&&e){if(Array.isArray(e))return e.map(R);let t={};for(let n in e)n!==`parent`&&L(e,n)&&(t[n]=R(e[n]));return t}return e}function z(e,t=/* @__PURE__ */ new Set){if(typeof e==`object`&&e){if(t.has(e))return;if(t.add(e),Array.isArray(e))e.forEach(e=>{z(e,t)});else for(let n in e)n!==`parent`&&L(e,n)&&z(e[n],t);Object.freeze(e)}}function B(e){return typeof e==`string`?e.replace(/[\u0000-\u0009\u000b-\u001a]/gu,e=>`\\u${e.codePointAt(0).toString(16).padStart(4,`0`)}`):``}function V(e,t){Object.defineProperties(t,{start:{get(){throw Error(`Use ${e}.range[0] instead of ${e}.start`)},configurable:!0,enumerable:!1},end:{get(){throw Error(`Use ${e}.range[1] instead of ${e}.end`)},configurable:!0,enumerable:!1}})}function H(e,t){S.traverse(e,{visitorKeys:t,enter:V.bind(null,`node`)}),e.tokens.forEach(V.bind(null,`token`)),e.comments.forEach(V.bind(null,`token`))}function de(e){return typeof e.parseForESLint==`function`?{[O]:e,parseForESLint(...t){let n=e.parseForESLint(...t);return H(n.ast,n.visitorKeys),n}}:{[O]:e,parse(...t){let n=e.parse(...t);return H(n),n}}}function fe(e,t){let n=t[e];return function(...t){let r=le.get(e);if(!r.has(this))return r.add(this),n.apply(this,t);throw Error(`\`SourceCode#${e}()\` cannot be called inside a rule.`)}}function U(e){let t=ee();return Array.from(e.matchAll(t),([,e])=>e.trim())}function W(e,t,n={}){let r=U(e);if(r.length===0)return[];let i=U(t),a=Object.keys(n);return r.filter(e=>i.includes(e)&&!a.includes(e))}let G="\n - If the rule has options, set `meta.schema` to an array or non-empty object to enable options validation.\n - If the rule doesn't have options, omit `meta.schema` to enforce that no options can be passed to the rule.\n - You can also set `meta.schema` to `false` to opt-out of options validation (not recommended).\n\n https://eslint.org/docs/latest/extend/custom-rules#options-schemas\n",pe=/* @__PURE__ */ new Set([`name`,`errors`,`output`]);function K(e){return e&&typeof e==`object`?e:{code:e}}function me(e,t,n={}){let r=typeof e==`number`,i=Array.isArray(e);!r&&!i&&(e===void 0?g.fail(`Did not specify errors for an invalid test of ${t}`):g.fail(`Invalid 'errors' property for invalid test of ${t}: expected a number or an array but got ${e===null?`null`:typeof e}`));let{requireMessage:a=!1,requireLocation:o=!1}=n;if(i){g.ok(e.length!==0,`Invalid cases must have at least one error`);for(let[t,n]of e.entries())if(typeof n==`string`||n instanceof RegExp)g.ok(a!==`messageId`&&!o,`errors[${t}] should be an object when 'assertionOptions.requireMessage' is 'messageId' or 'assertionOptions.requireLocation' is true.`);else if(typeof n==`object`&&n){for(let e of Object.keys(n))g.ok(P.has(e),`Invalid error property name '${e}'. Expected one of ${se}.`);a===`message`?g.ok(!L(n,`messageId`)&&L(n,`message`),`errors[${t}] should specify 'message' (and not 'messageId') when 'assertionOptions.requireMessage' is 'message'.`):a===`messageId`&&g.ok(!L(n,`message`)&&L(n,`messageId`),`errors[${t}] should specify 'messageId' (and not 'message') when 'assertionOptions.requireMessage' is 'messageId'.`),L(n,`message`)?(g.ok(!L(n,`messageId`),`errors[${t}] should not specify both 'message' and 'messageId'.`),g.ok(!L(n,`data`),`errors[${t}] should not specify both 'data' and 'message'.`)):g.ok(L(n,`messageId`),`errors[${t}] must specify either 'messageId' or 'message'.`)}else g.fail(`errors[${t}] must be a string, RegExp, or an object.`)}else g.ok(!a&&!o,`Invalid cases must have 'errors' value as an array`),g.ok(e>0,`Invalid cases must have 'error' value greater than 0`)}function q(e,t){if(!ne(e))return;let n=te(e,{replacer(t,n){return e!==this||!pe.has(t)?n:void 0}});g(!t.has(n),`detected duplicate test case`),t.add(n)}function he(e,t){g.ok(e&&typeof e==`object`&&typeof e.create==`function`,`Rule ${t} must be an object with a \`create\` method`)}function ge(e,t){g.ok(e&&typeof e==`object`,`Test Scenarios for rule ${t} : Could not find test scenario object`);let n=Array.isArray(e.valid),r=Array.isArray(e.invalid);g.ok(n,`Test Scenarios for rule ${t} is invalid: Could not find any valid test scenarios`),g.ok(r,`Test Scenarios for rule ${t} is invalid: Could not find any invalid test scenarios`)}function J(e){g.ok(typeof e.code==`string`,`Test case must specify a string value for 'code'`),e.name&&g.ok(typeof e.name==`string`,`Optional test case property 'name' must be a string`),L(e,`only`)&&g.ok(typeof e.only==`boolean`,`Optional test case property 'only' must be a boolean`),L(e,`filename`)&&g.ok(typeof e.filename==`string`,`Optional test case property 'filename' must be a string`),L(e,`options`)&&g.ok(Array.isArray(e.options),`Optional test case property 'options' must be an array`)}function _e(e,t){g.ok(e.errors===void 0,`Valid test case must not have 'errors' property`),g.ok(e.output===void 0,`Valid test case must not have 'output' property`),J(e),q(e,t)}function ve(e,t,n,r={}){J(e),me(e.errors,n,r),L(e,`output`)&&g.ok(e.output===null||typeof e.output==`string`,`Test property 'output', if specified, must be a string or null. If no autofix is expected, then omit the 'output' property or set it to null.`),q(e,t)}function Y(e=Y){let t={},n,{prepareStackTrace:r}=Error;return Error.prepareStackTrace=(e,[t])=>{n={sourceFile:t.getFileName()??`${t.getEvalOrigin()}, <anonymous>`,sourceLine:t.getLineNumber()??1,sourceColumn:t.getColumnNumber()??1}},Error.captureStackTrace(t,e),t.stack,Error.prepareStackTrace=r,n}function ye(e){let t=Y(e),n=null;return e=>{if(n===null){let{sourceFile:e,sourceLine:r,sourceColumn:i}=t;if(n={root:`${e}:${r}:${i}`},_(e)){let t=v(e,`utf8`).split(`
|
|
2
|
+
`).slice(r-1);t[0]=t[0].slice(Math.max(0,i-1)),t=t.map(e=>e.trim().replace(/\s*\/\/.*$(?<!,)/u,``));let a=t.findIndex(e=>/\bvalid\s*:/u.test(e)),o=t.findIndex(e=>/\binvalid\s*:/u.test(e));n.valid=`${e}:${r+a}`,n.invalid=`${e}:${r+o}`;let s=a<o?o:t.length,c=a<o?t.length:a,l=t.slice(a,s),u=t.slice(o,c),d=0,f=l.map((e,t)=>(/^(?:\w+\s*:\s*)?\{/u.test(e)&&d++,d>0?((e.endsWith(`}`)||e.endsWith(`},`))&&d--,d<=1&&e.includes(`code:`)?t:null):e.endsWith(`,`)?t:null)).filter(Boolean),p=u.map((e,t)=>e.trimStart().startsWith(`errors:`)?t:null).filter(Boolean);Object.assign(n,{"valid[0]":`${e}:${r+a}`},Object.fromEntries(f.map((t,n)=>[`valid[${n}]`,`${e}:${r+a+t}`])),Object.fromEntries(p.map((t,n)=>[`invalid[${n}]`,`${e}:${r+o+t}`]))),p.push(u.length);for(let t=0;t<p.length-1;t++){let i=p[t],a=p[t+1],s=u.slice(i,a),c=0,l=s.map((e,t)=>e.startsWith(`{`)||e.endsWith(`{`)?(c++,(e.endsWith(`}`)||e.endsWith(`},`))&&c--,c<=1?t:null):c>0?((e.endsWith(`}`)||e.endsWith(`},`))&&c--,null):e.endsWith(`,`)?t:null).filter(Boolean);Object.assign(n,Object.fromEntries(l.map((n,a)=>[`invalid[${t}].errors[${a}]`,`${e}:${r+o+i+n}`])))}}}return n[e]||`unknown source`}}let X=Symbol(`describe`),Z=Symbol(`it`),Q=Symbol(`itOnly`);function be(e,t){try{return t.call(this)}catch(e){throw e instanceof g.AssertionError&&(e.message+=` (${y.inspect(e.actual)} ${e.operator} ${y.inspect(e.expected)})`),e}}function xe(e,t){return t.call(this)}var $=class{constructor(e={}){this.testerConfig=[N,e,{rules:{"rule-tester/validate-ast":`error`}}],this.linter=new w({configType:`flat`})}static setDefaultConfig(e){if(typeof e!=`object`||!e)throw TypeError(`RuleTester.setDefaultConfig: config must be an object`);N=e,N.rules=N.rules||{}}static getDefaultConfig(){return N}static resetDefaultConfig(){N={rules:{...j.rules}}}static get describe(){return this[X]||(typeof describe==`function`?describe:xe)}static set describe(e){this[X]=e}static get it(){return this[Z]||(typeof it==`function`?it:be)}static set it(e){this[Z]=e}static only(e){return typeof e==`string`?{code:e,only:!0}:{...e,only:!0}}static get itOnly(){if(typeof this[Q]==`function`)return this[Q];if(typeof this[Z]==`function`&&typeof this[Z].only==`function`)return Function.bind.call(this[Z].only,this[Z]);if(typeof it==`function`&&typeof it.only==`function`)return Function.bind.call(it.only,it);throw typeof this[X]==`function`||typeof this[Z]==`function`?Error("Set `RuleTester.itOnly` to use `only` with a custom test framework.\nSee https://eslint.org/docs/latest/integrate/nodejs-api#customizing-ruletester for more."):Error(typeof it==`function`?"The current test framework does not support exclusive tests with `only`.":"To use `only`, use RuleTester with a test framework that provides `it.only()` like Mocha.")}static set itOnly(e){this[Q]=e}run(e,t,n){let r=this.testerConfig,i=this.linter,a=`rule-to-test/${e}`;he(t,e),ge(n,e);let o=ye(this.run),s=[{plugins:{"@":{parsers:{...D[0].plugins[`@`].parsers},rules:D[0].plugins[`@`].rules,languages:D[0].plugins[`@`].languages},"rule-to-test":{rules:{[e]:Object.assign({},t,{create(e){return z(e.options),z(e.settings),z(e.parserOptions),t.create(e)}})}}},language:D[0].language},...ie];function c(e,t){L(e,t)&&(g.strictEqual(typeof e[t],`function`,`Optional test case property '${t}' must be a function`),e[t]())}function l(n){let o=n.code,c=L(n,`filename`)?n.filename:void 0,l=L(n,`options`)?n.options:[],u={baseConfig:s};c&&(u.basePath=b.parse(c).root||void 0);let d=new re(r,u);d[k.finalizeConfig]=function(...e){let t=Object.getPrototypeOf(this)[k.finalizeConfig].apply(this,e);return t.language===ae&&(t.languageOptions.parser=de(t.languageOptions.parser)),t};let f,p,m,h={...n};for(let e of oe)delete h[e];d.push(h),d.push({rules:{[a]:[1,...l]}});let _;try{_=C.getRuleOptionsSchema(t)}catch(e){throw e.message+=G,e}if(_&&Object.keys(_).length===0)throw Error(`\`schema: {}\` is a no-op${G}`);if(d.push({plugins:{"rule-tester":{rules:{"validate-ast":{create(){return{Program(e){p=R(e)},"Program:exit"(e){m=e}}}}}}}}),_){let t=ue();if(t.validateSchema(_),t.errors){let n=t.errors.map(e=>`\t${e.dataPath[0]===`.`?e.dataPath.slice(1):e.dataPath}: ${e.message}`).join(`
|
|
3
|
+
`);throw Error([`Schema for rule ${e} is invalid:`,n])}try{t.compile(_)}catch(t){throw Error(`Schema for rule ${e} is invalid: ${t.message}`,{cause:t})}}try{d.normalizeSync(),d.getConfig(`test.js`)}catch(e){throw e.message=`ESLint configuration in rule-tester is invalid: ${e.message}`,e}let{applyLanguageOptions:v,applyInlineConfig:y,finalize:x}=A.prototype,S;try{I.forEach(e=>{A.prototype[e]=fe(e,A.prototype)}),S=i.verify(o,d,c)}finally{A.prototype.applyInlineConfig=y,A.prototype.applyLanguageOptions=v,A.prototype.finalize=x}let w=S.find(e=>e.fatal);if(g(!w,`A fatal parsing error occurred: ${w&&w.message}`),S.some(e=>e.fix)){f=T.applyFixes(o,S).output;let e=i.verify(f,d,c).find(e=>e.fatal);g(!e,[`A fatal parsing error occurred in autofix.`,`Error: ${e&&e.message}`,`Autofix output:`,f].join(`
|
|
4
|
+
`))}else f=o;return{messages:S,output:f,beforeAST:p,afterAST:R(m),configs:d,filename:c}}function u(e,t){x(e,t)||g.fail(`Rule should not modify AST.`)}function d(e){let t=l(e),n=t.messages;g.strictEqual(n.length,0,y.format(`Should have no errors but had %d: %s`,n.length,y.inspect(n))),u(t.beforeAST,t.afterAST)}function f(e,t){t instanceof RegExp?g.ok(t.test(e),`Expected '${e}' to match ${t}`):g.strictEqual(e,t)}function p(e){let{requireMessage:r=!1,requireLocation:o=!1,requireData:s=!1}=n.assertionOptions??{},c=L(t,`meta`)&&L(t.meta,`messages`),d=c?`[${Object.keys(t.meta.messages).map(e=>`'${e}'`).join(`, `)}]`:null;g.ok(c||r!==`messageId`,`Assertion options can not use 'requireMessage: "messageId"' if rule under test doesn't define 'meta.messages'.`);let p=l(e),m=p.messages;for(let e of m)if(L(e,`suggestions`)){let t=/* @__PURE__ */ new Map;for(let n=0;n<e.suggestions.length;n+=1){let r=e.suggestions[n].desc,i=t.get(r);g.ok(!t.has(r),`Suggestion message '${r}' reported from suggestion ${n} was previously reported by suggestion ${i}. Suggestion messages should be unique within an error.`),t.set(r,n)}}if(typeof e.errors==`number`)g.strictEqual(m.length,e.errors,y.format(`Should have %d error%s but had %d: %s`,e.errors,e.errors===1?``:`s`,m.length,y.inspect(m)));else{g.strictEqual(m.length,e.errors.length,y.format(`Should have %d error%s but had %d: %s`,e.errors.length,e.errors.length===1?``:`s`,m.length,y.inspect(m)));let n=m.some(e=>e.ruleId===a);for(let r=0,a=e.errors.length;r<a;r++)try{let a=e.errors[r],l=m[r];if(g(n,`Error rule name should be the same as the name of the rule being tested`),typeof a==`string`||a instanceof RegExp)f(l.message,a),g.ok(l.suggestions===void 0,`Error at index ${r} has suggestions. Please convert the test error into an object and specify 'suggestions' property on it to test suggestions.`);else if(typeof a==`object`&&a){if(L(a,`message`))f(l.message,a.message);else if(L(a,`messageId`)){g.ok(c,`Error can not use 'messageId' if rule under test doesn't define 'meta.messages'.`),L(t.meta.messages,a.messageId)||g(!1,`Invalid messageId '${a.messageId}'. Expected one of ${d}.`),g.strictEqual(l.messageId,a.messageId,`messageId '${l.messageId}' does not match expected messageId '${a.messageId}'.`);let e=W(l.message,t.meta.messages[l.messageId],a.data);if(g.ok(e.length===0,`The reported message has ${e.length>1?`unsubstituted placeholders: ${e.map(e=>`'${e}'`).join(`, `)}`:`an unsubstituted placeholder '${e[0]}'`}. Please provide the missing ${e.length>1?`values`:`value`} via the 'data' property in the context.report() call.`),L(a,`data`)){let e=t.meta.messages[a.messageId],n=E(e,a.data);g.strictEqual(l.message,n,`Hydrated message "${n}" does not match "${l.message}"`)}else{let e=s===!0||s===`error`,n=U(t.meta.messages[a.messageId]).length>0;g.ok(!e||!n,`Error should specify the 'data' property as the referenced message has placeholders.`)}}let n=[`line`,`column`,`endLine`,`endColumn`],u={},m={};for(let e of n)L(a,e)&&(u[e]=l[e],m[e]=a[e]);if(o){let e=n.filter(e=>!L(a,e)&&L(l,e));g.ok(e.length===0,`Error is missing expected location properties: ${e.join(`, `)}`)}if(Object.keys(m).length>0&&g.deepStrictEqual(u,m,`Actual error location does not match expected error location.`),g.ok(!l.suggestions||L(a,`suggestions`),`Error at index ${r} has suggestions. Please specify 'suggestions' property on the test error object.`),L(a,`suggestions`)){let n=Array.isArray(a.suggestions)?a.suggestions.length>0:!!a.suggestions,r=l.suggestions!==void 0;!r&&n?g.ok(!a.suggestions,`Error should have suggestions on error with message: "${l.message}"`):r&&(g.ok(n,`Error should have no suggestions on error with message: "${l.message}"`),typeof a.suggestions==`number`?g.strictEqual(l.suggestions.length,a.suggestions,`Error should have ${a.suggestions} suggestions. Instead found ${l.suggestions.length} suggestions`):Array.isArray(a.suggestions)?(g.strictEqual(l.suggestions.length,a.suggestions.length,`Error should have ${a.suggestions.length} suggestions. Instead found ${l.suggestions.length} suggestions`),a.suggestions.forEach((n,r)=>{g.ok(typeof n==`object`&&!!n,`Test suggestion in 'suggestions' array must be an object.`),Object.keys(n).forEach(e=>{g.ok(F.has(e),`Invalid suggestion property name '${e}'. Expected one of ${ce}.`)});let a=l.suggestions[r],o=`Error Suggestion at index ${r}:`;if(L(n,`desc`))g.ok(!L(n,`data`),`${o} Test should not specify both 'desc' and 'data'.`),g.ok(!L(n,`messageId`),`${o} Test should not specify both 'desc' and 'messageId'.`),g.strictEqual(a.desc,n.desc,`${o} desc should be "${n.desc}" but got "${a.desc}" instead.`);else if(L(n,`messageId`)){g.ok(c,`${o} Test can not use 'messageId' if rule under test doesn't define 'meta.messages'.`),g.ok(L(t.meta.messages,n.messageId),`${o} Test has invalid messageId '${n.messageId}', the rule under test allows only one of ${d}.`),g.strictEqual(a.messageId,n.messageId,`${o} messageId should be '${n.messageId}' but got '${a.messageId}' instead.`);let e=t.meta.messages[n.messageId],r=W(a.desc,e,n.data);if(g.ok(r.length===0,`The message of the suggestion has ${r.length>1?`unsubstituted placeholders: ${r.map(e=>`'${e}'`).join(`, `)}`:`an unsubstituted placeholder '${r[0]}'`}. Please provide the missing ${r.length>1?`values`:`value`} via the 'data' property for the suggestion in the context.report() call.`),L(n,`data`)){let e=t.meta.messages[n.messageId],r=E(e,n.data);g.strictEqual(a.desc,r,`${o} Hydrated test desc "${r}" does not match received desc "${a.desc}".`)}else{let t=s===!0||s===`suggestion`,n=U(e).length>0;g.ok(!t||!n,`${o} Suggestion should specify the 'data' property as the referenced message has placeholders.`)}}else L(n,`data`)?g.fail(`${o} Test must specify 'messageId' if 'data' is used.`):g.fail(`${o} Test must specify either 'messageId' or 'desc'.`);g.ok(L(n,`output`),`${o} The "output" property is required.`);let u=T.applyFixes(e.code,[a]).output,f=i.verify(u,p.configs,p.filename).find(e=>e.fatal);g(!f,[`A fatal parsing error occurred in suggestion fix.`,`Error: ${f&&f.message}`,`Suggestion output:`,u].join(`
|
|
5
|
+
`)),g.strictEqual(u,n.output,`Expected the applied suggestion fix to match the test suggestion output for suggestion at index: ${r} on error with message: "${l.message}"`),g.notStrictEqual(n.output,e.code,`The output of a suggestion should differ from the original source code for suggestion at index: ${r} on error with message: "${l.message}"`)})):g.fail(`Test error object property 'suggestions' should be an array or a number`))}}}catch(e){throw e instanceof Error&&(e.errorIndex=r),e}}L(e,`output`)?e.output===null?g.strictEqual(p.output,e.code,`Expected no autofixes to be suggested`):(g.strictEqual(p.output,e.output,`Output is incorrect.`),g.notStrictEqual(e.code,e.output,`Test property 'output' matches 'code'. If no autofix is expected, then omit the 'output' property or set it to null.`)):g.strictEqual(p.output,e.code,`The rule fixed the code. Please add 'output' property.`),u(p.beforeAST,p.afterAST)}this.constructor.describe(e,()=>{n.valid.length>0&&this.constructor.describe(`valid`,()=>{let e=/* @__PURE__ */ new Set;n.valid.forEach((t,n)=>{let r=K(t);this.constructor[t.only?`itOnly`:`it`](B(r.name||r.code),()=>{try{c(r,`before`),_e(r,e),d(r)}catch(e){throw e instanceof Error&&(e.scenarioType=`valid`,e.scenarioIndex=n,e.stack=e.stack.replace(/^ +at /mu,[` roughly at RuleTester.run.valid[${n}] (${o(`valid[${n}]`)})`,` roughly at RuleTester.run.valid (${o(`valid`)})`,` at RuleTester.run (${o(`root`)})`,` at `].join(`
|
|
6
|
+
`))),e}finally{c(r,`after`)}})})}),n.invalid.length>0&&this.constructor.describe(`invalid`,()=>{let t=/* @__PURE__ */ new Set;n.invalid.forEach((r,i)=>{let a=K(r);this.constructor[a.only?`itOnly`:`it`](B(a.name||a.code),()=>{try{c(a,`before`),ve(a,t,e,n.assertionOptions),p(a)}catch(e){if(e instanceof Error){e.scenarioType=`invalid`,e.scenarioIndex=i;let t=e.errorIndex;e.stack=e.stack.replace(/^ +at /mu,[...typeof t==`number`?[` roughly at RuleTester.run.invalid[${i}].error[${t}] (${o(`invalid[${i}].errors[${t}]`)})`]:[],` roughly at RuleTester.run.invalid[${i}] (${o(`invalid[${i}]`)})`,` roughly at RuleTester.run.invalid (${o(`invalid`)})`,` at RuleTester.run (${o(`root`)})`,` at `].join(`
|
|
7
|
+
`))}throw e}finally{c(a,`after`)}})})})})}};$[X]=$[Z]=$[Q]=null,m.exports=$})),_=/* @__PURE__ */ t(((e,t)=>{t.exports={RuleTester:g()}})),v=(/* @__PURE__ */ t(((e,t)=>{let{ESLint:r}=m(),{Linter:i}=n(),{RuleTester:a}=_(),{SourceCode:o}=s();async function c(){return r}t.exports={Linter:i,loadESLint:c,ESLint:r,RuleTester:a,SourceCode:o}})))(),y=v.ESLint,b=v.Linter,x=v.RuleTester,S=v.SourceCode,C=v.loadESLint;export{y as ESLint,b as Linter,x as RuleTester,S as SourceCode,C as loadESLint};
|