Skip to content

Commit 66ef0d9

Browse files
committed
chore: Use eslint types for configs
1 parent d792c01 commit 66ef0d9

File tree

9 files changed

+109
-83
lines changed

9 files changed

+109
-83
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import path from 'path';
1+
import type { Linter } from 'eslint';
2+
import path from 'node:path';
23
import { rules } from '../utils/rules';
34
const base = require.resolve('./base');
45
const baseExtend = path.extname(`${base}`) === '.ts' ? 'plugin:svelte/base' : base;
5-
export = {
6+
const config: Linter.Config = {
67
extends: [baseExtend],
78
rules: Object.fromEntries(
89
rules
9-
.map((rule) => [`svelte/${rule.meta.docs.ruleName}`, 'error' as const])
10+
.map((rule) => [`svelte/${rule.meta.docs.ruleName}`, 'error'])
1011
.filter(
1112
([ruleName]) =>
1213
![
@@ -16,3 +17,4 @@ export = {
1617
)
1718
)
1819
};
20+
export = config;
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4-
export = {
4+
import type { Linter } from 'eslint';
5+
const config: Linter.Config = {
56
plugins: ['svelte'],
67
overrides: [
78
{
89
files: ['*.svelte'],
910
parser: require.resolve('svelte-eslint-parser'),
1011
rules: {
1112
// ESLint core rules known to cause problems with `.svelte`.
12-
'no-inner-declarations': 'off' as const, // The AST generated by svelte-eslint-parser will false positives in it rule because the root node of the script is not the `Program`.
13-
// "no-irregular-whitespace": "off" as const,
13+
'no-inner-declarations': 'off', // The AST generated by svelte-eslint-parser will false positives in it rule because the root node of the script is not the `Program`.
14+
// "no-irregular-whitespace": "off",
1415
// Self assign is one of way to update reactive value in Svelte.
15-
'no-self-assign': 'off' as const,
16+
'no-self-assign': 'off',
1617

1718
// eslint-plugin-svelte rules
18-
'svelte/comment-directive': 'error' as const,
19-
'svelte/system': 'error' as const
19+
'svelte/comment-directive': 'error',
20+
'svelte/system': 'error'
2021
}
2122
}
2223
]
2324
};
25+
export = config;

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { Linter } from 'eslint';
12
import { rules } from '../../utils/rules';
23
import base from './base';
3-
export default [
4+
const config: Linter.FlatConfig[] = [
45
...base,
56
{
67
rules: Object.fromEntries(
78
rules
8-
.map((rule) => [`svelte/${rule.meta.docs.ruleName}`, 'error' as const])
9+
.map((rule) => [`svelte/${rule.meta.docs.ruleName}`, 'error'])
910
.filter(
1011
([ruleName]) =>
1112
![
@@ -16,3 +17,4 @@ export default [
1617
)
1718
}
1819
];
20+
export default config;

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4-
import type { ESLint } from 'eslint';
5-
export default [
4+
import type { ESLint, Linter } from 'eslint';
5+
const config: Linter.FlatConfig[] = [
66
{
77
plugins: {
88
get svelte(): ESLint.Plugin {
@@ -19,15 +19,16 @@ export default [
1919
},
2020
rules: {
2121
// ESLint core rules known to cause problems with `.svelte`.
22-
'no-inner-declarations': 'off' as const, // The AST generated by svelte-eslint-parser will false positives in it rule because the root node of the script is not the `Program`.
23-
// "no-irregular-whitespace": "off" as const,
22+
'no-inner-declarations': 'off', // The AST generated by svelte-eslint-parser will false positives in it rule because the root node of the script is not the `Program`.
23+
// "no-irregular-whitespace": "off",
2424
// Self assign is one of way to update reactive value in Svelte.
25-
'no-self-assign': 'off' as const,
25+
'no-self-assign': 'off',
2626

2727
// eslint-plugin-svelte rules
28-
'svelte/comment-directive': 'error' as const,
29-
'svelte/system': 'error' as const
28+
'svelte/comment-directive': 'error',
29+
'svelte/system': 'error'
3030
},
3131
processor: 'svelte/svelte'
3232
}
3333
];
34+
export default config;
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4+
import type { Linter } from 'eslint';
45
import base from './base';
5-
export default [
6+
const config: Linter.FlatConfig[] = [
67
...base,
78
{
89
rules: {
910
// eslint-plugin-svelte rules
10-
'svelte/first-attribute-linebreak': 'off' as const,
11-
'svelte/html-closing-bracket-spacing': 'off' as const,
12-
'svelte/html-quotes': 'off' as const,
13-
'svelte/html-self-closing': 'off' as const,
14-
'svelte/indent': 'off' as const,
15-
'svelte/max-attributes-per-line': 'off' as const,
16-
'svelte/mustache-spacing': 'off' as const,
17-
'svelte/no-spaces-around-equal-signs-in-attribute': 'off' as const,
18-
'svelte/no-trailing-spaces': 'off' as const,
19-
'svelte/shorthand-attribute': 'off' as const,
20-
'svelte/shorthand-directive': 'off' as const
11+
'svelte/first-attribute-linebreak': 'off',
12+
'svelte/html-closing-bracket-spacing': 'off',
13+
'svelte/html-quotes': 'off',
14+
'svelte/html-self-closing': 'off',
15+
'svelte/indent': 'off',
16+
'svelte/max-attributes-per-line': 'off',
17+
'svelte/mustache-spacing': 'off',
18+
'svelte/no-spaces-around-equal-signs-in-attribute': 'off',
19+
'svelte/no-trailing-spaces': 'off',
20+
'svelte/shorthand-attribute': 'off',
21+
'svelte/shorthand-directive': 'off'
2122
}
2223
}
2324
];
25+
export default config;
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4+
import type { Linter } from 'eslint';
45
import base from './base';
5-
export default [
6+
const config: Linter.FlatConfig[] = [
67
...base,
78
{
89
rules: {
910
// eslint-plugin-svelte rules
10-
'svelte/comment-directive': 'error' as const,
11-
'svelte/no-at-debug-tags': 'warn' as const,
12-
'svelte/no-at-html-tags': 'error' as const,
13-
'svelte/no-dupe-else-if-blocks': 'error' as const,
14-
'svelte/no-dupe-style-properties': 'error' as const,
15-
'svelte/no-dynamic-slot-name': 'error' as const,
16-
'svelte/no-inner-declarations': 'error' as const,
17-
'svelte/no-not-function-handler': 'error' as const,
18-
'svelte/no-object-in-text-mustaches': 'error' as const,
19-
'svelte/no-shorthand-style-property-overrides': 'error' as const,
20-
'svelte/no-unknown-style-directive-property': 'error' as const,
21-
'svelte/no-unused-svelte-ignore': 'error' as const,
22-
'svelte/system': 'error' as const,
23-
'svelte/valid-compile': 'error' as const
11+
'svelte/comment-directive': 'error',
12+
'svelte/no-at-debug-tags': 'warn',
13+
'svelte/no-at-html-tags': 'error',
14+
'svelte/no-dupe-else-if-blocks': 'error',
15+
'svelte/no-dupe-style-properties': 'error',
16+
'svelte/no-dynamic-slot-name': 'error',
17+
'svelte/no-inner-declarations': 'error',
18+
'svelte/no-not-function-handler': 'error',
19+
'svelte/no-object-in-text-mustaches': 'error',
20+
'svelte/no-shorthand-style-property-overrides': 'error',
21+
'svelte/no-unknown-style-directive-property': 'error',
22+
'svelte/no-unused-svelte-ignore': 'error',
23+
'svelte/system': 'error',
24+
'svelte/valid-compile': 'error'
2425
}
2526
}
2627
];
28+
export default config;
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4-
import path from 'path';
4+
import type { Linter } from 'eslint';
5+
import path from 'node:path';
56
const base = require.resolve('./base');
67
const baseExtend = path.extname(`${base}`) === '.ts' ? 'plugin:svelte/base' : base;
7-
export = {
8+
const config: Linter.Config = {
89
extends: [baseExtend],
910
rules: {
1011
// eslint-plugin-svelte rules
11-
'svelte/first-attribute-linebreak': 'off' as const,
12-
'svelte/html-closing-bracket-spacing': 'off' as const,
13-
'svelte/html-quotes': 'off' as const,
14-
'svelte/html-self-closing': 'off' as const,
15-
'svelte/indent': 'off' as const,
16-
'svelte/max-attributes-per-line': 'off' as const,
17-
'svelte/mustache-spacing': 'off' as const,
18-
'svelte/no-spaces-around-equal-signs-in-attribute': 'off' as const,
19-
'svelte/no-trailing-spaces': 'off' as const,
20-
'svelte/shorthand-attribute': 'off' as const,
21-
'svelte/shorthand-directive': 'off' as const
12+
'svelte/first-attribute-linebreak': 'off',
13+
'svelte/html-closing-bracket-spacing': 'off',
14+
'svelte/html-quotes': 'off',
15+
'svelte/html-self-closing': 'off',
16+
'svelte/indent': 'off',
17+
'svelte/max-attributes-per-line': 'off',
18+
'svelte/mustache-spacing': 'off',
19+
'svelte/no-spaces-around-equal-signs-in-attribute': 'off',
20+
'svelte/no-trailing-spaces': 'off',
21+
'svelte/shorthand-attribute': 'off',
22+
'svelte/shorthand-directive': 'off'
2223
}
2324
};
25+
export = config;
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4-
import path from 'path';
4+
import type { Linter } from 'eslint';
5+
import path from 'node:path';
56
const base = require.resolve('./base');
67
const baseExtend = path.extname(`${base}`) === '.ts' ? 'plugin:svelte/base' : base;
7-
export = {
8+
const config: Linter.Config = {
89
extends: [baseExtend],
910
rules: {
1011
// eslint-plugin-svelte rules
11-
'svelte/comment-directive': 'error' as const,
12-
'svelte/no-at-debug-tags': 'warn' as const,
13-
'svelte/no-at-html-tags': 'error' as const,
14-
'svelte/no-dupe-else-if-blocks': 'error' as const,
15-
'svelte/no-dupe-style-properties': 'error' as const,
16-
'svelte/no-dynamic-slot-name': 'error' as const,
17-
'svelte/no-inner-declarations': 'error' as const,
18-
'svelte/no-not-function-handler': 'error' as const,
19-
'svelte/no-object-in-text-mustaches': 'error' as const,
20-
'svelte/no-shorthand-style-property-overrides': 'error' as const,
21-
'svelte/no-unknown-style-directive-property': 'error' as const,
22-
'svelte/no-unused-svelte-ignore': 'error' as const,
23-
'svelte/system': 'error' as const,
24-
'svelte/valid-compile': 'error' as const
12+
'svelte/comment-directive': 'error',
13+
'svelte/no-at-debug-tags': 'warn',
14+
'svelte/no-at-html-tags': 'error',
15+
'svelte/no-dupe-else-if-blocks': 'error',
16+
'svelte/no-dupe-style-properties': 'error',
17+
'svelte/no-dynamic-slot-name': 'error',
18+
'svelte/no-inner-declarations': 'error',
19+
'svelte/no-not-function-handler': 'error',
20+
'svelte/no-object-in-text-mustaches': 'error',
21+
'svelte/no-shorthand-style-property-overrides': 'error',
22+
'svelte/no-unknown-style-directive-property': 'error',
23+
'svelte/no-unused-svelte-ignore': 'error',
24+
'svelte/system': 'error',
25+
'svelte/valid-compile': 'error'
2526
}
2627
};
28+
export = config;

packages/eslint-plugin-svelte/tools/update-rulesets.ts

+20-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const legacyBaseContent = `/*
1111
* This file has been automatically generated,
1212
* in order to update its content execute "pnpm run update"
1313
*/
14-
export = {
14+
import type { Linter } from 'eslint'
15+
const config: Linter.Config = {
1516
plugins: ["svelte"],
1617
overrides: [
1718
{
@@ -36,6 +37,7 @@ export = {
3637
},
3738
],
3839
}
40+
export = config
3941
`;
4042

4143
const legacyBaseFilePath = path.resolve(__dirname, '../src/configs/base.ts');
@@ -48,11 +50,12 @@ const legacyRecommendedContent = `/*
4850
* This file has been automatically generated,
4951
* in order to update its content execute "pnpm run update"
5052
*/
51-
import path from "path"
53+
import type { Linter } from 'eslint'
54+
import path from "node:path"
5255
const base = require.resolve("./base")
5356
const baseExtend =
5457
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base
55-
export = {
58+
const config: Linter.Config = {
5659
extends: [baseExtend],
5760
rules: {
5861
// eslint-plugin-svelte rules
@@ -65,6 +68,7 @@ export = {
6568
.join(',\n ')},
6669
},
6770
}
71+
export = config
6872
`;
6973

7074
const legacyRecommendedFilePath = path.resolve(__dirname, '../src/configs/recommended.ts');
@@ -77,11 +81,12 @@ const legacyPrettierContent = `/*
7781
* This file has been automatically generated,
7882
* in order to update its content execute "pnpm run update"
7983
*/
80-
import path from "path"
84+
import type { Linter } from 'eslint'
85+
import path from "node:path"
8186
const base = require.resolve("./base")
8287
const baseExtend =
8388
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base
84-
export = {
89+
const config: Linter.Config = {
8590
extends: [baseExtend],
8691
rules: {
8792
// eslint-plugin-svelte rules
@@ -91,6 +96,7 @@ export = {
9196
.join(',\n ')},
9297
},
9398
}
99+
export = config
94100
`;
95101

96102
const legacyPrettierFilePath = path.resolve(__dirname, '../src/configs/prettier.ts');
@@ -107,8 +113,8 @@ const baseContent = `/*
107113
* This file has been automatically generated,
108114
* in order to update its content execute "pnpm run update"
109115
*/
110-
import type { ESLint } from 'eslint';
111-
export default [
116+
import type { ESLint, Linter } from 'eslint';
117+
const config: Linter.FlatConfig[] = [
112118
{
113119
plugins: {
114120
get svelte(): ESLint.Plugin {
@@ -142,6 +148,7 @@ export default [
142148
processor: 'svelte/svelte'
143149
},
144150
]
151+
export default config
145152
`;
146153

147154
const baseFilePath = path.resolve(__dirname, '../src/configs/flat/base.ts');
@@ -154,8 +161,9 @@ const recommendedContent = `/*
154161
* This file has been automatically generated,
155162
* in order to update its content execute "pnpm run update"
156163
*/
164+
import type { Linter } from 'eslint';
157165
import base from "./base"
158-
export default [
166+
const config: Linter.FlatConfig[] = [
159167
...base,
160168
{
161169
rules: {
@@ -170,6 +178,7 @@ export default [
170178
},
171179
}
172180
]
181+
export default config
173182
`;
174183

175184
const recommendedFilePath = path.resolve(__dirname, '../src/configs/flat/recommended.ts');
@@ -182,8 +191,9 @@ const prettierContent = `/*
182191
* This file has been automatically generated,
183192
* in order to update its content execute "pnpm run update"
184193
*/
194+
import type { Linter } from 'eslint';
185195
import base from "./base"
186-
export default [
196+
const config: Linter.FlatConfig[] = [
187197
...base,
188198
{
189199
rules: {
@@ -195,6 +205,7 @@ export default [
195205
},
196206
}
197207
]
208+
export default config
198209
`;
199210

200211
const prettierFilePath = path.resolve(__dirname, '../src/configs/flat/prettier.ts');

0 commit comments

Comments
 (0)