From 241988828e30c2a32cc58982548dfce1cc56b87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 2 Jan 2024 10:37:27 +0800 Subject: [PATCH] fix: eslint 7.0 support (#156) --- .github/workflows/CI.yml | 11 +++++------ lib/configs/recommended-module.js | 3 +-- lib/configs/recommended-script.js | 3 +-- lib/util/is-typescript.js | 5 ++++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5c87676e..36c7d0ff 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -31,10 +31,9 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - eslint: [8.x, 7.x] + eslint: [8.x] node: [18.x, 20.x] include: - # run on node lts(ubuntu-latest) - os: ubuntu-latest node: "16.0.x" eslint: "8.x" @@ -44,6 +43,9 @@ jobs: - os: ubuntu-latest node: "19.x" eslint: "8.x" + - os: ubuntu-latest + node: "20.x" + eslint: "7.0.x" runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -57,10 +59,7 @@ jobs: - name: Install Packages run: npm install - name: Install ESLint ${{ matrix.eslint }} - # We need to execute this command twice because of npm's bug. - # See also: https://npm.community/t/error-node-modules-staging-eslint-e7cf6846-node-modules-eslint run: | - npm install --no-save eslint@${{ matrix.eslint }} - npm install --no-save eslint@${{ matrix.eslint }} + npm install --no-save --force eslint@${{ matrix.eslint }} - name: Test run: npm run -s test:ci diff --git a/lib/configs/recommended-module.js b/lib/configs/recommended-module.js index 38a246dd..0584fa63 100644 --- a/lib/configs/recommended-module.js +++ b/lib/configs/recommended-module.js @@ -7,9 +7,9 @@ const { commonRules } = require("./_commons") module.exports.eslintrc = { env: { node: true, - es2021: true, }, globals: { + ...globals.es2021, __dirname: "off", __filename: "off", exports: "off", @@ -36,7 +36,6 @@ module.exports.flat = { sourceType: "module", globals: { ...globals.node, - ...globals.es2021, ...module.exports.eslintrc.globals, }, }, diff --git a/lib/configs/recommended-script.js b/lib/configs/recommended-script.js index 1ac3fd82..0d8f1aa5 100644 --- a/lib/configs/recommended-script.js +++ b/lib/configs/recommended-script.js @@ -7,9 +7,9 @@ const { commonRules } = require("./_commons") module.exports.eslintrc = { env: { node: true, - es2021: true, }, globals: { + ...globals.es2021, __dirname: "readonly", __filename: "readonly", exports: "writable", @@ -33,7 +33,6 @@ module.exports.flat = { sourceType: "commonjs", globals: { ...globals.node, - ...globals.es2021, ...module.exports.eslintrc.globals, }, }, diff --git a/lib/util/is-typescript.js b/lib/util/is-typescript.js index 19d23347..fb468d21 100644 --- a/lib/util/is-typescript.js +++ b/lib/util/is-typescript.js @@ -12,7 +12,10 @@ const typescriptExtensions = [".ts", ".tsx", ".cts", ".mts"] */ module.exports = function isTypescript(context) { const sourceFileExt = path.extname( - context.physicalFilename ?? context.getPhysicalFilename() + context.physicalFilename ?? + context.getPhysicalFilename?.() ?? + context.filename ?? + context.getFilename?.() ) return typescriptExtensions.includes(sourceFileExt) }