From 9de33f879bfe226873e2d404863cba11f9d1167e Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 16 Jun 2024 06:21:32 +0900 Subject: [PATCH] fix: add support for eslint v9.5 (#58) --- .changeset/honest-paws-rule.md | 5 +++++ src/vite-plugin-eslint4b.ts | 9 ++++++++- tests/fixtures/build-test/src/index.ts | 5 +---- tests/src/vite-plugin-eslint4b.ts | 7 +------ 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .changeset/honest-paws-rule.md diff --git a/.changeset/honest-paws-rule.md b/.changeset/honest-paws-rule.md new file mode 100644 index 0000000..043440c --- /dev/null +++ b/.changeset/honest-paws-rule.md @@ -0,0 +1,5 @@ +--- +"vite-plugin-eslint4b": patch +--- + +fix: add support for eslint v9.5 diff --git a/src/vite-plugin-eslint4b.ts b/src/vite-plugin-eslint4b.ts index 1bd9373..5400d60 100644 --- a/src/vite-plugin-eslint4b.ts +++ b/src/vite-plugin-eslint4b.ts @@ -214,10 +214,17 @@ function buildLinter() { function buildSourceCode() { const eslintPackageJsonPath = requireResolved("eslint/package.json"); - const sourceCodePath = resolveAndNormalizePath( + let sourceCodePath = resolveAndNormalizePath( eslintPackageJsonPath, "../lib/source-code/index.js", ); + if (!fs.existsSync(sourceCodePath)) { + // ESLint v9.5.0 and later + sourceCodePath = resolveAndNormalizePath( + eslintPackageJsonPath, + "../lib/languages/js/source-code/index.js", + ); + } return build(sourceCodePath, ["path", "node:path", "assert", "node:assert"]); } diff --git a/tests/fixtures/build-test/src/index.ts b/tests/fixtures/build-test/src/index.ts index 9790406..b3147a4 100644 --- a/tests/fixtures/build-test/src/index.ts +++ b/tests/fixtures/build-test/src/index.ts @@ -4,14 +4,11 @@ import { name } from "eslint/package.json"; import * as TSESLintUtils from "@typescript-eslint/utils"; import * as TSESLintPlugin from "@typescript-eslint/eslint-plugin"; -const linter = new Linter({ configType: "eslintrc" }); +const linter = new Linter({}); export function lint(): Linter.LintMessage[] { return linter.verify("const a = 1", [ { - languageOptions: { - ecmaVersion: 2020, - }, rules: { semi: "error" }, }, ]); diff --git a/tests/src/vite-plugin-eslint4b.ts b/tests/src/vite-plugin-eslint4b.ts index 7ad75e4..f5b795a 100644 --- a/tests/src/vite-plugin-eslint4b.ts +++ b/tests/src/vite-plugin-eslint4b.ts @@ -6,12 +6,7 @@ import type { Linter } from "eslint"; const dynamicImport = new Function("file", "return import(file)"); describe("Build with Vite", () => { - if ( - !semver.satisfies( - process.version, - "^18.18.0 || ^20.9.0 || >=21.1.018.0.0 || ", - ) - ) { + if (!semver.satisfies(process.version, "^18.18.0 || ^20.9.0 || >=21.1.0")) { return; } let originalCwd: string;