From b72b97ba617ff5eeb9b6f4e600c511250c19a72b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 19 Jan 2024 02:30:14 +0900 Subject: [PATCH] feat: add support for eslint v9 (#673) --- .changeset/stale-crews-brush.md | 5 + .eslintrc.js | 5 +- .github/workflows/NodeCI.yml | 5 + .vscode/settings.json | 3 +- package.json | 4 +- ...-spaces-around-equal-signs-in-attribute.ts | 2 +- src/rules/prefer-destructured-store-props.ts | 2 +- src/utils/eslint-core.ts | 18 ++- .../invalid/.eslintrc.json | 5 + .../invalid/_config.json | 3 + .../invalid/_requirements.json | 3 + .../invalid/both/_config.json | 2 +- .../invalid/both/_requirements.json | 3 + .../invalid/both/test01-errors.yaml | 12 +- .../invalid/both/test01-input.svelte | 4 - .../invalid/test01-errors.yaml | 4 +- .../invalid/test01-input.svelte | 4 - .../invalid/v8/_config.json | 3 + .../invalid/v8/_requirements.json | 3 + .../invalid/v8/both/_config.json | 3 + .../invalid/v8/both/_requirements.json | 3 + .../invalid/v8/both/test01-errors.yaml | 28 +++++ .../invalid/v8/both/test01-input.svelte | 19 +++ .../invalid/v8/test01-errors.yaml | 12 ++ .../invalid/v8/test01-input.svelte | 19 +++ .../invalid/member02-errors.yaml | 17 --- .../valid-compile/valid/babel/_config.json | 8 +- tests/src/configs/all.ts | 4 +- tests/src/integration/no-unused-vars.ts | 10 +- .../no-unnecessary-condition.ts | 16 +-- .../no-unnecessary-condition.ts | 39 ++++--- tests/src/rules/block-lang.ts | 4 +- tests/src/rules/button-has-type.ts | 4 +- tests/src/rules/comment-directive.ts | 46 ++++---- .../rules/derived-has-same-inputs-outputs.ts | 4 +- .../rules/experimental-require-slot-types.ts | 4 +- .../experimental-require-strict-events.ts | 4 +- tests/src/rules/first-attribute-linebreak.ts | 4 +- .../src/rules/html-closing-bracket-spacing.ts | 4 +- tests/src/rules/html-quotes.ts | 4 +- tests/src/rules/html-self-closing.ts | 4 +- tests/src/rules/indent.ts | 12 +- tests/src/rules/infinite-reactive-loop.ts | 4 +- tests/src/rules/max-attributes-per-line.ts | 4 +- tests/src/rules/mustache-spacing.ts | 4 +- tests/src/rules/no-at-debug-tags.ts | 4 +- tests/src/rules/no-at-html-tags.ts | 4 +- tests/src/rules/no-dom-manipulating.ts | 4 +- tests/src/rules/no-dupe-else-if-blocks.ts | 4 +- tests/src/rules/no-dupe-on-directives.ts | 4 +- tests/src/rules/no-dupe-style-properties.ts | 4 +- tests/src/rules/no-dupe-use-directives.ts | 4 +- tests/src/rules/no-dynamic-slot-name.ts | 4 +- ...port-load-in-svelte-module-in-kit-pages.ts | 4 +- tests/src/rules/no-extra-reactive-curlies.ts | 4 +- tests/src/rules/no-ignored-unsubscribe.ts | 4 +- .../rules/no-immutable-reactive-statements.ts | 4 +- tests/src/rules/no-inline-styles.ts | 4 +- tests/src/rules/no-inner-declarations.ts | 4 +- tests/src/rules/no-not-function-handler.ts | 4 +- .../src/rules/no-object-in-text-mustaches.ts | 4 +- tests/src/rules/no-reactive-functions.ts | 4 +- tests/src/rules/no-reactive-literals.ts | 4 +- tests/src/rules/no-reactive-reassign.ts | 4 +- .../src/rules/no-restricted-html-elements.ts | 4 +- .../no-shorthand-style-property-overrides.ts | 4 +- ...-spaces-around-equal-signs-in-attribute.ts | 4 +- tests/src/rules/no-store-async.ts | 4 +- tests/src/rules/no-target-blank.ts | 4 +- tests/src/rules/no-trailing-spaces.ts | 4 +- .../no-unknown-style-directive-property.ts | 4 +- tests/src/rules/no-unused-class-name.ts | 4 +- tests/src/rules/no-unused-svelte-ignore.ts | 4 +- tests/src/rules/no-useless-mustaches.ts | 4 +- tests/src/rules/prefer-class-directive.ts | 4 +- .../rules/prefer-destructured-store-props.ts | 4 +- tests/src/rules/prefer-style-directive.ts | 4 +- tests/src/rules/require-each-key.ts | 4 +- .../rules/require-event-dispatcher-types.ts | 4 +- .../require-optimized-style-attribute.ts | 4 +- .../require-store-callbacks-use-set-param.ts | 4 +- .../rules/require-store-reactive-access.ts | 4 +- tests/src/rules/require-stores-init.ts | 4 +- tests/src/rules/shorthand-attribute.ts | 4 +- tests/src/rules/shorthand-directive.ts | 4 +- tests/src/rules/sort-attributes.ts | 4 +- tests/src/rules/spaced-html-comment.ts | 4 +- tests/src/rules/valid-compile.ts | 9 +- tests/src/rules/valid-each-key.ts | 4 +- .../rules/valid-prop-names-in-kit-pages.ts | 4 +- tests/src/settings/ignore-warnings.ts | 65 ++++++----- tests/utils/eslint-compat.ts | 9 ++ tests/utils/utils.ts | 109 ++++++++++-------- tools/new-rule.ts | 10 +- 94 files changed, 450 insertions(+), 302 deletions(-) create mode 100644 .changeset/stale-crews-brush.md create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/.eslintrc.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/_config.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/_requirements.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/both/_requirements.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/_config.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/_requirements.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_config.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_requirements.json create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-errors.yaml create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-input.svelte create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-errors.yaml create mode 100644 tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-input.svelte create mode 100644 tests/utils/eslint-compat.ts diff --git a/.changeset/stale-crews-brush.md b/.changeset/stale-crews-brush.md new file mode 100644 index 000000000..acd302594 --- /dev/null +++ b/.changeset/stale-crews-brush.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-svelte": patch +--- + +feat: add support for eslint v9 diff --git a/.eslintrc.js b/.eslintrc.js index a81c80236..81c3c95cd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -94,7 +94,7 @@ module.exports = { }, { selector: 'variable', - format: ['camelCase', 'UPPER_CASE'], + format: ['camelCase', 'UPPER_CASE', 'PascalCase'], leadingUnderscore: 'allow', trailingUnderscore: 'allow' }, @@ -156,7 +156,8 @@ module.exports = { { files: ['tests/**'], rules: { - '@typescript-eslint/no-misused-promises': 'off' + '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-require-imports': 'off' } }, { diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 377d64674..30033a9a5 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -41,6 +41,11 @@ jobs: os: [ubuntu-latest] eslint: [7, 8] node: [20] + include: + # On next ESLint version + - eslint: ^9.0.0-0 + node: 20 + os: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.vscode/settings.json b/.vscode/settings.json index 56963be4f..9c214fd5a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,6 @@ "source.fixAll": "explicit", "source.fixAll.stylelint": "explicit" }, - "svelte.plugin.typescript.diagnostics.enable": false + "svelte.plugin.typescript.diagnostics.enable": false, + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/package.json b/package.json index 49d718f5e..24d725166 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "version:ci": "env-cmd -e version-ci pnpm run update && changeset version" }, "peerDependencies": { - "eslint": "^7.0.0 || ^8.0.0-0", + "eslint": "^7.0.0 || ^8.0.0-0 || ^9.0.0-0", "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.33" }, "peerDependenciesMeta": { @@ -69,7 +69,7 @@ "@eslint-community/eslint-utils": "^4.2.0", "@jridgewell/sourcemap-codec": "^1.4.14", "debug": "^4.3.1", - "eslint-compat-utils": "^0.4.0", + "eslint-compat-utils": "^0.4.1", "esutils": "^2.0.3", "known-css-properties": "^0.29.0", "postcss": "^8.4.5", diff --git a/src/rules/no-spaces-around-equal-signs-in-attribute.ts b/src/rules/no-spaces-around-equal-signs-in-attribute.ts index 534fd1610..bbbb4dae4 100644 --- a/src/rules/no-spaces-around-equal-signs-in-attribute.ts +++ b/src/rules/no-spaces-around-equal-signs-in-attribute.ts @@ -9,7 +9,7 @@ export default createRule('no-spaces-around-equal-signs-in-attribute', { recommended: false, conflictWithPrettier: true }, - schema: {}, + schema: [], fixable: 'whitespace', messages: { noSpaces: 'Unexpected spaces found around equal signs.' diff --git a/src/rules/prefer-destructured-store-props.ts b/src/rules/prefer-destructured-store-props.ts index c57ae59c4..b9f766cbf 100644 --- a/src/rules/prefer-destructured-store-props.ts +++ b/src/rules/prefer-destructured-store-props.ts @@ -186,7 +186,7 @@ export default createRule('prefer-destructured-store-props', { // dynamic accesses like {$foo[bar]} !node.computed ) { - for (const variable of findReactiveVariable(node.object, node.property.name)) { + for (const variable of new Set(findReactiveVariable(node.object, node.property.name))) { suggest.push({ messageId: 'fixUseVariable', data: { diff --git a/src/utils/eslint-core.ts b/src/utils/eslint-core.ts index 4ce7e1695..82f131165 100644 --- a/src/utils/eslint-core.ts +++ b/src/utils/eslint-core.ts @@ -76,11 +76,17 @@ let ruleMap: Map | null = null; * Get the core rule implementation from the rule name */ export function getCoreRule(ruleName: string): RuleModule { - let map: Map; - if (ruleMap) { - map = ruleMap; - } else { - ruleMap = map = (new Linter() as any).getRules(); + try { + const map: Map = ruleMap + ? ruleMap + : (ruleMap = (new Linter() as any).getRules()); + return map.get(ruleName)!; + } catch { + // getRules() is no longer available in flat config. } - return map.get(ruleName)!; + + // eslint-disable-next-line @typescript-eslint/no-require-imports , @typescript-eslint/no-var-requires -- Ignore + const { builtinRules } = require('eslint/use-at-your-own-risk'); + ruleMap = builtinRules; + return builtinRules.get(ruleName) || null; } diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/.eslintrc.json b/tests/fixtures/rules/no-inner-declarations/invalid/.eslintrc.json new file mode 100644 index 000000000..62fd137a9 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-var": "off" + } +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/_config.json b/tests/fixtures/rules/no-inner-declarations/invalid/_config.json new file mode 100644 index 000000000..2ca520027 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/_config.json @@ -0,0 +1,3 @@ +{ + "options": ["functions", { "blockScopedFunctions": "disallow" }] +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/_requirements.json b/tests/fixtures/rules/no-inner-declarations/invalid/_requirements.json new file mode 100644 index 000000000..3a1e692a6 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/_requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": "^9.0.0-0" +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/both/_config.json b/tests/fixtures/rules/no-inner-declarations/invalid/both/_config.json index f3a3e6557..cabe15f0b 100644 --- a/tests/fixtures/rules/no-inner-declarations/invalid/both/_config.json +++ b/tests/fixtures/rules/no-inner-declarations/invalid/both/_config.json @@ -1,3 +1,3 @@ { - "options": ["both"] + "options": ["both", { "blockScopedFunctions": "disallow" }] } diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/both/_requirements.json b/tests/fixtures/rules/no-inner-declarations/invalid/both/_requirements.json new file mode 100644 index 000000000..3a1e692a6 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/both/_requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": "^9.0.0-0" +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-errors.yaml b/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-errors.yaml index 62049f3fd..4eede613c 100644 --- a/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-errors.yaml +++ b/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-errors.yaml @@ -3,26 +3,26 @@ column: 3 suggestions: null - message: Move variable declaration to program root. - line: 6 + line: 5 column: 11 suggestions: null - message: Move variable declaration to program root. - line: 8 + line: 6 column: 31 suggestions: null - message: Move function declaration to program root. - line: 10 + line: 8 column: 3 suggestions: null - message: Move variable declaration to function body root. - line: 13 + line: 10 column: 5 suggestions: null - message: Move function declaration to program root. - line: 18 + line: 15 column: 3 suggestions: null - message: Move variable declaration to function body root. - line: 20 + line: 16 column: 13 suggestions: null diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-input.svelte b/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-input.svelte index d7f0f6b14..2771ebca2 100644 --- a/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-input.svelte +++ b/tests/fixtures/rules/no-inner-declarations/invalid/both/test01-input.svelte @@ -2,21 +2,17 @@ if (test) { function doSomething() {} } - // eslint-disable-next-line no-var -- test if (foo) var a; - // eslint-disable-next-line no-var -- test if (foo) /* some comments */ var a; if (foo) { function f() { if (bar) { - // eslint-disable-next-line no-var -- test var a; } } } if (foo) { function f() { - // eslint-disable-next-line no-var -- test if (bar) var a; } } diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/test01-errors.yaml b/tests/fixtures/rules/no-inner-declarations/invalid/test01-errors.yaml index 673e13f28..ab6c5f85d 100644 --- a/tests/fixtures/rules/no-inner-declarations/invalid/test01-errors.yaml +++ b/tests/fixtures/rules/no-inner-declarations/invalid/test01-errors.yaml @@ -3,10 +3,10 @@ column: 3 suggestions: null - message: Move function declaration to program root. - line: 10 + line: 8 column: 3 suggestions: null - message: Move function declaration to program root. - line: 18 + line: 15 column: 3 suggestions: null diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/test01-input.svelte b/tests/fixtures/rules/no-inner-declarations/invalid/test01-input.svelte index d7f0f6b14..2771ebca2 100644 --- a/tests/fixtures/rules/no-inner-declarations/invalid/test01-input.svelte +++ b/tests/fixtures/rules/no-inner-declarations/invalid/test01-input.svelte @@ -2,21 +2,17 @@ if (test) { function doSomething() {} } - // eslint-disable-next-line no-var -- test if (foo) var a; - // eslint-disable-next-line no-var -- test if (foo) /* some comments */ var a; if (foo) { function f() { if (bar) { - // eslint-disable-next-line no-var -- test var a; } } } if (foo) { function f() { - // eslint-disable-next-line no-var -- test if (bar) var a; } } diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/_config.json b/tests/fixtures/rules/no-inner-declarations/invalid/v8/_config.json new file mode 100644 index 000000000..8322fb2f4 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/_config.json @@ -0,0 +1,3 @@ +{ + "options": ["functions"] +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/_requirements.json b/tests/fixtures/rules/no-inner-declarations/invalid/v8/_requirements.json new file mode 100644 index 000000000..84191ab69 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/_requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": "<=8" +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_config.json b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_config.json new file mode 100644 index 000000000..f3a3e6557 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_config.json @@ -0,0 +1,3 @@ +{ + "options": ["both"] +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_requirements.json b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_requirements.json new file mode 100644 index 000000000..84191ab69 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/_requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": "<=8" +} diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-errors.yaml b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-errors.yaml new file mode 100644 index 000000000..4eede613c --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-errors.yaml @@ -0,0 +1,28 @@ +- message: Move function declaration to program root. + line: 3 + column: 3 + suggestions: null +- message: Move variable declaration to program root. + line: 5 + column: 11 + suggestions: null +- message: Move variable declaration to program root. + line: 6 + column: 31 + suggestions: null +- message: Move function declaration to program root. + line: 8 + column: 3 + suggestions: null +- message: Move variable declaration to function body root. + line: 10 + column: 5 + suggestions: null +- message: Move function declaration to program root. + line: 15 + column: 3 + suggestions: null +- message: Move variable declaration to function body root. + line: 16 + column: 13 + suggestions: null diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-input.svelte b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-input.svelte new file mode 100644 index 000000000..2771ebca2 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/both/test01-input.svelte @@ -0,0 +1,19 @@ + diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-errors.yaml b/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-errors.yaml new file mode 100644 index 000000000..ab6c5f85d --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-errors.yaml @@ -0,0 +1,12 @@ +- message: Move function declaration to program root. + line: 3 + column: 3 + suggestions: null +- message: Move function declaration to program root. + line: 8 + column: 3 + suggestions: null +- message: Move function declaration to program root. + line: 15 + column: 3 + suggestions: null diff --git a/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-input.svelte b/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-input.svelte new file mode 100644 index 000000000..2771ebca2 --- /dev/null +++ b/tests/fixtures/rules/no-inner-declarations/invalid/v8/test01-input.svelte @@ -0,0 +1,19 @@ + diff --git a/tests/fixtures/rules/prefer-destructured-store-props/invalid/member02-errors.yaml b/tests/fixtures/rules/prefer-destructured-store-props/invalid/member02-errors.yaml index 0a1f4db0a..d258ce3e1 100644 --- a/tests/fixtures/rules/prefer-destructured-store-props/invalid/member02-errors.yaml +++ b/tests/fixtures/rules/prefer-destructured-store-props/invalid/member02-errors.yaml @@ -95,23 +95,6 @@ bar.foo: {b.foo} bar.baz: {$store.bar.baz} - baz.foo: {bbb.foo} - baz.bar: {bbb.bar} - - desc: Using the predefined reactive variable bbb - messageId: fixUseVariable - output: | - - - foo.bar: {foo.bar} - foo.baz: {$store.foo.baz} - - bar.foo: {b.foo} - bar.baz: {$store.bar.baz} - baz.foo: {bbb.foo} baz.bar: {bbb.bar} - desc: 'Using destructuring like $: ({ baz } = $store); will run faster' diff --git a/tests/fixtures/rules/valid-compile/valid/babel/_config.json b/tests/fixtures/rules/valid-compile/valid/babel/_config.json index 2d5ef92c2..dc4ba7060 100644 --- a/tests/fixtures/rules/valid-compile/valid/babel/_config.json +++ b/tests/fixtures/rules/valid-compile/valid/babel/_config.json @@ -1,5 +1,7 @@ { - "parserOptions": { - "parser": "@babel/eslint-parser" - } + "languageOptions": { + "parserOptions": { + "parser": "@babel/eslint-parser" + } + } } diff --git a/tests/src/configs/all.ts b/tests/src/configs/all.ts index 193edb450..cf67a89a1 100644 --- a/tests/src/configs/all.ts +++ b/tests/src/configs/all.ts @@ -1,12 +1,12 @@ import assert from 'assert'; -import eslint from 'eslint'; import plugin from '../../../src/index'; +import { LegacyESLint } from '../../utils/eslint-compat'; describe('`all` config', () => { it('`all` config should work. ', async () => { const code = `{@html a+b}`; - const linter = new eslint.ESLint({ + const linter = new LegacyESLint({ plugins: { svelte: plugin as never }, diff --git a/tests/src/integration/no-unused-vars.ts b/tests/src/integration/no-unused-vars.ts index 702be7033..d84a0bb9a 100644 --- a/tests/src/integration/no-unused-vars.ts +++ b/tests/src/integration/no-unused-vars.ts @@ -1,10 +1,12 @@ -import { RuleTester, Linter } from 'eslint'; +import type { Rule } from 'eslint'; +import { getCoreRule } from '../../../src/utils/eslint-core'; +import { RuleTester } from '../../utils/eslint-compat'; describe('Integration test for no-unused-vars', () => { - const ruleNoUnusedVars = new Linter().getRules().get('no-unused-vars')!; + const ruleNoUnusedVars = getCoreRule('no-unused-vars') as unknown as Rule.RuleModule; const tester = new RuleTester({ - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + languageOptions: { + parser: require('svelte-eslint-parser'), ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/@typescript-eslint/no-unnecessary-condition.ts b/tests/src/rules/@typescript-eslint/no-unnecessary-condition.ts index 7941caaf0..e15bc7b3f 100644 --- a/tests/src/rules/@typescript-eslint/no-unnecessary-condition.ts +++ b/tests/src/rules/@typescript-eslint/no-unnecessary-condition.ts @@ -1,16 +1,18 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../../utils/eslint-compat'; import rule from '../../../../src/rules/@typescript-eslint/no-unnecessary-condition'; import { loadTestCases, RULES_PROJECT } from '../../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module', - parser: { - ts: '@typescript-eslint/parser', - js: 'espree' - }, - project: RULES_PROJECT + parserOptions: { + parser: { + ts: '@typescript-eslint/parser', + js: 'espree' + }, + project: RULES_PROJECT + } } }); diff --git a/tests/src/rules/@typescript-eslint/original-tests/no-unnecessary-condition.ts b/tests/src/rules/@typescript-eslint/original-tests/no-unnecessary-condition.ts index 8f482b3c2..624ee2456 100644 --- a/tests/src/rules/@typescript-eslint/original-tests/no-unnecessary-condition.ts +++ b/tests/src/rules/@typescript-eslint/original-tests/no-unnecessary-condition.ts @@ -2,7 +2,8 @@ // https://github.com/typescript-eslint/typescript-eslint/blob/78467fc1bde9bd2db1e08b3d19f151f4adaff8a9/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts /* eslint func-style: off, eslint-plugin/consistent-output: off -- respect original */ import * as path from 'path'; -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../../../utils/eslint-compat'; +import type * as eslint from 'eslint'; import rule from '../../../../../src/rules/@typescript-eslint/no-unnecessary-condition'; @@ -13,25 +14,27 @@ function getFixturesRootDir(): string { const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ - parser: require.resolve('@typescript-eslint/parser'), - parserOptions: { - tsconfigRootDir: rootPath, - project: './tsconfig.json' + languageOptions: { + parser: require('@typescript-eslint/parser'), + parserOptions: { + tsconfigRootDir: rootPath, + project: './tsconfig.json' + } } }); -function withFileName( - list: (string | TestCase)[] -): TestCase[] { - return list.map((e) => { +function withFileName< + TestCase extends eslint.RuleTester.ValidTestCase | eslint.RuleTester.InvalidTestCase +>(list: (string | TestCase)[]): TestCase[] { + return list.map((e: any) => { if (typeof e === 'string') { return { code: e, filename: path.join(rootPath, 'file.ts') } as TestCase; } if (e.filename) return e; return { ...e, - filename: e.parserOptions?.tsconfigRootDir - ? path.join(e.parserOptions.tsconfigRootDir, 'file.ts') + filename: e.languageOptions?.parserOptions?.tsconfigRootDir + ? path.join(e.languageOptions?.parserOptions.tsconfigRootDir, 'file.ts') : path.join(rootPath, 'file.ts') } as TestCase; }); @@ -60,7 +63,7 @@ const t1 = b1 && b2; const unnecessaryConditionTest = ( condition: string, messageId: string -): RuleTester.InvalidTestCase => ({ +): eslint.RuleTester.InvalidTestCase => ({ code: necessaryConditionTest(condition), errors: [ruleError(4, 12, messageId)] }); @@ -536,8 +539,10 @@ if (x) { allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: true } ], - parserOptions: { - tsconfigRootDir: path.join(rootPath, 'unstrict') + languageOptions: { + parserOptions: { + tsconfigRootDir: path.join(rootPath, 'unstrict') + } } } ]), @@ -1539,8 +1544,10 @@ declare const x: string[] | null; if (x) { } `, - parserOptions: { - tsconfigRootDir: path.join(rootPath, 'unstrict') + languageOptions: { + parserOptions: { + tsconfigRootDir: path.join(rootPath, 'unstrict') + } }, errors: [ { diff --git a/tests/src/rules/block-lang.ts b/tests/src/rules/block-lang.ts index 343c41063..fb32f4901 100644 --- a/tests/src/rules/block-lang.ts +++ b/tests/src/rules/block-lang.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/block-lang'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/button-has-type.ts b/tests/src/rules/button-has-type.ts index 2b8c8b118..099d8aea6 100644 --- a/tests/src/rules/button-has-type.ts +++ b/tests/src/rules/button-has-type.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/button-has-type'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/comment-directive.ts b/tests/src/rules/comment-directive.ts index 9e675b28a..91c17de43 100644 --- a/tests/src/rules/comment-directive.ts +++ b/tests/src/rules/comment-directive.ts @@ -1,30 +1,33 @@ import assert from 'assert'; -import eslint from 'eslint'; import plugin from '../../../src/index'; +import { ESLint } from '../../utils/eslint-compat'; // ----------------------------------------------------------------------------- // Tests // ----------------------------------------------------------------------------- // Initialize linter. -const linter = new eslint.ESLint({ - plugins: { - svelte: plugin as never - }, +const linter = new ESLint({ baseConfig: { - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + languageOptions: { + parser: require('svelte-eslint-parser'), ecmaVersion: 2020 }, - plugins: ['svelte'], + plugins: { + // @ts-expect-error -- Type error for eslint v9 + svelte: plugin + }, rules: { 'no-undef': 'error', 'space-infix-ops': 'error', 'svelte/no-at-html-tags': 'error', 'svelte/comment-directive': 'error' - } + }, + processor: 'svelte/svelte', + files: ['**'] }, - useEslintrc: false + // @ts-expect-error -- Type error for eslint v9 + overrideConfigFile: true }); describe('comment-directive', () => { @@ -348,24 +351,27 @@ describe('comment-directive', () => { }); describe('reportUnusedDisableDirectives', () => { - const linter = new eslint.ESLint({ - plugins: { - svelte: plugin as never - }, + const linter = new ESLint({ baseConfig: { - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { - ecmaVersion: 2015 + languageOptions: { + parser: require('svelte-eslint-parser'), + ecmaVersion: 2020 + }, + plugins: { + // @ts-expect-error -- Type error for eslint v9 + svelte: plugin }, - plugins: ['svelte'], rules: { 'no-unused-vars': 'error', 'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }], 'svelte/no-at-html-tags': 'error', 'svelte/no-at-debug-tags': 'error' - } + }, + files: ['**'], + processor: 'svelte/svelte' }, - useEslintrc: false + // @ts-expect-error -- Type error for eslint v9 + overrideConfigFile: true }); it('report unused ', async () => { const code = ` diff --git a/tests/src/rules/derived-has-same-inputs-outputs.ts b/tests/src/rules/derived-has-same-inputs-outputs.ts index 51be96a55..59b67718f 100644 --- a/tests/src/rules/derived-has-same-inputs-outputs.ts +++ b/tests/src/rules/derived-has-same-inputs-outputs.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/derived-has-same-inputs-outputs'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/experimental-require-slot-types.ts b/tests/src/rules/experimental-require-slot-types.ts index 6cb1d22d4..6c4bdab9d 100644 --- a/tests/src/rules/experimental-require-slot-types.ts +++ b/tests/src/rules/experimental-require-slot-types.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/experimental-require-slot-types'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/experimental-require-strict-events.ts b/tests/src/rules/experimental-require-strict-events.ts index 52b926ef3..83ac9d1f4 100644 --- a/tests/src/rules/experimental-require-strict-events.ts +++ b/tests/src/rules/experimental-require-strict-events.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/experimental-require-strict-events'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/first-attribute-linebreak.ts b/tests/src/rules/first-attribute-linebreak.ts index 39bd5979f..ca40292a1 100644 --- a/tests/src/rules/first-attribute-linebreak.ts +++ b/tests/src/rules/first-attribute-linebreak.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/first-attribute-linebreak'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/html-closing-bracket-spacing.ts b/tests/src/rules/html-closing-bracket-spacing.ts index af715163b..743815046 100644 --- a/tests/src/rules/html-closing-bracket-spacing.ts +++ b/tests/src/rules/html-closing-bracket-spacing.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/html-closing-bracket-spacing'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/html-quotes.ts b/tests/src/rules/html-quotes.ts index 285332ebf..b85d60d6d 100644 --- a/tests/src/rules/html-quotes.ts +++ b/tests/src/rules/html-quotes.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/html-quotes'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/html-self-closing.ts b/tests/src/rules/html-self-closing.ts index 516cb1e2f..f6990dfca 100644 --- a/tests/src/rules/html-self-closing.ts +++ b/tests/src/rules/html-self-closing.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/html-self-closing'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/indent.ts b/tests/src/rules/indent.ts index 422143bac..755121a08 100644 --- a/tests/src/rules/indent.ts +++ b/tests/src/rules/indent.ts @@ -1,14 +1,16 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/indent'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module', - parser: { - ts: '@typescript-eslint/parser', - js: 'espree' + parserOptions: { + parser: { + ts: '@typescript-eslint/parser', + js: 'espree' + } } } }); diff --git a/tests/src/rules/infinite-reactive-loop.ts b/tests/src/rules/infinite-reactive-loop.ts index 37996845a..14872ef54 100644 --- a/tests/src/rules/infinite-reactive-loop.ts +++ b/tests/src/rules/infinite-reactive-loop.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/infinite-reactive-loop'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/max-attributes-per-line.ts b/tests/src/rules/max-attributes-per-line.ts index 82726f722..683d7fd66 100644 --- a/tests/src/rules/max-attributes-per-line.ts +++ b/tests/src/rules/max-attributes-per-line.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/max-attributes-per-line'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/mustache-spacing.ts b/tests/src/rules/mustache-spacing.ts index 833ed14ab..51d6941ca 100644 --- a/tests/src/rules/mustache-spacing.ts +++ b/tests/src/rules/mustache-spacing.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/mustache-spacing'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-at-debug-tags.ts b/tests/src/rules/no-at-debug-tags.ts index d41cc7efb..c7530044a 100644 --- a/tests/src/rules/no-at-debug-tags.ts +++ b/tests/src/rules/no-at-debug-tags.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-at-debug-tags'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-at-html-tags.ts b/tests/src/rules/no-at-html-tags.ts index abfb73ffc..308df8458 100644 --- a/tests/src/rules/no-at-html-tags.ts +++ b/tests/src/rules/no-at-html-tags.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-at-html-tags'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dom-manipulating.ts b/tests/src/rules/no-dom-manipulating.ts index 09132a1e0..9b307ad75 100644 --- a/tests/src/rules/no-dom-manipulating.ts +++ b/tests/src/rules/no-dom-manipulating.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dom-manipulating'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dupe-else-if-blocks.ts b/tests/src/rules/no-dupe-else-if-blocks.ts index dc1e325f7..df69710d0 100644 --- a/tests/src/rules/no-dupe-else-if-blocks.ts +++ b/tests/src/rules/no-dupe-else-if-blocks.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dupe-else-if-blocks'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dupe-on-directives.ts b/tests/src/rules/no-dupe-on-directives.ts index d645b4808..cd6ccf632 100644 --- a/tests/src/rules/no-dupe-on-directives.ts +++ b/tests/src/rules/no-dupe-on-directives.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dupe-on-directives'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dupe-style-properties.ts b/tests/src/rules/no-dupe-style-properties.ts index efe30999d..7a7b1ae1c 100644 --- a/tests/src/rules/no-dupe-style-properties.ts +++ b/tests/src/rules/no-dupe-style-properties.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dupe-style-properties'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dupe-use-directives.ts b/tests/src/rules/no-dupe-use-directives.ts index c0a2cc039..047371778 100644 --- a/tests/src/rules/no-dupe-use-directives.ts +++ b/tests/src/rules/no-dupe-use-directives.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dupe-use-directives'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-dynamic-slot-name.ts b/tests/src/rules/no-dynamic-slot-name.ts index e39931ed2..0612e657f 100644 --- a/tests/src/rules/no-dynamic-slot-name.ts +++ b/tests/src/rules/no-dynamic-slot-name.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-dynamic-slot-name'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-export-load-in-svelte-module-in-kit-pages.ts b/tests/src/rules/no-export-load-in-svelte-module-in-kit-pages.ts index cbf495a9a..a5ff796d5 100644 --- a/tests/src/rules/no-export-load-in-svelte-module-in-kit-pages.ts +++ b/tests/src/rules/no-export-load-in-svelte-module-in-kit-pages.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-export-load-in-svelte-module-in-kit-pages'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-extra-reactive-curlies.ts b/tests/src/rules/no-extra-reactive-curlies.ts index 92e2a43d7..ea5278c7c 100644 --- a/tests/src/rules/no-extra-reactive-curlies.ts +++ b/tests/src/rules/no-extra-reactive-curlies.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-extra-reactive-curlies'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-ignored-unsubscribe.ts b/tests/src/rules/no-ignored-unsubscribe.ts index 2d3bd2d3e..8334d44f6 100644 --- a/tests/src/rules/no-ignored-unsubscribe.ts +++ b/tests/src/rules/no-ignored-unsubscribe.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-ignored-unsubscribe'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-immutable-reactive-statements.ts b/tests/src/rules/no-immutable-reactive-statements.ts index 446c2c9b6..e6fbe3fed 100644 --- a/tests/src/rules/no-immutable-reactive-statements.ts +++ b/tests/src/rules/no-immutable-reactive-statements.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-immutable-reactive-statements'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-inline-styles.ts b/tests/src/rules/no-inline-styles.ts index e45d7bb5f..19f8356c3 100644 --- a/tests/src/rules/no-inline-styles.ts +++ b/tests/src/rules/no-inline-styles.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-inline-styles'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-inner-declarations.ts b/tests/src/rules/no-inner-declarations.ts index 0bfcd6c56..19d2f80be 100644 --- a/tests/src/rules/no-inner-declarations.ts +++ b/tests/src/rules/no-inner-declarations.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-inner-declarations'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-not-function-handler.ts b/tests/src/rules/no-not-function-handler.ts index 8c197796e..e6d44c17a 100644 --- a/tests/src/rules/no-not-function-handler.ts +++ b/tests/src/rules/no-not-function-handler.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-not-function-handler'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-object-in-text-mustaches.ts b/tests/src/rules/no-object-in-text-mustaches.ts index bae74601a..afb2f7bfd 100644 --- a/tests/src/rules/no-object-in-text-mustaches.ts +++ b/tests/src/rules/no-object-in-text-mustaches.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-object-in-text-mustaches'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-reactive-functions.ts b/tests/src/rules/no-reactive-functions.ts index da97b092e..8b2e0b494 100644 --- a/tests/src/rules/no-reactive-functions.ts +++ b/tests/src/rules/no-reactive-functions.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-reactive-functions'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-reactive-literals.ts b/tests/src/rules/no-reactive-literals.ts index 4d9597798..509ccf425 100644 --- a/tests/src/rules/no-reactive-literals.ts +++ b/tests/src/rules/no-reactive-literals.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-reactive-literals'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-reactive-reassign.ts b/tests/src/rules/no-reactive-reassign.ts index ff5882dd7..c03f73e09 100644 --- a/tests/src/rules/no-reactive-reassign.ts +++ b/tests/src/rules/no-reactive-reassign.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-reactive-reassign'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-restricted-html-elements.ts b/tests/src/rules/no-restricted-html-elements.ts index 9683052c8..f6853fc72 100644 --- a/tests/src/rules/no-restricted-html-elements.ts +++ b/tests/src/rules/no-restricted-html-elements.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-restricted-html-elements'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-shorthand-style-property-overrides.ts b/tests/src/rules/no-shorthand-style-property-overrides.ts index 1ef50ab82..c6c81ef4d 100644 --- a/tests/src/rules/no-shorthand-style-property-overrides.ts +++ b/tests/src/rules/no-shorthand-style-property-overrides.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-shorthand-style-property-overrides'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-spaces-around-equal-signs-in-attribute.ts b/tests/src/rules/no-spaces-around-equal-signs-in-attribute.ts index d17209d52..02a77c373 100644 --- a/tests/src/rules/no-spaces-around-equal-signs-in-attribute.ts +++ b/tests/src/rules/no-spaces-around-equal-signs-in-attribute.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-spaces-around-equal-signs-in-attribute'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-store-async.ts b/tests/src/rules/no-store-async.ts index 55d9157fe..9798939ed 100644 --- a/tests/src/rules/no-store-async.ts +++ b/tests/src/rules/no-store-async.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-store-async'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-target-blank.ts b/tests/src/rules/no-target-blank.ts index 2ce41699a..fad79e8d9 100644 --- a/tests/src/rules/no-target-blank.ts +++ b/tests/src/rules/no-target-blank.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-target-blank'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-trailing-spaces.ts b/tests/src/rules/no-trailing-spaces.ts index ebfc697f4..f4ff8e22b 100644 --- a/tests/src/rules/no-trailing-spaces.ts +++ b/tests/src/rules/no-trailing-spaces.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-trailing-spaces'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-unknown-style-directive-property.ts b/tests/src/rules/no-unknown-style-directive-property.ts index 695faae5e..933ca725e 100644 --- a/tests/src/rules/no-unknown-style-directive-property.ts +++ b/tests/src/rules/no-unknown-style-directive-property.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-unknown-style-directive-property'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-unused-class-name.ts b/tests/src/rules/no-unused-class-name.ts index 2cf9a4004..74d300c49 100644 --- a/tests/src/rules/no-unused-class-name.ts +++ b/tests/src/rules/no-unused-class-name.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-unused-class-name'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-unused-svelte-ignore.ts b/tests/src/rules/no-unused-svelte-ignore.ts index d8b782f00..3dd84174d 100644 --- a/tests/src/rules/no-unused-svelte-ignore.ts +++ b/tests/src/rules/no-unused-svelte-ignore.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-unused-svelte-ignore'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/no-useless-mustaches.ts b/tests/src/rules/no-useless-mustaches.ts index a5e8dad9d..43d694d3d 100644 --- a/tests/src/rules/no-useless-mustaches.ts +++ b/tests/src/rules/no-useless-mustaches.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/no-useless-mustaches'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/prefer-class-directive.ts b/tests/src/rules/prefer-class-directive.ts index 9371b06f2..04396297e 100644 --- a/tests/src/rules/prefer-class-directive.ts +++ b/tests/src/rules/prefer-class-directive.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/prefer-class-directive'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/prefer-destructured-store-props.ts b/tests/src/rules/prefer-destructured-store-props.ts index fcaf1a366..9c48dd52f 100644 --- a/tests/src/rules/prefer-destructured-store-props.ts +++ b/tests/src/rules/prefer-destructured-store-props.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/prefer-destructured-store-props'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/prefer-style-directive.ts b/tests/src/rules/prefer-style-directive.ts index 7783d3e9f..c6a8fea60 100644 --- a/tests/src/rules/prefer-style-directive.ts +++ b/tests/src/rules/prefer-style-directive.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/prefer-style-directive'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-each-key.ts b/tests/src/rules/require-each-key.ts index 1b394e222..05c10009d 100644 --- a/tests/src/rules/require-each-key.ts +++ b/tests/src/rules/require-each-key.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-each-key'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-event-dispatcher-types.ts b/tests/src/rules/require-event-dispatcher-types.ts index 853e140af..7e11ea5c5 100644 --- a/tests/src/rules/require-event-dispatcher-types.ts +++ b/tests/src/rules/require-event-dispatcher-types.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-event-dispatcher-types'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-optimized-style-attribute.ts b/tests/src/rules/require-optimized-style-attribute.ts index 7b82c7bdb..6edd26be4 100644 --- a/tests/src/rules/require-optimized-style-attribute.ts +++ b/tests/src/rules/require-optimized-style-attribute.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-optimized-style-attribute'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-store-callbacks-use-set-param.ts b/tests/src/rules/require-store-callbacks-use-set-param.ts index 9fc8bc3a2..f79c1eeee 100644 --- a/tests/src/rules/require-store-callbacks-use-set-param.ts +++ b/tests/src/rules/require-store-callbacks-use-set-param.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-store-callbacks-use-set-param'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-store-reactive-access.ts b/tests/src/rules/require-store-reactive-access.ts index 3a7f8103b..be250ac63 100644 --- a/tests/src/rules/require-store-reactive-access.ts +++ b/tests/src/rules/require-store-reactive-access.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-store-reactive-access'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/require-stores-init.ts b/tests/src/rules/require-stores-init.ts index 60e5628ff..ee31ee1dc 100644 --- a/tests/src/rules/require-stores-init.ts +++ b/tests/src/rules/require-stores-init.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/require-stores-init'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/shorthand-attribute.ts b/tests/src/rules/shorthand-attribute.ts index cfdb9a75a..62507651b 100644 --- a/tests/src/rules/shorthand-attribute.ts +++ b/tests/src/rules/shorthand-attribute.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/shorthand-attribute'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/shorthand-directive.ts b/tests/src/rules/shorthand-directive.ts index aa96bbaab..580c99731 100644 --- a/tests/src/rules/shorthand-directive.ts +++ b/tests/src/rules/shorthand-directive.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/shorthand-directive'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/sort-attributes.ts b/tests/src/rules/sort-attributes.ts index a2f924533..5b07319e5 100644 --- a/tests/src/rules/sort-attributes.ts +++ b/tests/src/rules/sort-attributes.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/sort-attributes'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/spaced-html-comment.ts b/tests/src/rules/spaced-html-comment.ts index aa5e81a25..a4a724627 100644 --- a/tests/src/rules/spaced-html-comment.ts +++ b/tests/src/rules/spaced-html-comment.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/spaced-html-comment'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/valid-compile.ts b/tests/src/rules/valid-compile.ts index ec01a7bae..0a6be1c0c 100644 --- a/tests/src/rules/valid-compile.ts +++ b/tests/src/rules/valid-compile.ts @@ -1,14 +1,13 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/valid-compile'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module', - parser: { - ts: '@typescript-eslint/parser', - js: 'espree' + parserOptions: { + parser: '@typescript-eslint/parser' } } }); diff --git a/tests/src/rules/valid-each-key.ts b/tests/src/rules/valid-each-key.ts index 4da363ad0..2a2c4ae5e 100644 --- a/tests/src/rules/valid-each-key.ts +++ b/tests/src/rules/valid-each-key.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/valid-each-key'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/rules/valid-prop-names-in-kit-pages.ts b/tests/src/rules/valid-prop-names-in-kit-pages.ts index 8cbb7c646..63c36cb7a 100644 --- a/tests/src/rules/valid-prop-names-in-kit-pages.ts +++ b/tests/src/rules/valid-prop-names-in-kit-pages.ts @@ -1,9 +1,9 @@ -import { RuleTester } from 'eslint'; +import { RuleTester } from '../../utils/eslint-compat'; import rule from '../../../src/rules/valid-prop-names-in-kit-pages'; import { loadTestCases } from '../../utils/utils'; const tester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2020, sourceType: 'module' } diff --git a/tests/src/settings/ignore-warnings.ts b/tests/src/settings/ignore-warnings.ts index 1beffa65e..23dcabd75 100644 --- a/tests/src/settings/ignore-warnings.ts +++ b/tests/src/settings/ignore-warnings.ts @@ -1,6 +1,6 @@ import assert from 'assert'; -import eslint from 'eslint'; import plugin from '../../../src/index'; +import { ESLint } from '../../utils/eslint-compat'; describe('ignore-warnings', () => { it('disable rules if ignoreWarnings: [ruleName]', async () => { @@ -14,16 +14,17 @@ describe('ignore-warnings', () => { {@debug a} `; - const linter = new eslint.ESLint({ - plugins: { - svelte: plugin as never - }, + const linter = new ESLint({ baseConfig: { - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + files: ['**'], + languageOptions: { + parser: require('svelte-eslint-parser'), ecmaVersion: 2020 }, - plugins: ['svelte'], + plugins: { + // @ts-expect-error -- Type error for eslint v9 + svelte: plugin as never + }, rules: { 'no-undef': 'error', 'space-infix-ops': 'error', @@ -35,9 +36,11 @@ describe('ignore-warnings', () => { svelte: { ignoreWarnings: ['no-undef', 'space-infix-ops', 'svelte/no-at-debug-tags'] } - } + }, + processor: 'svelte/svelte' }, - useEslintrc: false + // @ts-expect-error -- Type error for eslint v9 + overrideConfigFile: true }); const result = await linter.lintText(code, { filePath: 'test.svelte' }); const messages = result[0].messages; @@ -79,16 +82,17 @@ describe('ignore-warnings', () => { {@debug a} `; - const linter = new eslint.ESLint({ - plugins: { - svelte: plugin as never - }, + const linter = new ESLint({ baseConfig: { - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + files: ['**'], + languageOptions: { + parser: require('svelte-eslint-parser'), ecmaVersion: 2020 }, - plugins: ['svelte'], + plugins: { + // @ts-expect-error -- Type error for eslint v9 + svelte: plugin as never + }, rules: { 'no-undef': 'error', 'space-infix-ops': 'error', @@ -100,9 +104,11 @@ describe('ignore-warnings', () => { svelte: { ignoreWarnings: ['no-undef', '/debug/', '/^space/'] } - } + }, + processor: 'svelte/svelte' }, - useEslintrc: false + // @ts-expect-error -- Type error for eslint v9 + overrideConfigFile: true }); const result = await linter.lintText(code, { filePath: 'test.svelte' }); const messages = result[0].messages; @@ -145,21 +151,24 @@ describe('ignore-warnings', () => { {@debug a} `; - const linter = new eslint.ESLint({ - plugins: { - svelte: plugin as never - }, + const linter = new ESLint({ baseConfig: { - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + files: ['**'], + languageOptions: { + parser: require('svelte-eslint-parser'), ecmaVersion: 2020 }, - plugins: ['svelte'], + plugins: { + // @ts-expect-error -- Type error for eslint v9 + svelte: plugin as never + }, rules: { 'svelte/system': 'error' - } + }, + processor: 'svelte/svelte' }, - useEslintrc: false + // @ts-expect-error -- Type error for eslint v9 + overrideConfigFile: true }); const result = await linter.lintText(code, { filePath: 'test.svelte' }); const messages = result[0].messages; diff --git a/tests/utils/eslint-compat.ts b/tests/utils/eslint-compat.ts new file mode 100644 index 000000000..7cfa3ddc7 --- /dev/null +++ b/tests/utils/eslint-compat.ts @@ -0,0 +1,9 @@ +import { getLegacyESLint, getESLint } from 'eslint-compat-utils/eslint'; +import { getLinter } from 'eslint-compat-utils/linter'; +import { getRuleTester, getRuleIdPrefix } from 'eslint-compat-utils/rule-tester'; + +export const LegacyESLint = getLegacyESLint(); +export const ESLint = getESLint(); +export const RuleTester = getRuleTester(); +export const TEST_RULE_ID_PREFIX = getRuleIdPrefix(); +export const Linter = getLinter(); diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index 2efea0830..56b24b29a 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -1,16 +1,22 @@ import fs from 'fs'; import path from 'path'; import type { RuleTester } from 'eslint'; -import { Linter } from 'eslint'; -import * as svelteESLintParser from 'svelte-eslint-parser'; -import * as typescriptESLintParser from '@typescript-eslint/parser'; -// eslint-disable-next-line @typescript-eslint/no-require-imports -- tests +import type { Linter as LinterType } from 'eslint'; import plugin = require('../../src/index'); import { applyFixes } from './source-code-fixer'; import { parse as parseYaml, stringify as stringifyYaml } from 'yaml'; import semver from 'semver'; import { writeAndFormat } from '../../tools/lib/write'; - +import { Linter } from './eslint-compat'; + +const globals = { + console: 'readonly', + setTimeout: 'readonly', + setInterval: 'readonly', + queueMicrotask: 'readonly', + window: 'readonly', + globalThis: 'readonly' +}; /** * Prevents leading spaces in a multiline template literal from appearing in the resulting string */ @@ -94,10 +100,7 @@ export function loadTestCases( Object.entries(requirements).some(([pkgName, pkgVersion]) => { if (pkgName === 'FIXME') return false; // Comments const pkg = - pkgName === 'node' - ? { version: process.version } - : // eslint-disable-next-line @typescript-eslint/no-require-imports -- test - require(`${pkgName}/package.json`); + pkgName === 'node' ? { version: process.version } : require(`${pkgName}/package.json`); return !semver.satisfies(pkg.version, pkgVersion); }) ) { @@ -189,14 +192,14 @@ function* itrListupInput(rootDir: string): IterableIterator { // Necessary because of this: // https://github.com/eslint/eslint/issues/14936#issuecomment-906746754 -function applySuggestion(code: string, suggestion: Linter.LintSuggestion) { +function applySuggestion(code: string, suggestion: LinterType.LintSuggestion) { const { fix } = suggestion; return `${code.slice(0, fix.range[0])}${fix.text}${code.slice(fix.range[1])}`; } function writeFixtures(ruleName: string, inputFile: string, { force }: { force?: boolean } = {}) { - const linter = getLinter(ruleName); + const linter = new Linter(); const errorFile = inputFile.replace(/input\.[a-z]+$/u, 'errors.yaml'); const outputFile = inputFile.replace(/input\.[a-z]+$/u, 'output.svelte'); @@ -204,27 +207,41 @@ function writeFixtures(ruleName: string, inputFile: string, { force }: { force?: const parser = path.extname(inputFile) === '.svelte' - ? 'svelte-eslint-parser' + ? require('svelte-eslint-parser') : path.extname(inputFile) === '.ts' - ? '@typescript-eslint/parser' + ? require('@typescript-eslint/parser') : undefined; const { code, filename, options, ...verifyConfig } = config; + const resolvedParser = verifyConfig.languageOptions?.parser ?? parser; const result = linter.verify( code, { + files: ['**'], ...verifyConfig, + plugins: { + svelte: plugin + }, rules: { - [ruleName]: ['error', ...(options || [])] + [`svelte/${ruleName}`]: ['error', ...(options || [])] }, - parser, - parserOptions: { + languageOptions: { + globals, ecmaVersion: 2020, sourceType: 'module', - parser: { - ts: '@typescript-eslint/parser', - js: 'espree' + ...verifyConfig?.languageOptions, + parserOptions: { + project: RULES_PROJECT, + parser: { + ts: '@typescript-eslint/parser', + js: 'espree' + }, + ...verifyConfig.languageOptions?.parserOptions }, - ...verifyConfig.parserOptions + ...(resolvedParser + ? { + parser: resolvedParser + } + : {}) } }, filename @@ -260,17 +277,6 @@ function writeFixtures(ruleName: string, inputFile: string, { force }: { force?: } } -function getLinter(ruleName: string) { - const linter = new Linter(); - // @ts-expect-error for test - linter.defineParser('svelte-eslint-parser', svelteESLintParser); - // @ts-expect-error for test - linter.defineParser('@typescript-eslint/parser', typescriptESLintParser); - linter.defineRule(ruleName, plugin.rules[ruleName] as any); - - return linter; -} - function getConfig(ruleName: string, inputFile: string) { const filename = inputFile.slice(inputFile.indexOf(ruleName)); const code = fs.readFileSync(inputFile, 'utf8'); @@ -284,31 +290,38 @@ function getConfig(ruleName: string, inputFile: string) { } const parser = path.extname(filename) === '.svelte' - ? require.resolve('svelte-eslint-parser') + ? require('svelte-eslint-parser') : path.extname(inputFile) === '.ts' - ? require.resolve('@typescript-eslint/parser') + ? require('@typescript-eslint/parser') : undefined; + const resolvedParser = config?.languageOptions?.parser + ? require(config.languageOptions.parser) + : parser; return Object.assign( { - parser, - parserOptions: { - project: RULES_PROJECT, - parser: { - ts: '@typescript-eslint/parser', - js: 'espree' + ...config, + languageOptions: { + globals, + ecmaVersion: 2020, + sourceType: 'module', + ...config?.languageOptions, + parserOptions: { + project: RULES_PROJECT, + parser: { + ts: '@typescript-eslint/parser', + js: 'espree' + }, + extraFileExtensions: ['.svelte'], + ...config?.languageOptions?.parserOptions }, - extraFileExtensions: ['.svelte'] - }, - env: { - browser: true, - es2017: true - }, - globals: { - console: 'readonly' + ...(resolvedParser + ? { + parser: resolvedParser + } + : {}) } }, - config, { code, filename: inputFile } ); } diff --git a/tools/new-rule.ts b/tools/new-rule.ts index a3417d0bf..14b86f83a 100644 --- a/tools/new-rule.ts +++ b/tools/new-rule.ts @@ -70,15 +70,15 @@ export default createRule('${ruleId}', { ); await writeAndFormat( testFile, - `import { RuleTester } from 'eslint'; + `import { RuleTester } from '../../utils/eslint-compat'; import rule from '${getModulePath(testFile, ruleFile)}'; import { loadTestCases } from '${getModulePath(testFile, testUtilsPath)}'; const tester = new RuleTester({ - parserOptions: { - ecmaVersion: 2020, - sourceType: 'module', - }, + languageOptions: { + ecmaVersion: 2020, + sourceType: 'module' + } }); tester.run('${ruleId}', rule as any, loadTestCases('${ruleId}'));