Skip to content

Commit d224ebe

Browse files
authored
Replace test using CLIEngine class with ESLint class. (#299)
* Replace test using CLIEngine class with ESLint class. This change is a preparation for ESLint v8 support. * fix
1 parent a69ca2e commit d224ebe

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/lib/eslint-plugin.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "path"
22
import assert from "assert"
3-
import { CLIEngine } from "eslint"
3+
import { ESLint } from "eslint"
44
import plugin from "../../lib/index"
55

66
// -----------------------------------------------------------------------------
@@ -10,16 +10,26 @@ import plugin from "../../lib/index"
1010
const TEST_CWD = path.join(__dirname, "../fixtures/integrations/eslint-plugin")
1111

1212
describe("Integration with eslint-plugin-regexp", () => {
13-
it("should lint without errors", () => {
14-
const engine = new CLIEngine({
15-
cwd: TEST_CWD,
16-
})
17-
engine.addPlugin("eslint-plugin-regexp", plugin)
18-
const r = engine.executeOnFiles(["test.js"])
13+
it("should lint without errors", async () => {
14+
let results: ESLint.LintResult[]
15+
if (ESLint) {
16+
const eslint = new ESLint({
17+
cwd: TEST_CWD,
18+
plugins: { "eslint-plugin-regexp": plugin },
19+
})
20+
results = await eslint.lintFiles(["test.js"])
21+
} else {
22+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore
23+
const engine = new (require("eslint").CLIEngine)({
24+
cwd: TEST_CWD,
25+
})
26+
engine.addPlugin("eslint-plugin-regexp", plugin)
27+
results = engine.executeOnFiles(["test.js"]).results
28+
}
1929

20-
assert.strictEqual(r.results.length, 1)
30+
assert.strictEqual(results.length, 1)
2131
assert.deepStrictEqual(
22-
r.results[0].messages.map((m) => m.ruleId),
32+
results[0].messages.map((m) => m.ruleId),
2333
[
2434
"regexp/no-dupe-characters-character-class",
2535
"regexp/prefer-w",

0 commit comments

Comments
 (0)