@@ -30,16 +30,24 @@ export default util.createRule({
30
30
create ( context ) {
31
31
const sourceCode = context . getSourceCode ( ) ;
32
32
33
+ interface Method {
34
+ name : string ;
35
+ static : boolean ;
36
+ callSignature : boolean ;
37
+ }
38
+
33
39
/**
34
- * Gets the name of the member being processed.
40
+ * Gets the name and attribute of the member being processed.
35
41
* @param member the member being processed.
36
- * @returns the name of the member or null if it's a member not relevant to the rule.
42
+ * @returns the name and attribute of the member or null if it's a member not relevant to the rule.
37
43
*/
38
- function getMemberName ( member : TSESTree . Node ) : string | null {
44
+ function getMemberMethod ( member : TSESTree . Node ) : Method | null {
39
45
if ( ! member ) {
40
46
return null ;
41
47
}
42
48
49
+ const isStatic = 'static' in member && ! ! member . static ;
50
+
43
51
switch ( member . type ) {
44
52
case AST_NODE_TYPES . ExportDefaultDeclaration :
45
53
case AST_NODE_TYPES . ExportNamedDeclaration : {
@@ -49,33 +57,55 @@ export default util.createRule({
49
57
return null ;
50
58
}
51
59
52
- return getMemberName ( member . declaration ) ;
60
+ return getMemberMethod ( member . declaration ) ;
53
61
}
54
62
case AST_NODE_TYPES . TSDeclareFunction :
55
- case AST_NODE_TYPES . FunctionDeclaration :
56
- return member . id ?. name ?? null ;
63
+ case AST_NODE_TYPES . FunctionDeclaration : {
64
+ const name = member . id ?. name ?? null ;
65
+ if ( name === null ) {
66
+ return null ;
67
+ }
68
+ return {
69
+ name,
70
+ static : isStatic ,
71
+ callSignature : false ,
72
+ } ;
73
+ }
57
74
case AST_NODE_TYPES . TSMethodSignature :
58
- return util . getNameFromMember ( member , sourceCode ) ;
75
+ return {
76
+ name : util . getNameFromMember ( member , sourceCode ) ,
77
+ static : isStatic ,
78
+ callSignature : false ,
79
+ } ;
59
80
case AST_NODE_TYPES . TSCallSignatureDeclaration :
60
- return 'call' ;
81
+ return {
82
+ name : 'call' ,
83
+ static : isStatic ,
84
+ callSignature : true ,
85
+ } ;
61
86
case AST_NODE_TYPES . TSConstructSignatureDeclaration :
62
- return 'new' ;
87
+ return {
88
+ name : 'new' ,
89
+ static : isStatic ,
90
+ callSignature : false ,
91
+ } ;
63
92
case AST_NODE_TYPES . MethodDefinition :
64
- return util . getNameFromMember ( member , sourceCode ) ;
93
+ return {
94
+ name : util . getNameFromMember ( member , sourceCode ) ,
95
+ static : isStatic ,
96
+ callSignature : false ,
97
+ } ;
65
98
}
66
99
67
100
return null ;
68
101
}
69
102
70
- interface Method {
71
- name : string ;
72
- static : boolean ;
73
- }
74
103
function isSameMethod ( method1 : Method , method2 : Method | null ) : boolean {
75
104
return (
76
105
! ! method2 &&
77
106
method1 . name === method2 . name &&
78
- method1 . static === method2 . static
107
+ method1 . static === method2 . static &&
108
+ method1 . callSignature === method2 . callSignature
79
109
) ;
80
110
}
81
111
@@ -104,15 +134,11 @@ export default util.createRule({
104
134
const seenMethods : Method [ ] = [ ] ;
105
135
106
136
members . forEach ( member => {
107
- const name = getMemberName ( member ) ;
108
- if ( name === null ) {
137
+ const method = getMemberMethod ( member ) ;
138
+ if ( method === null ) {
109
139
lastMethod = null ;
110
140
return ;
111
141
}
112
- const method = {
113
- name,
114
- static : 'static' in member && ! ! member . static ,
115
- } ;
116
142
117
143
const index = seenMethods . findIndex ( seenMethod =>
118
144
isSameMethod ( method , seenMethod ) ,
0 commit comments