From 9fb6992c2a3dd0f7065fd623f5da28b8c5963023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 30 Aug 2021 03:06:15 +0200 Subject: [PATCH] feat: support ESLint 8.x --- .github/workflows/node-4+.yml | 25 +++++++++++++++++++++- package.json | 16 +++++++------- tests/helpers/getESLintCoreRule.js | 11 ++++++++++ tests/lib/rules/jsx-no-undef.js | 4 ++-- tests/lib/rules/jsx-no-useless-fragment.js | 4 +--- tests/lib/rules/jsx-uses-react.js | 4 ++-- tests/lib/rules/jsx-uses-vars.js | 6 +++--- 7 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 tests/helpers/getESLintCoreRule.js diff --git a/.github/workflows/node-4+.yml b/.github/workflows/node-4+.yml index 732f2273c6..f3ce28c3bc 100644 --- a/.github/workflows/node-4+.yml +++ b/.github/workflows/node-4+.yml @@ -26,6 +26,7 @@ jobs: matrix: node-version: ${{ fromJson(needs.matrix.outputs.latest) }} eslint: + - '^8.0.0-0' - 7 - 6 - 5 @@ -43,24 +44,46 @@ jobs: babel-eslint: 10 - node-version: 4 babel-eslint: 9 + - node-version: 15 + eslint: '^8.0.0-0' + - node-version: 13 + eslint: '^8.0.0-0' + - node-version: 11 + eslint: '^8.0.0-0' + - node-version: 11 + eslint: 7 + - node-version: 10 + eslint: '^8.0.0-0' + - node-version: 9 + eslint: '^8.0.0-0' - node-version: 9 eslint: 7 + - node-version: 8 + eslint: '^8.0.0-0' - node-version: 8 eslint: 7 + - node-version: 7 + eslint: '^8.0.0-0' - node-version: 7 eslint: 7 - node-version: 7 eslint: 6 + - node-version: 6 + eslint: '^8.0.0-0' - node-version: 6 eslint: 7 - node-version: 6 eslint: 6 + - node-version: 5 + eslint: '^8.0.0-0' - node-version: 5 eslint: 7 - node-version: 5 eslint: 6 - node-version: 5 eslint: 5 + - node-version: 4 + eslint: '^8.0.0-0' - node-version: 4 eslint: 7 - node-version: 4 @@ -74,7 +97,7 @@ jobs: name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} - after_install: npm install --no-save "eslint@${{ matrix.eslint }}" "@typescript-eslint/parser@${{ matrix.node-version >= 10 && '4.0' || (matrix.node-version >= 8 && '3' || '2') }}" "babel-eslint@${{ matrix.babel-eslint }}" + after_install: npm install --no-save "eslint@${{ matrix.eslint }}" "@typescript-eslint/parser@${{ matrix.node-version >= 10 && '^5.0.0-0' || (matrix.node-version >= 8 && '3' || '2') }}" "babel-eslint@${{ matrix.babel-eslint }}" skip-ls-check: true env: NPM_CONFIG_LEGACY_PEER_DEPS: true diff --git a/package.json b/package.json index 3f9d0e35bf..b76a45470e 100644 --- a/package.json +++ b/package.json @@ -43,18 +43,18 @@ "string.prototype.matchall": "^4.0.5" }, "devDependencies": { - "@types/eslint": "=7.2.10", - "@types/estree": "^0.0.47", - "@types/node": "^14.14.37", - "@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ~4.0", + "@types/eslint": "^7.28.0", + "@types/estree": "^0.0.50", + "@types/node": "^14.17.12", + "@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0 || ^5.0.0-0", "aud": "^1.1.5", "babel-eslint": "^8 || ^9 || ^10.1.0", - "eslint": "^3 || ^4 || ^5 || ^6 || ^7", + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8.0.0-0", "eslint-config-airbnb-base": "^14.2.1", - "eslint-plugin-eslint-plugin": "^2.3.0 || ^3.3.1", + "eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3", "eslint-plugin-import": "^2.24.2", "eslint-remote-tester": "^1.3.0", - "eslint-remote-tester-repositories": "^0.0.2", + "eslint-remote-tester-repositories": "^0.0.3", "espree": "^3.5.4", "istanbul": "^0.4.5", "markdown-magic": "^2.5.2", @@ -65,7 +65,7 @@ "typescript-eslint-parser": "^20.1.1" }, "peerDependencies": { - "eslint": "^3 || ^4 || ^5 || ^6 || ^7" + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8.0.0-0" }, "engines": { "node": ">=4" diff --git a/tests/helpers/getESLintCoreRule.js b/tests/helpers/getESLintCoreRule.js new file mode 100644 index 0000000000..bbed38bccb --- /dev/null +++ b/tests/helpers/getESLintCoreRule.js @@ -0,0 +1,11 @@ +'use strict'; + +const version = require('eslint/package.json').version; +const semver = require('semver'); + +const isESLintV8 = semver.major(version) >= 8; + +// eslint-disable-next-line global-require, import/no-dynamic-require, import/no-unresolved +const getESLintCoreRule = (ruleId) => (isESLintV8 ? require('eslint/use-at-your-own-risk').builtinRules.get(ruleId) : require(`eslint/lib/rules/${ruleId}`)); + +module.exports = getESLintCoreRule; diff --git a/tests/lib/rules/jsx-no-undef.js b/tests/lib/rules/jsx-no-undef.js index 40f498befd..cb946e1da0 100644 --- a/tests/lib/rules/jsx-no-undef.js +++ b/tests/lib/rules/jsx-no-undef.js @@ -28,8 +28,8 @@ const parserOptions = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({parserOptions}); -const linter = ruleTester.linter || eslint.linter; -linter.defineRule('no-undef', require('eslint/lib/rules/no-undef')); +const linter = ruleTester.linter || eslint.linter || eslint.Linter; +linter.defineRule('no-undef', require('../../helpers/getESLintCoreRule')('no-undef')); ruleTester.run('jsx-no-undef', rule, { valid: [{ diff --git a/tests/lib/rules/jsx-no-useless-fragment.js b/tests/lib/rules/jsx-no-useless-fragment.js index 9dd3487ef5..7a3aa0e4c1 100644 --- a/tests/lib/rules/jsx-no-useless-fragment.js +++ b/tests/lib/rules/jsx-no-useless-fragment.js @@ -8,12 +8,10 @@ // Requirements // ----------------------------------------------------------------------------- -const eslint = require('eslint'); +const RuleTester = require('eslint').RuleTester; const rule = require('../../../lib/rules/jsx-no-useless-fragment'); const parsers = require('../../helpers/parsers'); -const RuleTester = eslint.RuleTester; - const parserOptions = { ecmaVersion: 2018, ecmaFeatures: { diff --git a/tests/lib/rules/jsx-uses-react.js b/tests/lib/rules/jsx-uses-react.js index 6fd6d59d1f..0bde2276f1 100644 --- a/tests/lib/rules/jsx-uses-react.js +++ b/tests/lib/rules/jsx-uses-react.js @@ -10,7 +10,7 @@ // ----------------------------------------------------------------------------- const eslint = require('eslint'); -const rule = require('eslint/lib/rules/no-unused-vars'); +const rule = require('../../helpers/getESLintCoreRule')('no-unused-vars'); const RuleTester = eslint.RuleTester; @@ -35,7 +35,7 @@ const settings = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({parserOptions}); -const linter = ruleTester.linter || eslint.linter; +const linter = ruleTester.linter || eslint.linter || eslint.Linter; linter.defineRule('jsx-uses-react', require('../../../lib/rules/jsx-uses-react')); ruleTester.run('no-unused-vars', rule, { diff --git a/tests/lib/rules/jsx-uses-vars.js b/tests/lib/rules/jsx-uses-vars.js index ce02d7fc29..7bf665bc0b 100644 --- a/tests/lib/rules/jsx-uses-vars.js +++ b/tests/lib/rules/jsx-uses-vars.js @@ -10,8 +10,8 @@ // ----------------------------------------------------------------------------- const eslint = require('eslint'); -const ruleNoUnusedVars = require('eslint/lib/rules/no-unused-vars'); -const rulePreferConst = require('eslint/lib/rules/prefer-const'); +const ruleNoUnusedVars = require('../../helpers/getESLintCoreRule')('no-unused-vars'); +const rulePreferConst = require('../../helpers/getESLintCoreRule')('prefer-const'); const RuleTester = eslint.RuleTester; @@ -30,7 +30,7 @@ const parserOptions = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({parserOptions}); -const linter = ruleTester.linter || eslint.linter; +const linter = ruleTester.linter || eslint.linter || eslint.Linter; linter.defineRule('jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars')); ruleTester.run('no-unused-vars', ruleNoUnusedVars, {