From 999bb8f2c1a8d4fc74db11eb47641e6d310d5324 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 2 Aug 2024 08:11:57 +1200 Subject: [PATCH 1/4] feat: allow `@typescript-eslint` v8 --- package.json | 4 ++-- yarn.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index db75155b0..b6e329054 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ ] }, "dependencies": { - "@typescript-eslint/utils": "^6.0.0 || ^7.0.0" + "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "devDependencies": { "@babel/cli": "^7.4.4", @@ -106,7 +106,7 @@ "typescript": "^5.0.4" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0", + "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0 || ^8.0.0", "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", "jest": "*" }, diff --git a/yarn.lock b/yarn.lock index 45366ef09..e08a36280 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5199,7 +5199,7 @@ __metadata: ts-node: ^10.2.1 typescript: ^5.0.4 peerDependencies: - "@typescript-eslint/eslint-plugin": ^6.0.0 || ^7.0.0 + "@typescript-eslint/eslint-plugin": ^6.0.0 || ^7.0.0 || ^8.0.0 eslint: ^7.0.0 || ^8.0.0 || ^9.0.0 jest: "*" peerDependenciesMeta: From 69905c8f91ca4193c9faa8a5df9913e4928d2419 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 3 Aug 2024 09:08:09 +1200 Subject: [PATCH 2/4] ci: test against `@typescript-eslint/utils` v8 --- .github/workflows/nodejs.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 9eeace458..3067ba6ea 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -73,17 +73,23 @@ jobs: matrix: node-version: [16.x, 18.x, 20.x, 21.x, 22.x] eslint-version: [7, 8, 9] - ts-eslint-plugin-version: [6, 7] + ts-eslint-plugin-version: [6, 7, 8] exclude: # ts-eslint/plugin@7 doesn't support node@16 - node-version: 16.x ts-eslint-plugin-version: 7 + # ts-eslint/plugin@8 doesn't support node@16 + - node-version: 16.x + ts-eslint-plugin-version: 8 # eslint@9 doesn't support node@16 - node-version: 16.x eslint-version: 9 # ts-eslint/plugin@7 doesn't support eslint@7 - eslint-version: 7 ts-eslint-plugin-version: 7 + # ts-eslint/plugin@8 doesn't support eslint@7 + - eslint-version: 7 + ts-eslint-plugin-version: 8 runs-on: ubuntu-latest steps: From 56a732389ead4d32bc696224785f72dc962f062b Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 3 Aug 2024 09:14:15 +1200 Subject: [PATCH 3/4] chore: handle different rule names depending on `@typescript-eslint/eslint-plugin` version --- .eslintrc.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 70f54bac1..5d6e5f4b9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,25 @@ 'use strict'; +const { + version: typescriptESLintPluginVersion, +} = require('@typescript-eslint/eslint-plugin/package.json'); +const semver = require('semver'); const globals = require('./src/globals.json'); +const typescriptBanTypesRules = () => { + if (semver.major(typescriptESLintPluginVersion) === 8) { + return { + '@typescript-eslint/no-empty-object-type': 'error', + '@typescript-eslint/no-unsafe-function-type': 'error', + '@typescript-eslint/no-wrapper-object-types': 'error', + }; + } + + return { + '@typescript-eslint/ban-types': 'error', + }; +}; + module.exports = { parser: require.resolve('@typescript-eslint/parser'), extends: [ @@ -30,7 +48,7 @@ module.exports = { '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], '@typescript-eslint/no-require-imports': 'error', '@typescript-eslint/ban-ts-comment': 'error', - '@typescript-eslint/ban-types': 'error', + ...typescriptBanTypesRules(), '@typescript-eslint/consistent-type-imports': [ 'error', { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, From bca6dbd8a478d4e062d56b2e026529f6253e33fd Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 3 Aug 2024 09:27:12 +1200 Subject: [PATCH 4/4] test: only run `unbound-method` cases when using `@typescript-eslint` v7 --- jest.config.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 8403937e6..bc0faa898 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -42,17 +42,17 @@ if (semver.major(eslintVersion) !== 8) { config.projects = config.projects.filter( ({ displayName }) => displayName !== 'lint', ); +} - // jest/unbound-method doesn't work when using @typescript-eslint v6 - if (semver.major(typescriptESLintPluginVersion) === 6) { - for (const project of config.projects) { - project.testPathIgnorePatterns.push( - '/src/rules/__tests__/unbound-method.test.ts', - ); - project.coveragePathIgnorePatterns.push( - '/src/rules/unbound-method.ts', - ); - } +// jest/unbound-method seems to only be happy with @typescript-eslint v7 right now... +if (semver.major(typescriptESLintPluginVersion) !== 7) { + for (const project of config.projects) { + project.testPathIgnorePatterns.push( + '/src/rules/__tests__/unbound-method.test.ts', + ); + project.coveragePathIgnorePatterns.push( + '/src/rules/unbound-method.ts', + ); } }