Skip to content

Commit 3815685

Browse files
authored
feat: upgrade @typescript-eslint/utils to v6 (#238)
* feat: upgrade `@typescript-eslint/utils` to v6 * fix: remove `recommended` and `category` meta properties * fix: replace declaration merging with a type cast for now * fix: update `context` usages
1 parent 3a68a44 commit 3815685

10 files changed

+138
-100
lines changed

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@
6969
"@semantic-release/github"
7070
]
7171
},
72-
"resolutions": {
73-
"@typescript-eslint/experimental-utils": "^5.0.0"
74-
},
7572
"dependencies": {
76-
"@typescript-eslint/utils": "^5.10.0"
73+
"@typescript-eslint/utils": "^6.0.0"
7774
},
7875
"devDependencies": {
7976
"@babel/cli": "^7.4.4",
@@ -90,8 +87,8 @@
9087
"@types/dedent": "^0.7.0",
9188
"@types/jest": "^29.0.0",
9289
"@types/node": "^14.17.0",
93-
"@typescript-eslint/eslint-plugin": "^5.0.0",
94-
"@typescript-eslint/parser": "^5.0.0",
90+
"@typescript-eslint/eslint-plugin": "^6.0.0",
91+
"@typescript-eslint/parser": "^6.0.0",
9592
"babel-jest": "^29.0.0",
9693
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
9794
"dedent": "^1.0.0",

src/index.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readdirSync } from 'fs';
22
import { join, parse } from 'path';
3-
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
3+
import type { TSESLint } from '@typescript-eslint/utils';
44
import {
55
name as packageName,
66
version as packageVersion,
@@ -10,24 +10,6 @@ type RuleModule = TSESLint.RuleModule<string, unknown[]> & {
1010
meta: Required<Pick<TSESLint.RuleMetaData<string>, 'docs'>>;
1111
};
1212

13-
// v5 of `@typescript-eslint/experimental-utils` removed this
14-
declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
15-
export interface RuleMetaDataDocs {
16-
category: 'Best Practices' | 'Possible Errors' | 'Stylistic Issues';
17-
}
18-
}
19-
20-
declare module '@typescript-eslint/utils/dist/ts-eslint/SourceCode' {
21-
export interface SourceCode {
22-
/**
23-
* Returns the scope of the given node.
24-
* This information can be used track references to variables.
25-
* @since 8.37.0
26-
*/
27-
getScope(node: TSESTree.Node): TSESLint.Scope.Scope;
28-
}
29-
}
30-
3113
// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
3214
/* istanbul ignore next */
3315
const interopRequireDefault = (obj: any): { default: any } =>

src/rules/prefer-to-be-array.ts

-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export default createRule<Options, MessageIds>({
2525
name: __filename,
2626
meta: {
2727
docs: {
28-
category: 'Stylistic Issues',
2928
description: 'Suggest using `toBeArray()`',
30-
recommended: false,
3129
},
3230
messages: {
3331
preferToBeArray:

src/rules/prefer-to-be-false.ts

-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export default createRule({
1818
name: __filename,
1919
meta: {
2020
docs: {
21-
category: 'Stylistic Issues',
2221
description: 'Suggest using `toBeFalse()`',
23-
recommended: false,
2422
},
2523
messages: {
2624
preferToBeFalse: 'Prefer using `toBeFalse()` to test value is `false`.',

src/rules/prefer-to-be-object.ts

-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export default createRule<Options, MessageIds>({
1616
name: __filename,
1717
meta: {
1818
docs: {
19-
category: 'Stylistic Issues',
2019
description: 'Suggest using `toBeObject()`',
21-
recommended: false,
2220
},
2321
messages: {
2422
preferToBeObject:

src/rules/prefer-to-be-true.ts

-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export default createRule({
1818
name: __filename,
1919
meta: {
2020
docs: {
21-
category: 'Stylistic Issues',
2221
description: 'Suggest using `toBeTrue()`',
23-
recommended: false,
2422
},
2523
messages: {
2624
preferToBeTrue: 'Prefer using `toBeTrue()` to test value is `true`.',

src/rules/prefer-to-have-been-called-once.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export default createRule({
1010
name: __filename,
1111
meta: {
1212
docs: {
13-
category: 'Stylistic Issues',
1413
description: 'Suggest using `toHaveBeenCalledOnce()`',
15-
recommended: false,
1614
},
1715
messages: {
1816
preferCalledOnce: 'Prefer `toHaveBeenCalledOnce()`',

src/rules/utils/__tests__/parseJestFnCall.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ const rule = createRule({
5151
name: __filename,
5252
meta: {
5353
docs: {
54-
category: 'Possible Errors',
5554
description: 'Fake rule for testing parseJestFnCall',
56-
recommended: false,
5755
},
5856
messages: {
5957
details: '{{ data }}',

src/rules/utils/parseJestFnCall.ts

+14-19
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,22 @@ const ValidJestFnCallChains = [
166166
'xtest.failing.each',
167167
];
168168

169-
declare module '@typescript-eslint/utils/dist/ts-eslint' {
170-
export interface SharedConfigurationSettings {
171-
jest?: {
172-
globalAliases?: Record<string, string[]>;
173-
globalPackage?: string;
174-
version?: number | string;
175-
};
176-
}
169+
// todo: switch back to using declaration merging once https://github.com/typescript-eslint/typescript-eslint/pull/8485
170+
// is landed
171+
interface SharedConfigurationSettings {
172+
jest?: {
173+
globalAliases?: Record<string, string[]>;
174+
globalPackage?: string;
175+
version?: number | string;
176+
};
177177
}
178178

179179
const resolvePossibleAliasedGlobal = (
180180
global: string,
181181
context: TSESLint.RuleContext<string, unknown[]>,
182182
) => {
183-
const globalAliases = context.settings.jest?.globalAliases ?? {};
183+
const globalAliases =
184+
(context.settings as SharedConfigurationSettings).jest?.globalAliases ?? {};
184185

185186
const alias = Object.entries(globalAliases).find(([, aliases]) =>
186187
aliases.includes(global),
@@ -569,7 +570,8 @@ const resolveToJestFn = (
569570

570571
if (maybeImport) {
571572
const globalPackage =
572-
context.settings.jest?.globalPackage ?? '@jest/globals';
573+
(context.settings as SharedConfigurationSettings).jest?.globalPackage ??
574+
'@jest/globals';
573575

574576
// the identifier is imported from our global package so return the original import name
575577
if (maybeImport.source === globalPackage) {
@@ -595,14 +597,7 @@ const getScope = (
595597
context: TSESLint.RuleContext<string, unknown[]>,
596598
node: TSESTree.Node,
597599
) => {
598-
const sourceCode =
599-
'sourceCode' in context
600-
? (context.sourceCode as TSESLint.SourceCode)
601-
: context.getSourceCode();
602-
603-
if ('getScope' in sourceCode) {
604-
return sourceCode.getScope(node);
605-
}
600+
const sourceCode = context.sourceCode ?? context.getSourceCode();
606601

607-
return context.getScope();
602+
return sourceCode.getScope?.(node) ?? context.getScope();
608603
};

0 commit comments

Comments
 (0)