@@ -25,32 +25,33 @@ import {
2525 PRESENCE_MATCHERS ,
2626} from '../utils' ;
2727
28- const SETTING_OPTION_OFF = 'off' as const ;
28+ const SETTING_OPTION_OFF = 'off' ;
2929
3030export 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 > ) ;
3234 'testing-library/custom-renders' ?: string [ ] | typeof SETTING_OPTION_OFF ;
3335 'testing-library/custom-queries' ?: string [ ] | typeof SETTING_OPTION_OFF ;
3436} ;
3537
3638export type TestingLibraryContext <
37- TOptions extends readonly unknown [ ] ,
3839 TMessageIds extends string ,
40+ TOptions extends readonly unknown [ ] ,
3941> = Readonly <
4042 TSESLint . RuleContext < TMessageIds , TOptions > & {
4143 settings : TestingLibrarySettings ;
4244 }
4345> ;
4446
4547export type EnhancedRuleCreate <
46- TOptions extends readonly unknown [ ] ,
4748 TMessageIds extends string ,
48- TRuleListener extends TSESLint . RuleListener = TSESLint . RuleListener ,
49+ TOptions extends readonly unknown [ ] ,
4950> = (
50- context : TestingLibraryContext < TOptions , TMessageIds > ,
51+ context : TestingLibraryContext < TMessageIds , TOptions > ,
5152 optionsWithDefault : Readonly < TOptions > ,
5253 detectionHelpers : Readonly < DetectionHelpers >
53- ) => TRuleListener ;
54+ ) => TSESLint . RuleListener ;
5455
5556// Helpers methods
5657type GetTestingLibraryImportNodeFn = ( ) => ImportModuleNode | null ;
@@ -154,15 +155,14 @@ export type DetectionOptions = {
154155 * Enhances a given rule `create` with helpers to detect Testing Library utils.
155156 */
156157export function detectTestingLibraryUtils <
157- TOptions extends readonly unknown [ ] ,
158158 TMessageIds extends string ,
159- TRuleListener extends TSESLint . RuleListener = TSESLint . RuleListener ,
159+ TOptions extends readonly unknown [ ] ,
160160> (
161- ruleCreate : EnhancedRuleCreate < TOptions , TMessageIds , TRuleListener > ,
161+ ruleCreate : EnhancedRuleCreate < TMessageIds , TOptions > ,
162162 { skipRuleReportingCheck = false } : Partial < DetectionOptions > = { }
163163) {
164164 return (
165- context : TestingLibraryContext < TOptions , TMessageIds > ,
165+ context : TestingLibraryContext < TMessageIds , TOptions > ,
166166 optionsWithDefault : Readonly < TOptions >
167167 ) : TSESLint . RuleListener => {
168168 const importedTestingLibraryNodes : ImportModuleNode [ ] = [ ] ;
@@ -212,6 +212,7 @@ export function detectTestingLibraryUtils<
212212
213213 const originalNodeName =
214214 isImportSpecifier ( importedUtilSpecifier ) &&
215+ ASTUtils . isIdentifier ( importedUtilSpecifier . imported ) &&
215216 importedUtilSpecifier . local . name !== importedUtilSpecifier . imported . name
216217 ? importedUtilSpecifier . imported . name
217218 : undefined ;
0 commit comments