1- import { AST_NODE_TYPES , ESLintUtils , TSESLint } from '@typescript-eslint/utils'
1+ import { AST_NODE_TYPES , ESLintUtils } from '@typescript-eslint/utils'
2+ import { DefinitionType } from '@typescript-eslint/scope-manager'
23import { createEslintRule } from '../utils'
34import { parsePluginSettings } from '../utils/parse-plugin-settings'
45import { parseVitestFnCall } from '../utils/parse-vitest-fn-call'
@@ -32,7 +33,32 @@ export default createEslintRule<Options, MESSAGE_IDS>({
3233 return
3334 }
3435
36+ const scope = getModuleScope ( context , node )
3537 const [ argument ] = node . arguments
38+ if (
39+ argument . type === AST_NODE_TYPES . MemberExpression &&
40+ argument . object . type === AST_NODE_TYPES . Identifier &&
41+ argument . property . type === AST_NODE_TYPES . Identifier
42+ ) {
43+ const identifierName = argument . object . name
44+ const scopedFunction = scope ?. set . get ( identifierName ) ?. defs [ 0 ]
45+ if (
46+ scopedFunction ?. type !== DefinitionType . ImportBinding ||
47+ argument . property . name !== 'name'
48+ ) {
49+ return
50+ }
51+
52+ context . report ( {
53+ node : argument ,
54+ messageId : 'preferFunction' ,
55+ fix ( fixer ) {
56+ return fixer . replaceText ( argument , identifierName )
57+ } ,
58+ } )
59+ return
60+ }
61+
3662 if (
3763 argument . type !== AST_NODE_TYPES . Literal ||
3864 typeof argument . value !== 'string'
@@ -50,9 +76,8 @@ export default createEslintRule<Options, MESSAGE_IDS>({
5076 return
5177 }
5278
53- const scope = getModuleScope ( context , node )
5479 const scopedFunction = scope ?. set . get ( describedTitle ) ?. defs [ 0 ]
55- if ( scopedFunction ?. type !== ' ImportBinding' ) {
80+ if ( scopedFunction ?. type !== DefinitionType . ImportBinding ) {
5681 return
5782 }
5883
0 commit comments