@@ -25,32 +25,33 @@ import {
25
25
PRESENCE_MATCHERS ,
26
26
} from '../utils' ;
27
27
28
- const SETTING_OPTION_OFF = 'off' as const ;
28
+ const SETTING_OPTION_OFF = 'off' ;
29
29
30
30
export type TestingLibrarySettings = {
31
- 'testing-library/utils-module' ?: string | typeof SETTING_OPTION_OFF ;
31
+ 'testing-library/utils-module' ?:
32
+ | typeof SETTING_OPTION_OFF
33
+ | ( string & NonNullable < unknown > ) ;
32
34
'testing-library/custom-renders' ?: string [ ] | typeof SETTING_OPTION_OFF ;
33
35
'testing-library/custom-queries' ?: string [ ] | typeof SETTING_OPTION_OFF ;
34
36
} ;
35
37
36
38
export type TestingLibraryContext <
37
- TOptions extends readonly unknown [ ] ,
38
39
TMessageIds extends string ,
40
+ TOptions extends readonly unknown [ ] ,
39
41
> = Readonly <
40
42
TSESLint . RuleContext < TMessageIds , TOptions > & {
41
43
settings : TestingLibrarySettings ;
42
44
}
43
45
> ;
44
46
45
47
export type EnhancedRuleCreate <
46
- TOptions extends readonly unknown [ ] ,
47
48
TMessageIds extends string ,
48
- TRuleListener extends TSESLint . RuleListener = TSESLint . RuleListener ,
49
+ TOptions extends readonly unknown [ ] ,
49
50
> = (
50
- context : TestingLibraryContext < TOptions , TMessageIds > ,
51
+ context : TestingLibraryContext < TMessageIds , TOptions > ,
51
52
optionsWithDefault : Readonly < TOptions > ,
52
53
detectionHelpers : Readonly < DetectionHelpers >
53
- ) => TRuleListener ;
54
+ ) => TSESLint . RuleListener ;
54
55
55
56
// Helpers methods
56
57
type GetTestingLibraryImportNodeFn = ( ) => ImportModuleNode | null ;
@@ -154,15 +155,14 @@ export type DetectionOptions = {
154
155
* Enhances a given rule `create` with helpers to detect Testing Library utils.
155
156
*/
156
157
export function detectTestingLibraryUtils <
157
- TOptions extends readonly unknown [ ] ,
158
158
TMessageIds extends string ,
159
- TRuleListener extends TSESLint . RuleListener = TSESLint . RuleListener ,
159
+ TOptions extends readonly unknown [ ] ,
160
160
> (
161
- ruleCreate : EnhancedRuleCreate < TOptions , TMessageIds , TRuleListener > ,
161
+ ruleCreate : EnhancedRuleCreate < TMessageIds , TOptions > ,
162
162
{ skipRuleReportingCheck = false } : Partial < DetectionOptions > = { }
163
163
) {
164
164
return (
165
- context : TestingLibraryContext < TOptions , TMessageIds > ,
165
+ context : TestingLibraryContext < TMessageIds , TOptions > ,
166
166
optionsWithDefault : Readonly < TOptions >
167
167
) : TSESLint . RuleListener => {
168
168
const importedTestingLibraryNodes : ImportModuleNode [ ] = [ ] ;
@@ -212,6 +212,7 @@ export function detectTestingLibraryUtils<
212
212
213
213
const originalNodeName =
214
214
isImportSpecifier ( importedUtilSpecifier ) &&
215
+ ASTUtils . isIdentifier ( importedUtilSpecifier . imported ) &&
215
216
importedUtilSpecifier . local . name !== importedUtilSpecifier . imported . name
216
217
? importedUtilSpecifier . imported . name
217
218
: undefined ;
0 commit comments