forked from sveltejs/eslint-plugin-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-rules.ts
37 lines (31 loc) · 888 Bytes
/
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
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() : ""))
}
const 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")
// Update file.
fs.writeFileSync(filePath, content)
// Format files.
// const linter = new eslint.CLIEngine({ fix: true })
// const report = linter.executeOnFiles([filePath])
// eslint.CLIEngine.outputFixes(report)