Skip to content

Commit 414dc8f

Browse files
authored
feat: support @typescript-eslint/utils v7 & v8 (#241)
* feat: support `@typescript-eslint/utils` v7 * refactor: adjust array type * chore: specific single major version of `@typescript-eslint/utils` for local * ci: adjust test matrix * feat: allow `@typescript-eslint/utils` v8
1 parent b93b441 commit 414dc8f

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

.eslintrc.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
'use strict';
22

3+
const {
4+
version: typescriptESLintPluginVersion,
5+
} = require('@typescript-eslint/eslint-plugin/package.json');
6+
const semver = require('semver');
7+
8+
const typescriptBanTypesRules = () => {
9+
if (semver.major(typescriptESLintPluginVersion) === 8) {
10+
return {
11+
'@typescript-eslint/no-empty-object-type': 'error',
12+
'@typescript-eslint/no-unsafe-function-type': 'error',
13+
'@typescript-eslint/no-wrapper-object-types': 'error',
14+
};
15+
}
16+
17+
return {
18+
'@typescript-eslint/ban-types': 'error',
19+
};
20+
};
21+
322
module.exports = {
423
parser: require.resolve('@typescript-eslint/parser'),
524
extends: [
@@ -27,7 +46,7 @@ module.exports = {
2746
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
2847
'@typescript-eslint/no-require-imports': 'error',
2948
'@typescript-eslint/ban-ts-comment': 'warn',
30-
'@typescript-eslint/ban-types': 'error',
49+
...typescriptBanTypesRules(),
3150
'@typescript-eslint/consistent-type-imports': [
3251
'error',
3352
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },

.github/workflows/nodejs.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,30 @@ jobs:
6666
test-node:
6767
name:
6868
# prettier-ignore
69-
Test on Node.js v${{ matrix.node-version }}, eslint v${{ matrix.eslint-version }}
69+
Test on Node.js v${{ matrix.node-version }}, eslint v${{ matrix.eslint-version }}, and ts-eslint v${{ matrix.ts-eslint-plugin-version }}
7070
needs: prepare-yarn-cache-ubuntu
7171
strategy:
7272
fail-fast: false
7373
matrix:
7474
node-version: [16.x, 18.x, 19.x, 20.x, 21.x]
7575
eslint-version: [7, 8, 9]
76+
ts-eslint-plugin-version: [6, 7, 8]
7677
exclude:
78+
# ts-eslint/plugin@7 doesn't support node@16
79+
- node-version: 16.x
80+
ts-eslint-plugin-version: 7
81+
# ts-eslint/plugin@8 doesn't support node@16
82+
- node-version: 16.x
83+
ts-eslint-plugin-version: 8
7784
# eslint@9 doesn't support node@16
7885
- node-version: 16.x
7986
eslint-version: 9
87+
# ts-eslint/plugin@7 doesn't support eslint@7
88+
- eslint-version: 7
89+
ts-eslint-plugin-version: 7
90+
# ts-eslint/plugin@8 doesn't support eslint@7
91+
- eslint-version: 7
92+
ts-eslint-plugin-version: 8
8093
runs-on: ubuntu-latest
8194

8295
steps:
@@ -93,7 +106,9 @@ jobs:
93106
install with eslint v${{ matrix.eslint-version }}
94107
run: |
95108
yarn
96-
yarn add --dev eslint@${{ matrix.eslint-version }}
109+
yarn add @typescript-eslint/utils@${{ matrix.ts-eslint-plugin-version }}
110+
# prettier-ignore
111+
yarn add --dev eslint@${{ matrix.eslint-version }} @typescript-eslint/eslint-plugin@${{ matrix.ts-eslint-plugin-version }} @typescript-eslint/parser@${{ matrix.ts-eslint-plugin-version }}
97112
- name: run tests
98113
# only collect coverage on eslint versions that support dynamic import
99114
run: yarn test --coverage ${{ matrix.eslint-version == 8 }}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
]
7171
},
7272
"dependencies": {
73-
"@typescript-eslint/utils": "^6.0.0"
73+
"@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0"
7474
},
7575
"devDependencies": {
7676
"@babel/cli": "^7.4.4",
@@ -87,8 +87,10 @@
8787
"@types/dedent": "^0.7.0",
8888
"@types/jest": "^29.0.0",
8989
"@types/node": "^14.17.0",
90+
"@types/semver": "^7.5.8",
9091
"@typescript-eslint/eslint-plugin": "^6.0.0",
9192
"@typescript-eslint/parser": "^6.0.0",
93+
"@typescript-eslint/utils": "^6.0.0",
9294
"babel-jest": "^29.0.0",
9395
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
9496
"dedent": "^1.0.0",

src/rules/__tests__/test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester {
1717

1818
public override run<
1919
TMessageIds extends string,
20-
TOptions extends Readonly<unknown[]>,
20+
TOptions extends readonly unknown[],
2121
>(
2222
ruleName: string,
2323
rule: TSESLint.RuleModule<TMessageIds, TOptions>,

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ __metadata:
28332833
languageName: node
28342834
linkType: hard
28352835

2836-
"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.0, @types/semver@npm:^7.5.5":
2836+
"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.0, @types/semver@npm:^7.5.5, @types/semver@npm:^7.5.8":
28372837
version: 7.5.8
28382838
resolution: "@types/semver@npm:7.5.8"
28392839
checksum: ea6f5276f5b84c55921785a3a27a3cd37afee0111dfe2bcb3e03c31819c197c782598f17f0b150a69d453c9584cd14c4c4d7b9a55d2c5e6cacd4d66fdb3b3663
@@ -5128,6 +5128,7 @@ __metadata:
51285128
"@types/dedent": ^0.7.0
51295129
"@types/jest": ^29.0.0
51305130
"@types/node": ^14.17.0
5131+
"@types/semver": ^7.5.8
51315132
"@typescript-eslint/eslint-plugin": ^6.0.0
51325133
"@typescript-eslint/parser": ^6.0.0
51335134
"@typescript-eslint/utils": ^6.0.0

0 commit comments

Comments
 (0)