Skip to content

Commit

Permalink
feat: support @typescript-eslint/utils v7 & v8 (#241)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
G-Rath authored Jan 17, 2025
1 parent b93b441 commit 414dc8f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
21 changes: 20 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
'use strict';

const {
version: typescriptESLintPluginVersion,
} = require('@typescript-eslint/eslint-plugin/package.json');
const semver = require('semver');

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: [
Expand Down Expand Up @@ -27,7 +46,7 @@ module.exports = {
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/ban-types': 'error',
...typescriptBanTypesRules(),
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,30 @@ jobs:
test-node:
name:
# prettier-ignore
Test on Node.js v${{ matrix.node-version }}, eslint v${{ matrix.eslint-version }}
Test on Node.js v${{ matrix.node-version }}, eslint v${{ matrix.eslint-version }}, and ts-eslint v${{ matrix.ts-eslint-plugin-version }}
needs: prepare-yarn-cache-ubuntu
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 19.x, 20.x, 21.x]
eslint-version: [7, 8, 9]
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:
Expand All @@ -93,7 +106,9 @@ jobs:
install with eslint v${{ matrix.eslint-version }}
run: |
yarn
yarn add --dev eslint@${{ matrix.eslint-version }}
yarn add @typescript-eslint/utils@${{ matrix.ts-eslint-plugin-version }}
# prettier-ignore
yarn add --dev eslint@${{ matrix.eslint-version }} @typescript-eslint/eslint-plugin@${{ matrix.ts-eslint-plugin-version }} @typescript-eslint/parser@${{ matrix.ts-eslint-plugin-version }}
- name: run tests
# only collect coverage on eslint versions that support dynamic import
run: yarn test --coverage ${{ matrix.eslint-version == 8 }}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
]
},
"dependencies": {
"@typescript-eslint/utils": "^6.0.0"
"@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
Expand All @@ -87,8 +87,10 @@
"@types/dedent": "^0.7.0",
"@types/jest": "^29.0.0",
"@types/node": "^14.17.0",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/utils": "^6.0.0",
"babel-jest": "^29.0.0",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"dedent": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester {

public override run<
TMessageIds extends string,
TOptions extends Readonly<unknown[]>,
TOptions extends readonly unknown[],
>(
ruleName: string,
rule: TSESLint.RuleModule<TMessageIds, TOptions>,
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,7 @@ __metadata:
languageName: node
linkType: hard

"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.0, @types/semver@npm:^7.5.5":
"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.0, @types/semver@npm:^7.5.5, @types/semver@npm:^7.5.8":
version: 7.5.8
resolution: "@types/semver@npm:7.5.8"
checksum: ea6f5276f5b84c55921785a3a27a3cd37afee0111dfe2bcb3e03c31819c197c782598f17f0b150a69d453c9584cd14c4c4d7b9a55d2c5e6cacd4d66fdb3b3663
Expand Down Expand Up @@ -5128,6 +5128,7 @@ __metadata:
"@types/dedent": ^0.7.0
"@types/jest": ^29.0.0
"@types/node": ^14.17.0
"@types/semver": ^7.5.8
"@typescript-eslint/eslint-plugin": ^6.0.0
"@typescript-eslint/parser": ^6.0.0
"@typescript-eslint/utils": ^6.0.0
Expand Down

0 comments on commit 414dc8f

Please sign in to comment.