-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate-rules.ts
46 lines (39 loc) · 1.06 KB
/
update-rules.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
import path from "path";
import fs from "fs";
import os from "os";
// import eslint from "eslint"
import { rules } from "./lib/load-rules";
const isWin = os.platform().startsWith("win");
/**
* Convert text to camelCase
*/
function camelCase(str: string) {
return str.replace(/[-/_](\w)/gu, (_, c) => (c ? c.toUpperCase() : ""));
}
let content = `
import type { RuleModule } from "../types"
${rules
.map(
(rule) =>
`import ${camelCase(rule.meta.docs.ruleName)} from "../rules/${
rule.meta.docs.ruleName
}"`,
)
.join("\n")}
export const rules = [
${rules.map((rule) => camelCase(rule.meta.docs.ruleName)).join(",")}
] as RuleModule[]
`;
const filePath = path.resolve(__dirname, "../src/utils/rules.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);
// Format files.
// const linter = new eslint.CLIEngine({ fix: true })
// const report = linter.executeOnFiles([filePath])
// eslint.CLIEngine.outputFixes(report)