Skip to content

Commit 83c107e

Browse files
committed
feat(deps): update to @typescript-eslint/* v8
1 parent 2bd0323 commit 83c107e

17 files changed

+281
-295
lines changed

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ export type TestingLibrarySettings = {
3636
};
3737

3838
export type TestingLibraryContext<
39-
TOptions extends readonly unknown[],
4039
TMessageIds extends string,
40+
TOptions extends readonly unknown[],
4141
> = Readonly<
4242
TSESLint.RuleContext<TMessageIds, TOptions> & {
4343
settings: TestingLibrarySettings;
4444
}
4545
>;
4646

4747
export type EnhancedRuleCreate<
48-
TOptions extends readonly unknown[],
4948
TMessageIds extends string,
50-
TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener,
49+
TOptions extends readonly unknown[],
5150
> = (
52-
context: TestingLibraryContext<TOptions, TMessageIds>,
51+
context: TestingLibraryContext<TMessageIds, TOptions>,
5352
optionsWithDefault: Readonly<TOptions>,
5453
detectionHelpers: Readonly<DetectionHelpers>
55-
) => TRuleListener;
54+
) => TSESLint.RuleListener;
5655

5756
// Helpers methods
5857
type GetTestingLibraryImportNodeFn = () => ImportModuleNode | null;
@@ -156,15 +155,14 @@ export type DetectionOptions = {
156155
* Enhances a given rule `create` with helpers to detect Testing Library utils.
157156
*/
158157
export function detectTestingLibraryUtils<
159-
TOptions extends readonly unknown[],
160158
TMessageIds extends string,
161-
TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener,
159+
TOptions extends readonly unknown[],
162160
>(
163-
ruleCreate: EnhancedRuleCreate<TOptions, TMessageIds, TRuleListener>,
161+
ruleCreate: EnhancedRuleCreate<TMessageIds, TOptions>,
164162
{ skipRuleReportingCheck = false }: Partial<DetectionOptions> = {}
165163
) {
166164
return (
167-
context: TestingLibraryContext<TOptions, TMessageIds>,
165+
context: TestingLibraryContext<TMessageIds, TOptions>,
168166
optionsWithDefault: Readonly<TOptions>
169167
): TSESLint.RuleListener => {
170168
const importedTestingLibraryNodes: ImportModuleNode[] = [];
@@ -214,6 +212,7 @@ export function detectTestingLibraryUtils<
214212

215213
const originalNodeName =
216214
isImportSpecifier(importedUtilSpecifier) &&
215+
ASTUtils.isIdentifier(importedUtilSpecifier.imported) &&
217216
importedUtilSpecifier.local.name !== importedUtilSpecifier.imported.name
218217
? importedUtilSpecifier.imported.name
219218
: undefined;
+17-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ESLintUtils, TSESLint } from '@typescript-eslint/utils';
1+
import { ESLintUtils } from '@typescript-eslint/utils';
22

3-
import { getDocsUrl, TestingLibraryRuleMeta } from '../utils';
3+
import { getDocsUrl, TestingLibraryPluginDocs } from '../utils';
44

55
import {
66
DetectionOptions,
@@ -11,32 +11,27 @@ import {
1111
export const createTestingLibraryRule = <
1212
TOptions extends readonly unknown[],
1313
TMessageIds extends string,
14-
TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener,
1514
>({
1615
create,
1716
detectionOptions = {},
18-
meta,
1917
...remainingConfig
20-
}: Readonly<{
21-
name: string;
22-
meta: TestingLibraryRuleMeta<TMessageIds, TOptions>;
23-
defaultOptions: Readonly<TOptions>;
24-
detectionOptions?: Partial<DetectionOptions>;
25-
create: EnhancedRuleCreate<TOptions, TMessageIds, TRuleListener>;
26-
}>): TSESLint.RuleModule<TMessageIds, TOptions> =>
27-
ESLintUtils.RuleCreator(getDocsUrl)({
18+
}: Readonly<
19+
Omit<
20+
ESLintUtils.RuleWithMetaAndName<
21+
TOptions,
22+
TMessageIds,
23+
TestingLibraryPluginDocs<TOptions>
24+
>,
25+
'create'
26+
> & {
27+
create: EnhancedRuleCreate<TMessageIds, TOptions>;
28+
detectionOptions?: Partial<DetectionOptions>;
29+
}
30+
>) =>
31+
ESLintUtils.RuleCreator<TestingLibraryPluginDocs<TOptions>>(getDocsUrl)({
2832
...remainingConfig,
29-
create: detectTestingLibraryUtils<TOptions, TMessageIds, TRuleListener>(
33+
create: detectTestingLibraryUtils<TMessageIds, TOptions>(
3034
create,
3135
detectionOptions
3236
),
33-
meta: {
34-
...meta,
35-
docs: {
36-
...meta.docs,
37-
// We're using our own recommendedConfig meta to tell our build tools
38-
// if the rule is recommended on a config basis
39-
recommended: undefined,
40-
},
41-
},
4237
});

lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SupportedTestingFramework } from './utils';
88
const {
99
name: packageName,
1010
version: packageVersion,
11-
// eslint-disable-next-line @typescript-eslint/no-var-requires
11+
// eslint-disable-next-line @typescript-eslint/no-require-imports
1212
} = require('../package.json') as { name: string; version: string };
1313

1414
const plugin = {

lib/node-utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ export function findImportSpecifier(
665665
const namedExport = node.specifiers.find((n) => {
666666
return (
667667
isImportSpecifier(n) &&
668+
ASTUtils.isIdentifier(n.imported) &&
668669
[n.imported.name, n.local.name].includes(specifierName)
669670
);
670671
});

lib/rules/index.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import { readdirSync } from 'fs';
22
import { join, parse } from 'path';
33

4-
import { TSESLint } from '@typescript-eslint/utils';
5-
6-
import { importDefault, TestingLibraryRuleMeta } from '../utils';
7-
8-
type RuleModule = TSESLint.RuleModule<string, unknown[]> & {
9-
meta: TestingLibraryRuleMeta<string, unknown[]> & {
10-
recommended: false;
11-
};
12-
};
4+
import { importDefault, TestingLibraryPluginRuleModule } from '../utils';
135

146
const rulesDir = __dirname;
157
const excludedFiles = ['index'];
168

179
export default readdirSync(rulesDir)
1810
.map((rule) => parse(rule).name)
1911
.filter((ruleName) => !excludedFiles.includes(ruleName))
20-
.reduce<Record<string, RuleModule>>(
12+
.reduce<Record<string, TestingLibraryPluginRuleModule<string, unknown[]>>>(
2113
(allRules, ruleName) => ({
2214
...allRules,
23-
[ruleName]: importDefault<RuleModule>(join(rulesDir, ruleName)),
15+
[ruleName]: importDefault<
16+
TestingLibraryPluginRuleModule<string, unknown[]>
17+
>(join(rulesDir, ruleName)),
2418
}),
2519
{}
2620
);

lib/rules/no-manual-cleanup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
7575
const cleanupSpecifier = moduleNode.specifiers.find(
7676
(specifier) =>
7777
isImportSpecifier(specifier) &&
78+
ASTUtils.isIdentifier(specifier.imported) &&
7879
specifier.imported.name === 'cleanup'
7980
);
8081

lib/utils/file-import.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const interopRequireDefault = <T>(obj: any): { default: T } =>
55
obj?.__esModule ? obj : { default: obj };
66

77
export const importDefault = <T>(moduleName: string): T =>
8-
// eslint-disable-next-line @typescript-eslint/no-var-requires
8+
// eslint-disable-next-line @typescript-eslint/no-require-imports
99
interopRequireDefault<T>(require(moduleName)).default;

lib/utils/types.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { type TSESLint } from '@typescript-eslint/utils';
1+
import { TSESLint } from '@typescript-eslint/utils';
22

33
type Recommended = 'error' | 'warn' | false;
44
type RecommendedConfig<TOptions extends readonly unknown[]> =
55
| Recommended
66
| [Recommended, ...TOptions];
77

8-
// These 2 types are copied from `@typescript-eslint/utils`' `CreateRuleMeta`
9-
// and modified to our needs
10-
export type TestingLibraryRuleMetaDocs<TOptions extends readonly unknown[]> =
11-
Omit<TSESLint.RuleMetaDataDocs<TOptions>, 'recommended' | 'url'> & {
12-
/**
13-
* The recommendation level for the rule on a framework basis.
14-
* Used by the build tools to generate the framework config.
15-
* Set to `false` to not include it the config
16-
*/
17-
recommendedConfig: Record<
18-
SupportedTestingFramework,
19-
RecommendedConfig<TOptions>
20-
>;
21-
};
22-
export type TestingLibraryRuleMeta<
8+
export type TestingLibraryPluginDocs<TOptions extends readonly unknown[]> = {
9+
/**
10+
* The recommendation level for the rule on a framework basis.
11+
* Used by the build tools to generate the framework config.
12+
* Set to `false` to not include it the config
13+
*/
14+
recommendedConfig: Record<
15+
SupportedTestingFramework,
16+
RecommendedConfig<TOptions>
17+
>;
18+
};
19+
20+
export type TestingLibraryPluginRuleModule<
2321
TMessageIds extends string,
2422
TOptions extends readonly unknown[],
25-
> = Omit<TSESLint.RuleMetaData<TMessageIds, TOptions>, 'docs'> & {
26-
docs: TestingLibraryRuleMetaDocs<TOptions>;
27-
};
23+
> = TSESLint.RuleModuleWithMetaDocs<
24+
TMessageIds,
25+
TOptions,
26+
TestingLibraryPluginDocs<TOptions>
27+
>;
2828

2929
export const SUPPORTED_TESTING_FRAMEWORKS = [
3030
'dom',

lint-staged.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//eslint-disable-next-line @typescript-eslint/no-var-requires
1+
//eslint-disable-next-line @typescript-eslint/no-require-imports
22
const { ESLint } = require('eslint');
33

44
const removeIgnoredFiles = async (files) => {

0 commit comments

Comments
 (0)