From 8a3d04e95c4c3d31c093007dcdc59b039f3577ae Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 29 Jan 2025 14:49:23 +0900 Subject: [PATCH 1/2] Remove unnecessary code --- package.json | 1 - src/common/create-require.ts | 17 -- src/common/eslint-scope.ts | 2 +- src/common/espree.ts | 2 +- test/ast.js | 4 - test/index.js | 293 +++++++++++++++++------------------ test/integrations.js | 4 - 7 files changed, 144 insertions(+), 179 deletions(-) delete mode 100644 src/common/create-require.ts diff --git a/package.json b/package.json index c95fea61..03daf818 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "@eslint/eslintrc": "^3.2.0", "@eslint/js": "^9.19.0", "@types/debug": "^4.1.7", - "@types/eslint": "^9.6.1", "@types/estree": "^1.0.0", "@types/lodash": "^4.14.186", "@types/mocha": "^9.0.0", diff --git a/src/common/create-require.ts b/src/common/create-require.ts deleted file mode 100644 index 6c536680..00000000 --- a/src/common/create-require.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Module from "module" -import path from "path" -export const createRequire: (filename: string) => (modname: string) => any = - // Added in v12.2.0 - (Module as any).createRequire || - // Added in v10.12.0, but deprecated in v12.2.0. - (Module as any).createRequireFromPath || - // Polyfill - This is not executed on the tests on node@>=10. - /* istanbul ignore next */ - ((modname) => { - const mod = new Module(modname) - - mod.filename = modname - mod.paths = (Module as any)._nodeModulePaths(path.dirname(modname)) - ;(mod as any)._compile("module.exports = require;", modname) - return mod.exports - }) diff --git a/src/common/eslint-scope.ts b/src/common/eslint-scope.ts index 524aaa84..a0e96810 100644 --- a/src/common/eslint-scope.ts +++ b/src/common/eslint-scope.ts @@ -1,7 +1,7 @@ import * as escope from "eslint-scope" import { lte } from "semver" -import { createRequire } from "./create-require" import path from "path" +import { createRequire } from "module" type ESLintScope = typeof escope & { version: string diff --git a/src/common/espree.ts b/src/common/espree.ts index bcb3fd7c..f9c1efcc 100644 --- a/src/common/espree.ts +++ b/src/common/espree.ts @@ -2,9 +2,9 @@ import type { ParserOptions } from "../common/parser-options" // @ts-expect-error -- ignore import * as dependencyEspree from "espree" import { lte } from "semver" -import { createRequire } from "./create-require" import path from "path" import type { BasicParserObject } from "./parser-object" +import { createRequire } from "module" type Espree = BasicParserObject & { latestEcmaVersion: number diff --git a/test/ast.js b/test/ast.js index 16fe5e49..c984b824 100644 --- a/test/ast.js +++ b/test/ast.js @@ -300,10 +300,6 @@ describe("Template AST", () => { }) it("should scope in the correct.", () => { - const version = require(`eslint/package.json`).version - if (!semver.satisfies(version, ">=8")) { - return - } const resultPath = path.join(ROOT, `${name}/scope.json`) if (!fs.existsSync(resultPath)) { return diff --git a/test/index.js b/test/index.js index 4a5bf90d..e4d898b3 100644 --- a/test/index.js +++ b/test/index.js @@ -12,7 +12,6 @@ const assert = require("assert") const path = require("path") const fs = require("fs-extra") -const semver = require("semver") const parse = require("../src").parse const parseForESLint = require("../src").parseForESLint const eslint = require("eslint") @@ -302,99 +301,97 @@ describe("Basic tests", async () => { assert.deepStrictEqual(messages, []) }) - if (semver.gte(process.version, "10.0.0")) { - it("should notify no error with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.js"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: "@typescript-eslint/parser", - }, + it("should notify no error with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.js"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: "@typescript-eslint/parser", }, - rules: { semi: ["error", "never"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["typed.js"]) - const messages = report[0].messages - - assert.deepStrictEqual(messages, []) + rules: { semi: ["error", "never"] }, + }, + overrideConfigFile: true, }) + const report = await cli.lintFiles(["typed.js"]) + const messages = report[0].messages - it("should notify no error with multiple parser with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.ts", "*.tsx"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: { - ts: "@typescript-eslint/parser", - }, + assert.deepStrictEqual(messages, []) + }) + + it("should notify no error with multiple parser with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.ts", "*.tsx"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: { + ts: "@typescript-eslint/parser", }, }, - rules: { semi: ["error", "never"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["typed.ts", "typed.tsx"]) - - assert.deepStrictEqual(report[0].messages, []) - assert.deepStrictEqual(report[1].messages, []) + rules: { semi: ["error", "never"] }, + }, + overrideConfigFile: true, }) + const report = await cli.lintFiles(["typed.ts", "typed.tsx"]) - it("should notify no error with parser object with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.js"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: require("@typescript-eslint/parser"), - }, + assert.deepStrictEqual(report[0].messages, []) + assert.deepStrictEqual(report[1].messages, []) + }) + + it("should notify no error with parser object with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.js"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: require("@typescript-eslint/parser"), }, - rules: { semi: ["error", "never"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["typed.js"]) - const messages = report[0].messages - - assert.deepStrictEqual(messages, []) + rules: { semi: ["error", "never"] }, + }, + overrideConfigFile: true, }) + const report = await cli.lintFiles(["typed.js"]) + const messages = report[0].messages - it("should notify no error with multiple parser object with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.ts", "*.tsx"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: { - ts: require("@typescript-eslint/parser"), - }, + assert.deepStrictEqual(messages, []) + }) + + it("should notify no error with multiple parser object with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.ts", "*.tsx"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: { + ts: require("@typescript-eslint/parser"), }, }, - rules: { semi: ["error", "never"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["typed.ts", "typed.tsx"]) - - assert.deepStrictEqual(report[0].messages, []) - assert.deepStrictEqual(report[1].messages, []) + rules: { semi: ["error", "never"] }, + }, + overrideConfigFile: true, }) - } + const report = await cli.lintFiles(["typed.ts", "typed.tsx"]) + + assert.deepStrictEqual(report[0].messages, []) + assert.deepStrictEqual(report[1].messages, []) + }) }) describe("About fixtures/typed.vue", () => { @@ -420,29 +417,27 @@ describe("Basic tests", async () => { assert.deepStrictEqual(messages, []) }) - if (semver.gte(process.version, "10.0.0")) { - it("should notify no error with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.vue"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: "@typescript-eslint/parser", - }, + it("should notify no error with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.vue"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: "@typescript-eslint/parser", }, - rules: { semi: ["error", "never"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["typed.vue"]) - const messages = report[0].messages - - assert.deepStrictEqual(messages, []) + rules: { semi: ["error", "never"] }, + }, + overrideConfigFile: true, }) - } + const report = await cli.lintFiles(["typed.vue"]) + const messages = report[0].messages + + assert.deepStrictEqual(messages, []) + }) it("should fix 'semi' errors with --fix option with '@babel/eslint-parser'", async () => { const cli = new ESLint({ @@ -475,69 +470,65 @@ describe("Basic tests", async () => { assert(actual === expected) }) - if (semver.gte(process.version, "10.0.0")) { - it("should fix 'semi' errors with --fix option with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - fix: true, - overrideConfig: { - files: ["*.vue"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: "@typescript-eslint/parser", - }, + it("should fix 'semi' errors with --fix option with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + fix: true, + overrideConfig: { + files: ["*.vue"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: "@typescript-eslint/parser", }, - rules: { semi: ["error", "always"] }, }, - overrideConfigFile: true, - }) - await ESLint.outputFixes(await cli.lintFiles(["typed.vue"])) - - const actual = fs.readFileSync( - path.join(FIXTURE_DIR, "typed.vue"), - "utf8", - ) - const expected = fs.readFileSync( - path.join(FIXTURE_DIR, "typed.vue.fixed"), - "utf8", - ) - - assert.strictEqual(actual, expected) + rules: { semi: ["error", "always"] }, + }, + overrideConfigFile: true, }) - } + await ESLint.outputFixes(await cli.lintFiles(["typed.vue"])) + + const actual = fs.readFileSync( + path.join(FIXTURE_DIR, "typed.vue"), + "utf8", + ) + const expected = fs.readFileSync( + path.join(FIXTURE_DIR, "typed.vue.fixed"), + "utf8", + ) + + assert.strictEqual(actual, expected) + }) }) - if (semver.gte(process.version, "10.0.0")) { - describe("About fixtures/ts-scope-manager.vue", () => { - it("should calculate the correct location with '@typescript-eslint/parser'", async () => { - const cli = new ESLint({ - cwd: FIXTURE_DIR, - overrideConfig: { - files: ["*.vue"], - languageOptions: { - parser, - globals: {}, - parserOptions: { - parser: "@typescript-eslint/parser", - }, + describe("About fixtures/ts-scope-manager.vue", () => { + it("should calculate the correct location with '@typescript-eslint/parser'", async () => { + const cli = new ESLint({ + cwd: FIXTURE_DIR, + overrideConfig: { + files: ["*.vue"], + languageOptions: { + parser, + globals: {}, + parserOptions: { + parser: "@typescript-eslint/parser", }, - rules: { "no-unused-vars": ["error"] }, }, - overrideConfigFile: true, - }) - const report = await cli.lintFiles(["ts-scope-manager.vue"]) - const messages = report[0].messages - - assert.strictEqual(messages.length, 1) - assert.deepStrictEqual(messages[0].line, 8) - assert.deepStrictEqual(messages[0].column, 8) - assert.deepStrictEqual(messages[0].endLine, 8) - assert.deepStrictEqual(messages[0].endColumn, 14) + rules: { "no-unused-vars": ["error"] }, + }, + overrideConfigFile: true, }) + const report = await cli.lintFiles(["ts-scope-manager.vue"]) + const messages = report[0].messages + + assert.strictEqual(messages.length, 1) + assert.deepStrictEqual(messages[0].line, 8) + assert.deepStrictEqual(messages[0].column, 8) + assert.deepStrictEqual(messages[0].endLine, 8) + assert.deepStrictEqual(messages[0].endColumn, 14) }) - } + }) describe("About fixtures/svg-attrs.vue", () => { it("parses attributes with colons", async () => { diff --git a/test/integrations.js b/test/integrations.js index 69a3004a..88e9c501 100644 --- a/test/integrations.js +++ b/test/integrations.js @@ -6,7 +6,6 @@ const assert = require("assert") const path = require("path") const fs = require("fs-extra") const cp = require("child_process") -const semver = require("semver") const eslintCompat = require("./lib/eslint-compat") //------------------------------------------------------------------------------ @@ -20,9 +19,6 @@ const FIXTURE_DIR = path.join(__dirname, "fixtures/integrations") //------------------------------------------------------------------------------ describe("Integration tests", () => { - if (!semver.gte(process.version, "14.0.0")) { - return - } for (const target of fs.readdirSync(FIXTURE_DIR)) { it(target, async () => { let ESLint = eslintCompat(require("eslint")).ESLint From acd48d94b9c2cae2140ad468f14366a8e8c7a49a Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 29 Jan 2025 14:52:54 +0900 Subject: [PATCH 2/2] fix ci --- .github/workflows/CI.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2e31fdae..cdd408e3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,10 +40,6 @@ jobs: - eslint: 9 node: 'lts/*' os: macos-latest - # On old ESLint versions - - eslint: 8 - node: 'lts/*' - os: ubuntu-latest runs-on: ${{ matrix.os }} steps: @@ -63,6 +59,30 @@ jobs: run: npm run -s build - name: Test run: npm run -s test:mocha + test-for-old-eslint: + name: Test + strategy: + matrix: + eslint: [8] + node: ['lts/*'] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Checkout submodules + run: git submodule update --init + - name: Install Node.js v${{ matrix.node }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - name: Install Packages + run: npm install -f + - name: Install ESLint v${{ matrix.eslint }} + run: node scripts/ci-install-eslint ${{ matrix.eslint }} + - name: Test + run: npm run -s test:debug test-cov: name: Test and Send Coverage