Skip to content

refactor(scripts): use ESLint class instead of CLIEngine class internally #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions scripts/generate-browser-globals.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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))