Skip to content

Commit 9225766

Browse files
refactor(scripts): use ESLint class instead of CLIEngine class internally (#36)
1 parent 6a7a1f1 commit 9225766

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

scripts/generate-browser-globals.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const fs = require("fs")
88
const path = require("path")
9-
const { CLIEngine } = require("eslint")
9+
const { ESLint } = require("eslint")
1010
const { browser: originalGlobals } = require("globals")
1111

1212
const targetFile = path.resolve(__dirname, "../lib/configs/_browser-globals.js")
@@ -33,16 +33,14 @@ for (const key of Object.keys(originalGlobals).sort()) {
3333
}
3434
}
3535

36-
const linter = new CLIEngine({ fix: true })
36+
const linter = new ESLint({ fix: true })
3737
const rawCode = `/**
3838
* DON'T EDIT THIS FILE WHICH WAS GENERATED BY './scripts/generate-browser-globals.js'.
3939
*/
4040
"use strict"
4141
4242
module.exports = ${JSON.stringify(globals, null, 4)}
4343
`
44-
const code =
45-
linter.executeOnText(rawCode, "_browser-globals.js").results[0].output ||
46-
rawCode
47-
48-
fs.writeFileSync(targetFile, code)
44+
linter
45+
.lintText(rawCode, { filePath: targetFile })
46+
.then(([{ output }]) => fs.writeFileSync(targetFile, output || rawCode))

scripts/generate-configs.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const fs = require("fs")
88
const path = require("path")
9-
const { CLIEngine } = require("eslint")
9+
const { ESLint } = require("eslint")
1010

1111
const targetFile = path.resolve(__dirname, "../lib/configs.js")
1212

@@ -28,6 +28,5 @@ ${fs
2828
`
2929
)
3030

31-
const linter = new CLIEngine({ fix: true })
32-
const result = linter.executeOnFiles([targetFile])
33-
CLIEngine.outputFixes(result)
31+
const linter = new ESLint({ fix: true })
32+
linter.lintFiles([targetFile]).then(([result]) => ESLint.outputFixes(result))

scripts/generate-rules.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const fs = require("fs")
88
const path = require("path")
9-
const { CLIEngine } = require("eslint")
9+
const { ESLint } = require("eslint")
1010

1111
const targetFile = path.resolve(__dirname, "../lib/rules.js")
1212

@@ -34,6 +34,5 @@ ${fs
3434
`
3535
)
3636

37-
const linter = new CLIEngine({ fix: true })
38-
const result = linter.executeOnFiles([targetFile])
39-
CLIEngine.outputFixes(result)
37+
const linter = new ESLint({ fix: true })
38+
linter.lintFiles([targetFile]).then(([result]) => ESLint.outputFixes(result))

0 commit comments

Comments
 (0)