@@ -3,32 +3,15 @@ import escapeRegExp from "escape-string-regexp";
3
3
import type { JSONSchema4 } from "json-schema" ;
4
4
import type { ReadonlyDeep } from "type-fest" ;
5
5
6
+ import { getNodeIdentifierTexts } from "~/util/misc" ;
6
7
import type { BaseOptions } from "~/util/rule" ;
8
+ import { inClass , inFunctionBody , inInterface } from "~/util/tree" ;
7
9
import {
8
- getKeyOfValueInObjectExpression ,
9
- inClass ,
10
- inFunctionBody ,
11
- inInterface ,
12
- } from "~/util/tree" ;
13
- import {
14
- hasID ,
15
- hasKey ,
16
10
isAssignmentExpression ,
17
- isDefined ,
18
11
isPropertyDefinition ,
19
- isExpressionStatement ,
20
- isIdentifier ,
21
12
isMemberExpression ,
22
13
isReadonlyArray ,
23
14
isThisExpression ,
24
- isTSArrayType ,
25
- isTSIndexSignature ,
26
- isTSTupleType ,
27
- isTSTypeAnnotation ,
28
- isTSTypeLiteral ,
29
- isTSTypeReference ,
30
- isUnaryExpression ,
31
- isVariableDeclaration ,
32
15
} from "~/util/typeguard" ;
33
16
34
17
/**
@@ -125,73 +108,6 @@ export const ignoreInterfaceOptionSchema: JSONSchema4["properties"] = {
125
108
} ,
126
109
} ;
127
110
128
- /**
129
- * Get the identifier text of the given node.
130
- */
131
- function getNodeIdentifierText (
132
- node : ReadonlyDeep < TSESTree . Node > | null | undefined ,
133
- context : ReadonlyDeep < TSESLint . RuleContext < string , BaseOptions > >
134
- ) : string | undefined {
135
- if ( ! isDefined ( node ) ) {
136
- return undefined ;
137
- }
138
-
139
- const identifierText = isIdentifier ( node )
140
- ? node . name
141
- : hasID ( node ) && isDefined ( node . id )
142
- ? getNodeIdentifierText ( node . id , context )
143
- : hasKey ( node ) && isDefined ( node . key )
144
- ? getNodeIdentifierText ( node . key , context )
145
- : isAssignmentExpression ( node )
146
- ? getNodeIdentifierText ( node . left , context )
147
- : isMemberExpression ( node )
148
- ? `${ getNodeIdentifierText ( node . object , context ) } .${ getNodeIdentifierText (
149
- node . property ,
150
- context
151
- ) } `
152
- : isThisExpression ( node )
153
- ? "this"
154
- : isUnaryExpression ( node )
155
- ? getNodeIdentifierText ( node . argument , context )
156
- : isExpressionStatement ( node )
157
- ? context . getSourceCode ( ) . getText ( node as TSESTree . Node )
158
- : isTSArrayType ( node ) ||
159
- isTSIndexSignature ( node ) ||
160
- isTSTupleType ( node ) ||
161
- isTSTypeAnnotation ( node ) ||
162
- isTSTypeLiteral ( node ) ||
163
- isTSTypeReference ( node )
164
- ? getNodeIdentifierText ( node . parent , context )
165
- : null ;
166
-
167
- if ( identifierText !== null ) {
168
- return identifierText ;
169
- }
170
-
171
- const keyInObjectExpression = getKeyOfValueInObjectExpression ( node ) ;
172
- if ( keyInObjectExpression !== null ) {
173
- return keyInObjectExpression ;
174
- }
175
-
176
- return undefined ;
177
- }
178
-
179
- /**
180
- * Get all the identifier texts of the given node.
181
- */
182
- function getNodeIdentifierTexts (
183
- node : ReadonlyDeep < TSESTree . Node > ,
184
- context : ReadonlyDeep < TSESLint . RuleContext < string , BaseOptions > >
185
- ) : ReadonlyArray < string > {
186
- return (
187
- isVariableDeclaration ( node )
188
- ? node . declarations . flatMap ( ( declarator ) =>
189
- getNodeIdentifierText ( declarator , context )
190
- )
191
- : [ getNodeIdentifierText ( node , context ) ]
192
- ) . filter < string > ( ( text ) : text is string => text !== undefined ) ;
193
- }
194
-
195
111
/**
196
112
* Should the given text be allowed?
197
113
*
0 commit comments