Skip to content

Commit 70db50b

Browse files
committed
chore: drop ESLint compat
Uses the `loadESLint` helper directly from eslint instead.
1 parent 89942db commit 70db50b

File tree

6 files changed

+83
-61
lines changed

6 files changed

+83
-61
lines changed

packages/eslint-plugin-svelte/tests/src/configs/all.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import assert from 'assert';
2-
import semver from 'semver';
32
import plugin from '../../../src/index.js';
4-
import { ESLint } from '../../utils/eslint-compat.js';
3+
import { loadESLint, type ESLint as ESLintClass } from 'eslint';
54

65
describe('`all` config', () => {
6+
let ESLint: typeof ESLintClass;
7+
8+
before(async () => {
9+
ESLint = await loadESLint({ useFlatConfig: true });
10+
});
11+
712
it('`all` config should work. ', async () => {
8-
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
913
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`;
1014

1115
const linter = new ESLint({
12-
overrideConfigFile: true as never,
13-
overrideConfig: plugin.configs['flat/all'] as never
16+
overrideConfigFile: true,
17+
overrideConfig: plugin.configs['flat/all']
1418
});
1519
const result = await linter.lintText(code, { filePath: 'test.svelte' });
1620
const messages = result[0].messages;

packages/eslint-plugin-svelte/tests/src/configs/base.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import assert from 'assert';
2-
import semver from 'semver';
32
import plugin from '../../../src/index.js';
4-
import { ESLint } from '../../utils/eslint-compat.js';
3+
import { loadESLint, type ESLint as ESLintClass } from 'eslint';
54

65
describe('`base` config', () => {
6+
let ESLint: typeof ESLintClass;
7+
8+
before(async () => {
9+
ESLint = await loadESLint({ useFlatConfig: true });
10+
});
11+
712
it('`base` config should work. ', async () => {
8-
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
913
const code = `<script>const a = 1, b = 2;</script>
1014
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
1115
{@html a+b}
1216
{@html a+b}`;
1317
const linter = new ESLint({
14-
overrideConfigFile: true as never,
18+
overrideConfigFile: true,
1519
overrideConfig: [
1620
...plugin.configs['flat/base'],
1721
{
1822
rules: {
1923
'svelte/no-at-html-tags': 'error'
2024
}
2125
}
22-
] as never
26+
]
2327
});
2428
const result = await linter.lintText(code, { filePath: 'test.svelte' });
2529
const messages = result[0].messages;

packages/eslint-plugin-svelte/tests/src/configs/recommended.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import assert from 'assert';
2-
import semver from 'semver';
32
import plugin from '../../../src/index.js';
4-
import { ESLint } from '../../utils/eslint-compat.js';
3+
import { loadESLint, type ESLint as ESLintClass } from 'eslint';
54

65
describe('`recommended` config', () => {
6+
let ESLint: typeof ESLintClass;
7+
8+
before(async () => {
9+
ESLint = await loadESLint({ useFlatConfig: true });
10+
});
11+
712
it('`recommended` config should work. ', async () => {
8-
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
913
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`;
1014

1115
const linter = new ESLint({
12-
overrideConfigFile: true as never,
13-
overrideConfig: plugin.configs['flat/recommended'] as never
16+
overrideConfigFile: true,
17+
overrideConfig: plugin.configs['flat/recommended']
1418
});
1519
const result = await linter.lintText(code, { filePath: 'test.svelte' });
1620
const messages = result[0].messages;

packages/eslint-plugin-svelte/tests/src/rules/comment-directive.ts

+49-43
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
import assert from 'assert';
22
import plugin from '../../../src/index.js';
3-
import { ESLint } from '../../utils/eslint-compat.js';
3+
import { loadESLint, type ESLint as ESLintClass } from 'eslint';
44
import * as svelteParser from 'svelte-eslint-parser';
55

66
// -----------------------------------------------------------------------------
77
// Tests
88
// -----------------------------------------------------------------------------
99

10-
// Initialize linter.
11-
const linter = new ESLint({
12-
// @ts-expect-error -- Type error?
13-
baseConfig: {
14-
languageOptions: {
15-
parser: svelteParser,
16-
ecmaVersion: 2020
17-
},
18-
plugins: {
19-
svelte: plugin
20-
},
21-
rules: {
22-
'no-undef': 'error',
23-
'space-infix-ops': 'error',
24-
'svelte/no-at-html-tags': 'error',
25-
'svelte/comment-directive': 'error'
26-
},
27-
processor: 'svelte/svelte',
28-
files: ['**']
29-
},
30-
overrideConfigFile: true
31-
});
32-
3310
describe('comment-directive', () => {
11+
let ESLint: typeof ESLintClass;
12+
let linter: InstanceType<typeof ESLintClass>;
13+
14+
before(async () => {
15+
ESLint = await loadESLint({ useFlatConfig: true });
16+
linter = new ESLint({
17+
baseConfig: {
18+
languageOptions: {
19+
parser: svelteParser,
20+
ecmaVersion: 2020
21+
},
22+
plugins: {
23+
svelte: plugin
24+
},
25+
rules: {
26+
'no-undef': 'error',
27+
'space-infix-ops': 'error',
28+
'svelte/no-at-html-tags': 'error',
29+
'svelte/comment-directive': 'error'
30+
},
31+
processor: 'svelte/svelte',
32+
files: ['**']
33+
},
34+
overrideConfigFile: true
35+
});
36+
});
37+
3438
describe('eslint-disable/eslint-enable', () => {
3539
it('disable all rules if <!-- eslint-disable -->', async () => {
3640
const code = `
@@ -351,27 +355,29 @@ describe('comment-directive', () => {
351355
});
352356

353357
describe('reportUnusedDisableDirectives', () => {
354-
const linter = new ESLint({
355-
// @ts-expect-error -- Type error?
356-
baseConfig: {
357-
languageOptions: {
358-
parser: svelteParser,
359-
ecmaVersion: 2020
360-
},
361-
plugins: {
362-
svelte: plugin
363-
},
364-
rules: {
365-
'no-unused-vars': 'error',
366-
'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }],
367-
'svelte/no-at-html-tags': 'error',
368-
'svelte/no-at-debug-tags': 'error'
358+
before(() => {
359+
linter = new ESLint({
360+
baseConfig: {
361+
languageOptions: {
362+
parser: svelteParser,
363+
ecmaVersion: 2020
364+
},
365+
plugins: {
366+
svelte: plugin
367+
},
368+
rules: {
369+
'no-unused-vars': 'error',
370+
'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }],
371+
'svelte/no-at-html-tags': 'error',
372+
'svelte/no-at-debug-tags': 'error'
373+
},
374+
files: ['**'],
375+
processor: 'svelte/svelte'
369376
},
370-
files: ['**'],
371-
processor: 'svelte/svelte'
372-
},
373-
overrideConfigFile: true
377+
overrideConfigFile: true
378+
});
374379
});
380+
375381
it('report unused <!-- eslint-disable -->', async () => {
376382
const code = `
377383
<!-- eslint-disable -->

packages/eslint-plugin-svelte/tests/src/settings/ignore-warnings.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import assert from 'assert';
22
import plugin from '../../../src/index.js';
3-
import { ESLint } from '../../utils/eslint-compat.js';
3+
import { loadESLint, type ESLint as ESLintClass } from 'eslint';
44
import * as svelteParser from 'svelte-eslint-parser';
55

66
describe('ignore-warnings', () => {
7+
let ESLint: typeof ESLintClass;
8+
9+
before(async () => {
10+
ESLint = await loadESLint({ useFlatConfig: true });
11+
});
12+
713
it('disable rules if ignoreWarnings: [ruleName]', async () => {
814
const code = `
915
{@html a+b}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { getESLint } from 'eslint-compat-utils/eslint';
21
import { getRuleTester } from 'eslint-compat-utils/rule-tester';
32

4-
export const ESLint = getESLint();
53
export const RuleTester = getRuleTester();

0 commit comments

Comments
 (0)