Skip to content

Commit 49418a0

Browse files
authored
feat!: upgrade @typescript-eslint/utils to v7 (#66)
* feat!: drop eslint <8.56 support * feat!: remove eslint-compat-utils, remove compatibility codes
1 parent db5641f commit 49418a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1261
-1378
lines changed

.changeset/blue-pianos-drum.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": minor
3+
---
4+
5+
chore(dep)!: drop eslint <8.56 support

.changeset/chilled-roses-smile.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": minor
3+
---
4+
5+
feat!: upgrade @typescript-eslint/utils to v7

.eslintrc.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const eslintPkg = require('eslint/package.json')
2-
const semver = require('semver')
3-
41
/**
52
* @type {import('eslint').Linter.Config}
63
*/
@@ -12,11 +9,9 @@ module.exports = {
129
'plugin:eslint-plugin/recommended',
1310
'plugin:import-x/recommended',
1411
'plugin:n/recommended',
15-
semver.satisfies(eslintPkg.version, '>=8')
16-
? 'plugin:unicorn/recommended'
17-
: undefined,
12+
'plugin:unicorn/recommended',
1813
'plugin:prettier/recommended',
19-
].filter(Boolean),
14+
],
2015
env: {
2116
node: true,
2217
es6: true,

.github/workflows/ci.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
- 18
1919
- 20
2020
eslint:
21-
- 7.2
22-
- 7
23-
- 8
21+
- '8.56'
22+
- '8'
2423
runs-on: ${{ matrix.os }}
2524
steps:
2625
- name: Checkout Repo
@@ -60,7 +59,7 @@ jobs:
6059
EFF_NO_LINK_RULES: true
6160
PARSER_NO_WATCH: true
6261
SKIP_YARN_COREPACK_CHECK: 1
63-
if: ${{ matrix.node == 20 && matrix.eslint == 8 }}
62+
if: ${{ matrix.node == 20 }}
6463

6564
- name: Codecov
6665
uses: codecov/codecov-action@v3

package.json

+18-20
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545
"watch": "yarn test --watch"
4646
},
4747
"peerDependencies": {
48-
"eslint": "^7.2.0 || ^8 || ^9.0.0-0"
48+
"eslint": "^8.56.0 || ^9.0.0-0"
4949
},
5050
"dependencies": {
51-
"@typescript-eslint/utils": "^5.62.0",
51+
"@typescript-eslint/utils": "^7.4.0",
5252
"debug": "^4.3.4",
5353
"doctrine": "^3.0.0",
54-
"eslint-compat-utils": "^0.5.0",
5554
"eslint-import-resolver-node": "^0.3.9",
5655
"get-tsconfig": "^4.7.3",
5756
"is-glob": "^4.0.3",
@@ -62,33 +61,32 @@
6261
"@1stg/prettier-config": "^4.0.1",
6362
"@1stg/tsconfig": "^2.3.3",
6463
"@angular-eslint/template-parser": "^17.3.0",
65-
"@babel/core": "^7.24.0",
66-
"@babel/eslint-parser": "^7.23.10",
67-
"@babel/plugin-proposal-decorators": "^7.24.0",
68-
"@babel/plugin-proposal-export-default-from": "^7.23.3",
69-
"@babel/preset-env": "^7.24.0",
70-
"@babel/preset-flow": "^7.24.0",
71-
"@babel/preset-react": "^7.23.3",
72-
"@babel/preset-typescript": "^7.23.3",
64+
"@babel/core": "^7.24.3",
65+
"@babel/eslint-parser": "^7.24.1",
66+
"@babel/plugin-proposal-decorators": "^7.24.1",
67+
"@babel/plugin-proposal-export-default-from": "^7.24.1",
68+
"@babel/preset-env": "^7.24.3",
69+
"@babel/preset-flow": "^7.24.1",
70+
"@babel/preset-react": "^7.24.1",
71+
"@babel/preset-typescript": "^7.24.1",
7372
"@babel/register": "^7.23.7",
7473
"@changesets/changelog-github": "^0.5.0",
7574
"@changesets/cli": "^2.27.1",
7675
"@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped",
7776
"@swc-node/jest": "^1.8.0",
78-
"@swc/core": "^1.4.8",
77+
"@swc/core": "^1.4.11",
7978
"@swc/helpers": "^0.5.7",
8079
"@test-scope/some-module": "link:./test/fixtures/symlinked-module",
8180
"@total-typescript/ts-reset": "^0.5.1",
8281
"@types/debug": "^4.1.12",
8382
"@types/doctrine": "^0.0.9",
84-
"@types/eslint": "^8.56.5",
83+
"@types/eslint": "^8.56.6",
8584
"@types/is-glob": "^4.0.4",
8685
"@types/jest": "^29.5.12",
8786
"@types/json-schema": "^7.0.15",
88-
"@types/node": "^20.11.28",
89-
"@typescript-eslint/eslint-plugin": "^5.62.0",
90-
"@typescript-eslint/parser": "^5.62.0",
91-
"@typescript-eslint/typescript-estree": "^5.62.0",
87+
"@types/node": "^20.11.30",
88+
"@typescript-eslint/eslint-plugin": "^7.4.0",
89+
"@typescript-eslint/parser": "^7.4.0",
9290
"@unts/patch-package": "^8.0.0",
9391
"cross-env": "^7.0.3",
9492
"enhanced-resolve": "^5.16.0",
@@ -99,7 +97,7 @@
9997
"eslint-import-resolver-typescript": "^3.6.1",
10098
"eslint-import-resolver-webpack": "^0.13.8",
10199
"eslint-import-test-order-redirect": "link:./test/fixtures/order-redirect",
102-
"eslint-plugin-eslint-plugin": "^5.4.0",
100+
"eslint-plugin-eslint-plugin": "^5.4.1",
103101
"eslint-plugin-import-x": "link:.",
104102
"eslint-plugin-jest": "^27.9.0",
105103
"eslint-plugin-json": "^3.1.0",
@@ -113,7 +111,7 @@
113111
"rimraf": "^5.0.5",
114112
"svelte": "^4.2.12",
115113
"ts-node": "^10.9.2",
116-
"type-fest": "^4.12.0",
117-
"typescript": "~5.1.0"
114+
"type-fest": "^4.14.0",
115+
"typescript": "^5.4.3"
118116
}
119117
}

