-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathupdate-rules.ts
52 lines (44 loc) · 1.21 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
47
48
49
50
51
52
import path from "path"
import fs from "fs"
// import eslint from "eslint"
import { rules } from "./lib/load-rules"
/**
* Convert text to camelCase
*/
function camelCase(str: string) {
return str.replace(/[-_](\w)/gu, (_, c) => (c ? c.toUpperCase() : ""))
}
/**
* Convert text to identifier
*/
function toIdentifier(str: string) {
const clean = str
.replace(/^[^\p{ID_Start}$_]/u, "")
.replace(/[^\p{ID_Continue}$\u200c\u200d]/gu, "-")
return camelCase(clean)
}
const content = `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "yarn update"
*/
import type { RuleModule } from "../types"
${rules
.map(
(rule) =>
`import ${toIdentifier(rule.meta.docs.ruleName)} from "../rules/${
rule.meta.docs.ruleName
}"`,
)
.join("\n")}
export const rules = [
${rules.map((rule) => toIdentifier(rule.meta.docs.ruleName)).join(",")}
] as RuleModule[]
`
const filePath = path.resolve(__dirname, "../src/utils/rules.ts")
// Update file.
fs.writeFileSync(filePath, content)
// Format files.
// const linter = new eslint.CLIEngine({ fix: true })
// const report = linter.executeOnFiles([filePath])
// eslint.CLIEngine.outputFixes(report)