-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
update-lib-configs.js
78 lines (70 loc) · 1.91 KB
/
update-lib-configs.js
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
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const fs = require("fs")
const path = require("path")
const { ESLint } = require("eslint")
const { categories } = require("./rules")
const Root = path.resolve(__dirname, "../lib/configs")
function wrapCode(code) {
return `/**
* DON'T EDIT THIS FILE.
* This file was generated by "scripts/update-lib-configs.js" script.
*/
"use strict"
module.exports = ${code}
`
}
/** @type {Record<string, import("./rules").Category>} */
const configs = {}
for (const { configName, rules, ...config } of Object.values(categories)) {
if (configs[configName]) {
configs[configName].rules.push(...rules)
} else {
configs[configName] = {
...config,
configName,
rules: [...rules],
}
}
}
for (const {
edition,
rules,
configName,
aboveConfigName,
specKind,
} of Object.values(configs)) {
if (!configName) {
continue
}
const ruleSetting = rules.map((r) => `"es-x/${r.ruleId}":"error"`).join(",")
fs.writeFileSync(
path.join(Root, `${configName}.js`),
wrapCode(`{ plugins: ["es-x"], rules: { ${ruleSetting} } }`),
)
if (aboveConfigName) {
const extendSetting = Object.values(categories)
.filter(
(c) =>
c.edition >= edition &&
c.specKind === specKind &&
!c.experimental &&
c.configName,
)
.map((c) => `require.resolve("./${c.configName}")`)
.join(",")
fs.writeFileSync(
path.join(Root, `${aboveConfigName}.js`),
wrapCode(`{ extends: [${extendSetting}] }`),
)
}
}
format()
async function format() {
ESLint.outputFixes(
await new ESLint({ fix: true }).lintFiles(["lib/configs"]),
)
}