patches/@typescript-eslint+utils+5.62.0.patch renamed to patches/@typescript-eslint+utils+7.4.0.patch

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
diff --git a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
2-
index 9a3a1fd..c6ed412 100644
2+
index 5ae7288..3d14a45 100644
33
--- a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
44
+++ b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
5-
@@ -6,6 +6,10 @@ import type { Scope } from './Scope';
6-
import type { SourceCode } from './SourceCode';
7-
export type RuleRecommendation = 'error' | 'strict' | 'warn' | false;
8-
interface RuleMetaDataDocs {
5+
@@ -11,6 +11,10 @@ export interface RuleRecommendationAcrossConfigs<Options extends readonly unknow
6+
strict: Partial<Options>;
7+
}
8+
export interface RuleMetaDataDocs<Options extends readonly unknown[]> {
99
+ /**
1010
+ * The category the rule falls under
1111
+ */
1212
+ category?: string;
1313
/**
1414
* Concise description of the rule
1515
*/
16-
@@ -15,7 +19,7 @@ interface RuleMetaDataDocs {
16+
@@ -20,7 +24,7 @@ export interface RuleMetaDataDocs<Options extends readonly unknown[]> {
1717
* Used by the build tools to generate the recommended and strict configs.
18-
* Set to false to not include it as a recommendation
18+
* Exclude to not include it as a recommendation.
1919
*/
20-
- recommended: 'error' | 'strict' | 'warn' | false;
21-
+ recommended?: 'error' | 'strict' | 'warn' | boolean;
20+
- recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<Options>;
21+
+ recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<Options> | boolean;
2222
/**
2323
* The URL of the rule's docs
2424
*/
2525
diff --git a/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts b/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
26-
index c8afefe..d629d04 100644
26+
index 38d1f12..bf897a3 100644
2727
--- a/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
2828
+++ b/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
29-
@@ -115,7 +115,7 @@ interface RunTests<TMessageIds extends string, TOptions extends Readonly<unknown
30-
readonly invalid: readonly InvalidTestCase<TMessageIds, TOptions>[];
29+
@@ -113,7 +113,7 @@ interface RunTests<MessageIds extends string, Options extends Readonly<unknown[]
30+
readonly invalid: readonly InvalidTestCase<MessageIds, Options>[];
3131
}
32-
interface RuleTesterConfig extends Linter.Config {
32+
interface RuleTesterConfig extends ClassicConfig.Config {
3333
- readonly parser: string;
3434
+ readonly parser?: string;
3535
readonly parserOptions?: Readonly<ParserOptions>;

src/rules/consistent-type-specifier-style.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
2-
import { getSourceCode } from 'eslint-compat-utils'
32

43
import { createRule } from '../utils'
54

@@ -74,7 +73,7 @@ export = createRule<[Options?], MessageId>({
7473
},
7574
defaultOptions: [],
7675
create(context) {
77-
const sourceCode = getSourceCode(context)
76+
const { sourceCode } = context
7877

7978
if (context.options[0] === 'prefer-inline') {
8079
return {

src/rules/dynamic-import-chunkname.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import vm from 'node:vm'
22

33
import type { TSESTree } from '@typescript-eslint/utils'
4-
import { getSourceCode } from 'eslint-compat-utils'
54

65
import { createRule } from '../utils'
76

@@ -75,7 +74,7 @@ export = createRule<[Options?], MessageId>({
7574
const chunkSubstrRegex = new RegExp(chunkSubstrFormat)
7675

7776
function run(node: TSESTree.Node, arg: TSESTree.Node) {
78-
const sourceCode = getSourceCode(context)
77+
const { sourceCode } = context
7978
const leadingComments = sourceCode.getCommentsBefore(arg)
8079

8180
if ((!leadingComments || leadingComments.length === 0) && !allowEmpty) {

src/rules/extensions.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ import {
1111
} from '../utils'
1212

1313
const enumValues = {
14-
enum: ['always', 'ignorePackages', 'never'] as const,
14+
type: 'string' as const,
15+
enum: ['always', 'ignorePackages', 'never'],
1516
}
1617

1718
const patternProperties = {
18-
type: 'object',
19+
type: 'object' as const,
1920
patternProperties: { '.*': enumValues },
2021
}
2122

2223
const properties = {
23-
type: 'object',
24+
type: 'object' as const,
2425
properties: {
2526
pattern: patternProperties,
26-
ignorePackages: { type: 'boolean' },
27+
ignorePackages: {
28+
type: 'boolean' as const,
29+
},
2730
},
2831
}
2932

src/rules/first.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
2-
import { getSourceCode } from 'eslint-compat-utils'
32

43
import type { RuleContext } from '../types'
54
import { createRule } from '../utils'
@@ -53,7 +52,7 @@ export = createRule<['absolute-first'?], MessageId>({
5352
}
5453

5554
const absoluteFirst = context.options[0] === 'absolute-first'
56-
const sourceCode = getSourceCode(context)
55+
const { sourceCode } = context
5756
const originSourceCode = sourceCode.getText()
5857

5958
let nonImportCount = 0

src/rules/group-exports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export = createRule<[], 'ExportNamedDeclaration' | 'AssignmentExpression'>({
4444
description:
4545
'Prefer named exports to be grouped together in a single export declaration.',
4646
},
47-
schema: {},
47+
schema: [],
4848
messages: {
4949
ExportNamedDeclaration:
5050
'Multiple named export declarations; consolidate all named exports into a single export declaration',

src/rules/named.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'node:path'
22

33
import type { TSESTree } from '@typescript-eslint/utils'
4-
import { getFilename, getPhysicalFilename } from 'eslint-compat-utils'
54

65
import { ExportMap, createRule } from '../utils'
76
import type { ModuleOptions } from '../utils'
@@ -97,10 +96,7 @@ export = createRule<[ModuleOptions?], MessageId>({
9796
if (deepLookup.path.length > 1) {
9897
const deepPath = deepLookup.path
9998
.map(i =>
100-
path.relative(
101-
path.dirname(getPhysicalFilename(context)),
102-
i.path,
103-
),
99+
path.relative(path.dirname(context.physicalFilename), i.path),
104100
)
105101
.join(' -> ')
106102

@@ -196,9 +192,7 @@ export = createRule<[ModuleOptions?], MessageId>({
196192
if (!deepLookup.found) {
197193
if (deepLookup.path.length > 1) {
198194
const deepPath = deepLookup.path
199-
.map(i =>
200-
path.relative(path.dirname(getFilename(context)), i.path),
201-
)
195+
.map(i => path.relative(path.dirname(context.filename), i.path))
202196
.join(' -> ')
203197

204198
context.report({

src/rules/newline-after-import.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
66
import debug from 'debug'
7-
import { getPhysicalFilename } from 'eslint-compat-utils'
87

98
import { isStaticRequire, createRule, getScope } from '../utils'
109

@@ -245,7 +244,11 @@ export = createRule<[Options?], MessageId>({
245244
}
246245

247246
// skip "export import"s
248-
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) {
247+
if (
248+
node.type === 'TSImportEqualsDeclaration' &&
249+
// @ts-expect-error - legacy parser type
250+
node.isExport
251+
) {
249252
return
250253
}
251254

@@ -254,7 +257,9 @@ export = createRule<[Options?], MessageId>({
254257
} else if (
255258
nextNode &&
256259
nextNode.type !== 'ImportDeclaration' &&
257-
(nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)
260+
(nextNode.type !== 'TSImportEqualsDeclaration' ||
261+
// @ts-expect-error - legacy parser type
262+
nextNode.isExport)
258263
) {
259264
checkForNewLine(node, nextNode, 'import')
260265
}
@@ -269,7 +274,8 @@ export = createRule<[Options?], MessageId>({
269274
}
270275
},
271276
'Program:exit'(node) {
272-
log('exit processing for', getPhysicalFilename(context))
277+
log('exit processing for', context.physicalFilename)
278+
273279
const scopeBody = getScopeBody(getScope(context, node))
274280

275281
log('got scope:', scopeBody)

src/rules/no-absolute-path.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import path from 'node:path'
22

3-
import { getPhysicalFilename } from 'eslint-compat-utils'
4-
53
import {
64
isAbsolute,
75
createRule,
@@ -37,10 +35,9 @@ export = createRule<[ModuleOptions?], MessageId>({
3735
node: source,
3836
messageId: 'absolute',
3937
fix(fixer) {
40-
const resolvedContext = getPhysicalFilename(context)
4138
// node.js and web imports work with posix style paths ("/")
4239
let relativePath = path.posix.relative(
43-
path.dirname(resolvedContext),
40+
path.dirname(context.physicalFilename),
4441
source.value,
4542
)
4643
if (!relativePath.startsWith('.')) {

src/rules/no-anonymous-default-export.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const schemaProperties = Object.fromEntries(
105105
def.option,
106106
{
107107
description: def.description,
108-
type: 'boolean',
108+
type: 'boolean' as const,
109109
},
110110
]),
111111
)

src/rules/no-commonjs.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ export = createRule<[Options?], MessageId>({
7676
anyOf: [
7777
{
7878
type: 'array',
79-
items: [{ enum: ['allow-primitive-modules'] }],
79+
items: [
80+
{
81+
type: 'string',
82+
enum: ['allow-primitive-modules'],
83+
},
84+
],
8085
additionalItems: false,
8186
},
8287
{

0 commit comments

Comments
 (0)