Skip to content

Commit 7ab7356

Browse files
authored
chore: migrate dev dependency ESLint to v9 (#1078)
1 parent 62d343c commit 7ab7356

File tree

62 files changed

+1747
-1176
lines changed

Some content is hidden

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

62 files changed

+1747
-1176
lines changed

.eslint-doc-generatorrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const prettier = require('prettier');
2+
23
const prettierConfig = require('./.prettierrc.js');
34

45
/** @type {import('eslint-doc-generator').GenerateOptions} */

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// @ts-check
2+
3+
import js from '@eslint/js';
4+
import { defineConfig, globalIgnores } from 'eslint/config';
5+
import prettierConfig from 'eslint-config-prettier/flat';
6+
import { importX } from 'eslint-plugin-import-x';
7+
import jest from 'eslint-plugin-jest';
8+
import * as jestFormatting from 'eslint-plugin-jest-formatting';
9+
import globals from 'globals';
10+
import tseslint from 'typescript-eslint';
11+
12+
const config = defineConfig(
13+
js.configs.recommended,
14+
tseslint.configs.recommendedTypeChecked,
15+
importX.flatConfigs.recommended,
16+
importX.flatConfigs.typescript,
17+
{
18+
name: 'Language options',
19+
files: ['**/*.{js,mjs,cjs,ts,mts}'],
20+
languageOptions: {
21+
globals: {
22+
...globals.node,
23+
},
24+
ecmaVersion: 'latest',
25+
sourceType: 'module',
26+
parser: tseslint.parser,
27+
parserOptions: {
28+
projectService: true,
29+
tsconfigRootDir: import.meta.dirname,
30+
},
31+
},
32+
},
33+
{
34+
name: 'Rules overrides for all files',
35+
rules: {
36+
// Base
37+
'max-lines-per-function': 'off',
38+
'no-console': 'warn',
39+
40+
// TypeScript
41+
'@typescript-eslint/consistent-type-imports': 'error',
42+
'@typescript-eslint/explicit-function-return-type': 'off',
43+
'@typescript-eslint/no-unused-vars': [
44+
'warn',
45+
{
46+
argsIgnorePattern: '^_',
47+
},
48+
],
49+
'@typescript-eslint/no-use-before-define': 'off',
50+
51+
// Import
52+
'import-x/order': [
53+
'warn',
54+
{
55+
groups: [
56+
'builtin',
57+
'external',
58+
'internal',
59+
['parent', 'sibling', 'index'],
60+
'object',
61+
'type',
62+
],
63+
'newlines-between': 'always',
64+
65+
alphabetize: {
66+
order: 'asc',
67+
caseInsensitive: false,
68+
},
69+
},
70+
],
71+
'import-x/first': 'error',
72+
'import-x/no-empty-named-blocks': 'error',
73+
'import-x/no-extraneous-dependencies': 'error',
74+
'import-x/no-mutable-exports': 'error',
75+
'import-x/no-named-default': 'error',
76+
'import-x/no-relative-packages': 'warn',
77+
},
78+
},
79+
{
80+
name: 'Rule overrides only for TypeScript files',
81+
files: ['**/*.{ts,mts}'],
82+
rules: {
83+
// Rules enabled by `import-x/recommended` but are better handled by
84+
// TypeScript and typescript-eslint.
85+
'import-x/default': 'off',
86+
'import-x/export': 'off',
87+
'import-x/namespace': 'off',
88+
'import-x/no-unresolved': 'off',
89+
},
90+
},
91+
{
92+
name: 'Jest config',
93+
files: ['**/*.test.ts', '**/*.test.js'],
94+
...jest.configs['flat/recommended'],
95+
...jestFormatting.configs['flat/recommended'],
96+
},
97+
{
98+
name: 'Plain JS',
99+
files: ['**/*.{js,mjs,cjs}'],
100+
extends: [tseslint.configs.disableTypeChecked],
101+
},
102+
{
103+
name: 'Config files',
104+
files: ['**/*rc*.{js,mjs,cjs}', '**/*.config.{js,cjs,mjs,ts}'],
105+
rules: {
106+
'@typescript-eslint/no-require-imports': 'off',
107+
'import-x/no-named-as-default-member': 'off',
108+
},
109+
},
110+
globalIgnores(['**/coverage/', '**/dist/']),
111+
prettierConfig // must always be the last one
112+
);
113+
114+
export default config;

lib/configs/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { join } from 'path';
22

3-
import type { TSESLint } from '@typescript-eslint/utils';
3+
import { importDefault, SUPPORTED_TESTING_FRAMEWORKS } from '../utils';
44

5-
import {
6-
importDefault,
7-
SUPPORTED_TESTING_FRAMEWORKS,
8-
SupportedTestingFramework,
9-
} from '../utils';
5+
import type { SupportedTestingFramework } from '../utils';
6+
import type { TSESLint } from '@typescript-eslint/utils';
107

118
const configsDir = __dirname;
129

lib/create-testing-library-rule/detect-testing-library-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ASTUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
1+
import { ASTUtils } from '@typescript-eslint/utils';
22

33
import {
44
findClosestVariableDeclaratorNode,
@@ -9,7 +9,6 @@ import {
99
getPropertyIdentifierNode,
1010
getReferenceNode,
1111
hasImportMatch,
12-
ImportModuleNode,
1312
isCallExpression,
1413
isImportDeclaration,
1514
isImportDefaultSpecifier,
@@ -31,6 +30,9 @@ import {
3130
isTestingLibraryModule,
3231
} from '../utils/is-testing-library-module';
3332

33+
import type { ImportModuleNode } from '../node-utils';
34+
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
35+
3436
const SETTING_OPTION_OFF = 'off';
3537

3638
export type TestingLibrarySettings = {
@@ -490,7 +492,6 @@ export function detectTestingLibraryUtils<
490492
/**
491493
* Determines whether a given node is fireEvent method or not
492494
*/
493-
// eslint-disable-next-line complexity
494495
const isFireEventMethod: IsFireEventMethodFn = (node) => {
495496
const fireEventUtil =
496497
findImportedTestingLibraryUtilSpecifier(FIRE_EVENT_NAME);
@@ -527,7 +528,6 @@ export function detectTestingLibraryUtils<
527528

528529
// we know it's defined at this point, but TS seems to think it is not
529530
// so here I'm enforcing it once in order to avoid using "!" operator every time
530-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
531531
const definedParentMemberExpression = parentMemberExpression!;
532532

533533
// check fireEvent.click() usage

lib/create-testing-library-rule/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ESLintUtils } from '@typescript-eslint/utils';
22

3-
import {
4-
getDocsUrl,
3+
import { getDocsUrl } from '../utils';
4+
import { detectTestingLibraryUtils } from './detect-testing-library-utils';
5+
6+
import type {
57
TestingLibraryPluginDocs,
68
TestingLibraryPluginRuleModule,
79
} from '../utils';
8-
9-
import {
10+
import type {
1011
DetectionOptions,
11-
detectTestingLibraryUtils,
1212
EnhancedRuleCreate,
1313
} from './detect-testing-library-utils';
1414

lib/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { TSESLint } from '@typescript-eslint/utils';
2-
31
import configs from './configs';
42
import rules from './rules';
5-
import { SupportedTestingFramework } from './utils';
3+
4+
import type { SupportedTestingFramework } from './utils';
5+
import type { TSESLint } from '@typescript-eslint/utils';
66

77
// we can't natively import package.json as tsc will copy it into dist/
88
const {

lib/node-utils/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { FunctionScope, ScopeType } from '@typescript-eslint/scope-manager';
2-
import {
3-
AST_NODE_TYPES,
4-
ASTUtils,
5-
TSESLint,
6-
TSESTree,
7-
} from '@typescript-eslint/utils';
1+
import { ScopeType } from '@typescript-eslint/scope-manager';
2+
import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';
83

94
import { getDeclaredVariables, getScope } from '../utils';
10-
115
import {
126
isArrayExpression,
137
isArrowFunctionExpression,
@@ -28,6 +22,9 @@ import {
2822
isVariableDeclaration,
2923
} from './is-node-of-type';
3024

25+
import type { FunctionScope } from '@typescript-eslint/scope-manager';
26+
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
27+
3128
export * from './is-node-of-type';
3229

3330
const ValidLeftHandSideExpressions = [
@@ -301,7 +298,6 @@ export function getVariableReferences(
301298
node: TSESTree.Node
302299
): TSESLint.Scope.Reference[] {
303300
if (ASTUtils.isVariableDeclarator(node)) {
304-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
305301
return getDeclaredVariables(context, node)[0]?.references?.slice(1) ?? [];
306302
}
307303

lib/rules/await-async-events.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ASTUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
1+
import { ASTUtils } from '@typescript-eslint/utils';
22

33
import { createTestingLibraryRule } from '../create-testing-library-rule';
44
import {
@@ -12,6 +12,8 @@ import {
1212
} from '../node-utils';
1313
import { EVENTS_SIMULATORS } from '../utils';
1414

15+
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
16+
1517
export const RULE_NAME = 'await-async-events';
1618
export type MessageIds = 'awaitAsyncEvent' | 'awaitAsyncEventWrapper';
1719
const FIRE_EVENT_NAME = 'fireEvent';

0 commit comments

Comments
 (0)