1
- import { AST_NODE_TYPES } from '@typescript-eslint/utils' ;
1
+ import { AST_NODE_TYPES , type TSESTree } from '@typescript-eslint/utils' ;
2
+ import jestFnNames from '../globals.json' ;
2
3
import {
3
4
type ParsedJestFnCall ,
4
5
createRule ,
@@ -31,11 +32,32 @@ export default createRule({
31
32
} ,
32
33
defaultOptions : [ ] ,
33
34
create ( context ) {
35
+ const jestFunctionNames : string [ ] = Object . keys ( jestFnNames ) ;
34
36
const importedJestFunctions : string [ ] = [ ] ;
35
37
const usedJestFunctions : ParsedJestFnCall [ ] = [ ] ;
36
38
37
39
return {
38
- CallExpression ( node ) {
40
+ CallExpression ( node : TSESTree . CallExpression ) {
41
+ if (
42
+ node . type === AST_NODE_TYPES . CallExpression &&
43
+ node . callee . type === AST_NODE_TYPES . Identifier &&
44
+ jestFunctionNames . includes ( node . callee . name )
45
+ ) {
46
+ const jestFnCall : ParsedJestFnCall = {
47
+ head : {
48
+ type : 'import' ,
49
+ node : node . callee ,
50
+ original : node . callee . name ,
51
+ local : node . callee . name ,
52
+ } ,
53
+ name : node . callee . name ,
54
+ type : 'jest' ,
55
+ members : [ ] ,
56
+ } ;
57
+
58
+ usedJestFunctions . push ( jestFnCall ) ;
59
+ }
60
+
39
61
const jestFnCall = parseJestFnCall ( node , context ) ;
40
62
41
63
if ( ! jestFnCall ) {
@@ -56,8 +78,8 @@ export default createRule({
56
78
if ( ! jestFunctionsToReport . length ) {
57
79
return ;
58
80
}
59
- const jestFunctionsToImport = jestFunctionsToReport . map (
60
- jestFunction => jestFunction . name ,
81
+ const jestFunctionsToImport = Array . from (
82
+ new Set ( jestFunctionsToReport . map ( jestFunction => jestFunction . name ) ) ,
61
83
) ;
62
84
const reportingNode = jestFunctionsToReport [ 0 ] . head . node ;
63
85
0 commit comments