-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathupdate-rulesets.ts
101 lines (91 loc) · 2.76 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
import path from "path"
import fs from "fs"
import { rules } from "./lib/load-rules"
const baseContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "yarn 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 baseFilePath = path.resolve(__dirname, "../src/configs/base.ts")
// Update file.
fs.writeFileSync(baseFilePath, baseContent)
const recommendedContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "yarn 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 recommendedFilePath = path.resolve(
__dirname,
"../src/configs/recommended.ts",
)
// Update file.
fs.writeFileSync(recommendedFilePath, recommendedContent)
const prettierContent = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "yarn 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 prettierFilePath = path.resolve(__dirname, "../src/configs/prettier.ts")
// Update file.
fs.writeFileSync(prettierFilePath, prettierContent)