-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathupdate-rulesets.ts
202 lines (180 loc) · 5.59 KB
/
update-rulesets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import path from 'path';
import { rules } from './lib/load-rules';
import { writeAndFormat } from './lib/write';
// ------------------
// Legacy Config
// ------------------
const legacyBaseContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
export = {
plugins: ["svelte"],
overrides: [
{
files: ["*.svelte"],
parser: require.resolve("svelte-eslint-parser"),
rules: {
// ESLint core rules known to cause problems with \`.svelte\`.
"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\`.
// "no-irregular-whitespace": "off",
// Self assign is one of way to update reactive value in Svelte.
"no-self-assign": "off",
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended === 'base' && !rule.meta.deprecated)
.map((rule) => {
const conf = rule.meta.docs.default || 'error';
return `"${rule.meta.docs.ruleId}": "${conf}"`;
})
.join(',\n ')},
},
},
],
}
`;
const legacyBaseFilePath = path.resolve(__dirname, '../src/configs/base.ts');
// Update file.
void writeAndFormat(legacyBaseFilePath, legacyBaseContent);
const legacyRecommendedContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base
export = {
extends: [baseExtend],
rules: {
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended && !rule.meta.deprecated)
.map((rule) => {
const conf = rule.meta.docs.default || 'error';
return `"${rule.meta.docs.ruleId}": "${conf}"`;
})
.join(',\n ')},
},
}
`;
const legacyRecommendedFilePath = path.resolve(__dirname, '../src/configs/recommended.ts');
// Update file.
void writeAndFormat(legacyRecommendedFilePath, legacyRecommendedContent);
const legacyPrettierContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base
export = {
extends: [baseExtend],
rules: {
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.conflictWithPrettier)
.map((rule) => `"${rule.meta.docs.ruleId}": "off"`)
.join(',\n ')},
},
}
`;
const legacyPrettierFilePath = path.resolve(__dirname, '../src/configs/prettier.ts');
// Update file.
void writeAndFormat(legacyPrettierFilePath, legacyPrettierContent);
// ------------------
// Flat Config
// ------------------
const baseContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
import type { ESLint } from 'eslint';
export default [
{
plugins: {
get svelte(): ESLint.Plugin {
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
return require("../../index")
}
},
},
{
files: ["*.svelte", "**/*.svelte"],
languageOptions: {
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
parser: require('svelte-eslint-parser'),
},
rules: {
// ESLint core rules known to cause problems with \`.svelte\`.
"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\`.
// "no-irregular-whitespace": "off",
// Self assign is one of way to update reactive value in Svelte.
"no-self-assign": "off",
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended === 'base' && !rule.meta.deprecated)
.map((rule) => {
const conf = rule.meta.docs.default || 'error';
return `"${rule.meta.docs.ruleId}": "${conf}"`;
})
.join(',\n ')},
},
},
]
`;
const baseFilePath = path.resolve(__dirname, '../src/configs/flat/base.ts');
// Update file.
void writeAndFormat(baseFilePath, baseContent);
const recommendedContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
import base from "./base"
export default [
...base,
{
rules: {
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended && !rule.meta.deprecated)
.map((rule) => {
const conf = rule.meta.docs.default || 'error';
return `"${rule.meta.docs.ruleId}": "${conf}"`;
})
.join(',\n ')},
},
}
]
`;
const recommendedFilePath = path.resolve(__dirname, '../src/configs/flat/recommended.ts');
// Update file.
void writeAndFormat(recommendedFilePath, recommendedContent);
const prettierContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "pnpm run update"
*/
import base from "./base"
export default [
...base,
{
rules: {
// eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.conflictWithPrettier)
.map((rule) => `"${rule.meta.docs.ruleId}": "off"`)
.join(',\n ')},
},
}
]
`;
const prettierFilePath = path.resolve(__dirname, '../src/configs/flat/prettier.ts');
// Update file.
void writeAndFormat(prettierFilePath, prettierContent);