Skip to content

Commit a9bd859

Browse files
committed
refactor: force consistent type imports
Types must be imported: - as separate type imports - in the last position of import groups
1 parent 5d5b484 commit a9bd859

Some content is hidden

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

51 files changed

+182
-150
lines changed

eslint.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const config = defineConfig(
3737
'max-lines-per-function': 'off',
3838

3939
// TypeScript
40+
'@typescript-eslint/consistent-type-imports': 'error',
4041
'@typescript-eslint/explicit-function-return-type': 'off',
4142
'@typescript-eslint/no-unused-vars': [
4243
'warn',
@@ -50,7 +51,14 @@ const config = defineConfig(
5051
'import-x/order': [
5152
'warn',
5253
{
53-
groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
54+
groups: [
55+
'builtin',
56+
'external',
57+
'internal',
58+
['parent', 'sibling', 'index'],
59+
'object',
60+
'type',
61+
],
5462
'newlines-between': 'always',
5563

5664
alphabetize: {

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 & 2 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 = {

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 & 8 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 = [

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';

lib/rules/await-async-queries.ts

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

33
import { createTestingLibraryRule } from '../create-testing-library-rule';
44
import {
@@ -10,6 +10,8 @@ import {
1010
isPromiseHandled,
1111
} from '../node-utils';
1212

13+
import type { TSESTree } from '@typescript-eslint/utils';
14+
1315
export const RULE_NAME = 'await-async-queries';
1416
export type MessageIds = 'asyncQueryWrapper' | 'awaitAsyncQuery';
1517
type Options = [];

lib/rules/await-async-utils.ts

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

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

16+
import type { TSESTree } from '@typescript-eslint/utils';
17+
1618
export const RULE_NAME = 'await-async-utils';
1719
export type MessageIds = 'asyncUtilWrapper' | 'awaitAsyncUtil';
1820
type Options = [];

lib/rules/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { readdirSync } from 'fs';
22
import { join, parse } from 'path';
33

4-
import { importDefault, TestingLibraryPluginRuleModule } from '../utils';
4+
import { importDefault } from '../utils';
5+
6+
import type { TestingLibraryPluginRuleModule } from '../utils';
57

68
const rulesDir = __dirname;
79
const excludedFiles = ['index'];

0 commit comments

Comments
 (0)