-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
update-rulesets.ts
85 lines (80 loc) · 1.99 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
import path from "path";
import fs from "fs";
import os from "os";
// import eslint from "eslint"
import { rules } from "./lib/load-rules";
import type { RuleModule } from "../src/types";
const isWin = os.platform().startsWith("win");
const CONFIGS = {
recommended: {
filter(rule: RuleModule) {
return (
rule.meta.docs.categories &&
!rule.meta.deprecated &&
rule.meta.docs.categories.includes("recommended")
);
},
option(rule: RuleModule) {
return rule.meta.docs.default || "error";
},
config: "recommended",
},
standard: {
filter(rule: RuleModule) {
return (
rule.meta.docs.categories &&
!rule.meta.deprecated &&
rule.meta.docs.categories.includes("standard")
);
},
option(rule: RuleModule) {
return rule.meta.docs.default || "error";
},
config: "standard",
},
prettier: {
filter(rule: RuleModule) {
return rule.meta.docs.layout;
},
option(_rule: RuleModule) {
return "off";
},
config: "prettier",
},
};
for (const rec of ["recommended", "standard", "prettier"] as const) {
let content = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "npm run update"
*/
import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(\`\${base}\`) === ".ts" ? "plugin:yml/base" : base
export = {
extends: [baseExtend],
rules: {
// eslint-plugin-yml rules
${rules
.filter(CONFIGS[rec].filter)
.map((rule) => {
return `"${rule.meta.docs.ruleId}": "${CONFIGS[rec].option(rule)}"`;
})
.join(",\n")}
},
}
`;
const filePath = path.resolve(
__dirname,
`../src/configs/${CONFIGS[rec].config}.ts`
);
if (isWin) {
content = content
.replace(/\r?\n/gu, "\n")
.replace(/\r/gu, "\n")
.replace(/\n/gu, "\r\n");
}
// Update file.
fs.writeFileSync(filePath, content);
}