Skip to content

Commit

Permalink
refactor(scripts): use ESLint class instead of CLIEngine class in…
Browse files Browse the repository at this point in the history
…ternally (#36)
  • Loading branch information
MichaelDeBoey committed Oct 18, 2022
1 parent 6a7a1f1 commit 9225766
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
12 changes: 5 additions & 7 deletions scripts/generate-browser-globals.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")
const { browser: originalGlobals } = require("globals")

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

const linter = new CLIEngine({ fix: true })
const linter = new ESLint({ fix: true })
const rawCode = `/**
* DON'T EDIT THIS FILE WHICH WAS GENERATED BY './scripts/generate-browser-globals.js'.
*/
"use strict"
module.exports = ${JSON.stringify(globals, null, 4)}
`
const code =
linter.executeOnText(rawCode, "_browser-globals.js").results[0].output ||
rawCode

fs.writeFileSync(targetFile, code)
linter
.lintText(rawCode, { filePath: targetFile })
.then(([{ output }]) => fs.writeFileSync(targetFile, output || rawCode))
7 changes: 3 additions & 4 deletions scripts/generate-configs.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")

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

Expand All @@ -28,6 +28,5 @@ ${fs
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)
const linter = new ESLint({ fix: true })
linter.lintFiles([targetFile]).then(([result]) => ESLint.outputFixes(result))
7 changes: 3 additions & 4 deletions scripts/generate-rules.js
Expand Up @@ -6,7 +6,7 @@

const fs = require("fs")
const path = require("path")
const { CLIEngine } = require("eslint")
const { ESLint } = require("eslint")

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

Expand Down Expand Up @@ -34,6 +34,5 @@ ${fs
`
)

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

0 comments on commit 9225766

Please sign in to comment.