@@ -125,6 +125,11 @@ export const ignoreNewArrayOptionSchema: JSONSchema4 = {
125
125
additionalProperties : false
126
126
} ;
127
127
128
+ /**
129
+ * Recursive callback of `getNodeText`.
130
+ *
131
+ * This function not be called from anywhere else.
132
+ */
128
133
function _getNodeText (
129
134
node : TSESTree . Node ,
130
135
context : RuleContext < string , BaseOptions >
@@ -139,6 +144,9 @@ function _getNodeText(
139
144
: context . getSourceCode ( ) . getText ( node ) ;
140
145
}
141
146
147
+ /**
148
+ * Get the text of the given node.
149
+ */
142
150
function getNodeText (
143
151
node : TSESTree . Node ,
144
152
context : RuleContext < string , BaseOptions >
@@ -156,6 +164,9 @@ function getNodeText(
156
164
: _getNodeText ( node , context ) ;
157
165
}
158
166
167
+ /**
168
+ * Get all the important bits of texts from the given node.
169
+ */
159
170
function getNodeTexts (
160
171
node : TSESTree . Node ,
161
172
context : RuleContext < string , BaseOptions >
@@ -166,7 +177,12 @@ function getNodeTexts(
166
177
) . filter ( name => name !== undefined ) as ReadonlyArray < string > ;
167
178
}
168
179
169
- function isIgnoredPattern (
180
+ /**
181
+ * Should the given text be ignore?
182
+ *
183
+ * Test using the given pattern(s).
184
+ */
185
+ function shouldIgnoreViaPattern (
170
186
text : string ,
171
187
ignorePattern : ReadonlyArray < string > | string
172
188
) : boolean {
@@ -178,7 +194,14 @@ function isIgnoredPattern(
178
194
return patterns . some ( pattern => new RegExp ( pattern ) . test ( text ) ) ;
179
195
}
180
196
181
- function findMatch (
197
+ /**
198
+ * Recursive callback of `shouldIgnoreViaAccessorPattern`.
199
+ *
200
+ * This function not be called from anywhere else.
201
+ *
202
+ * Does the given text match the given pattern.
203
+ */
204
+ function accessorPatternMatch (
182
205
[ pattern , ...remainingPatternParts ] : ReadonlyArray < string > ,
183
206
textParts : ReadonlyArray < string > ,
184
207
allowExtra : boolean = false
@@ -188,23 +211,41 @@ function findMatch(
188
211
: // Match any depth (including 0)?
189
212
pattern === "**"
190
213
? textParts . length === 0
191
- ? findMatch ( remainingPatternParts , [ ] , allowExtra )
214
+ ? accessorPatternMatch ( remainingPatternParts , [ ] , allowExtra )
192
215
: Array . from ( { length : textParts . length } )
193
216
. map ( ( _element , index ) => index )
194
217
. some ( offset =>
195
- findMatch ( remainingPatternParts , textParts . slice ( offset ) , true )
218
+ accessorPatternMatch (
219
+ remainingPatternParts ,
220
+ textParts . slice ( offset ) ,
221
+ true
222
+ )
196
223
)
197
224
: // Match anything?
198
225
pattern === "*"
199
226
? textParts . length > 0 &&
200
- findMatch ( remainingPatternParts , textParts . slice ( 1 ) , allowExtra )
227
+ accessorPatternMatch (
228
+ remainingPatternParts ,
229
+ textParts . slice ( 1 ) ,
230
+ allowExtra
231
+ )
201
232
: // Text matches pattern?
202
233
new RegExp ( "^" + escapeRegExp ( pattern ) . replace ( / \\ \* / g, ".*" ) + "$" ) . test (
203
234
textParts [ 0 ]
204
- ) && findMatch ( remainingPatternParts , textParts . slice ( 1 ) , allowExtra ) ;
235
+ ) &&
236
+ accessorPatternMatch (
237
+ remainingPatternParts ,
238
+ textParts . slice ( 1 ) ,
239
+ allowExtra
240
+ ) ;
205
241
}
206
242
207
- function isIgnoredAccessorPattern (
243
+ /**
244
+ * Should the given text be ignore?
245
+ *
246
+ * Test using the given accessor pattern(s).
247
+ */
248
+ function shouldIgnoreViaAccessorPattern (
208
249
text : string ,
209
250
ignorePattern : ReadonlyArray < string > | string
210
251
) : boolean {
@@ -214,7 +255,7 @@ function isIgnoredAccessorPattern(
214
255
215
256
// One or more patterns match?
216
257
return patterns . some ( pattern =>
217
- findMatch ( pattern . split ( "." ) , text . split ( "." ) )
258
+ accessorPatternMatch ( pattern . split ( "." ) , text . split ( "." ) )
218
259
) ;
219
260
}
220
261
@@ -238,12 +279,15 @@ export function shouldIgnore(
238
279
? // Ignore if ignorePattern is set and a pattern matches.
239
280
( options . ignorePattern !== undefined &&
240
281
texts . every ( text =>
241
- isIgnoredPattern ( text , options . ignorePattern ! )
282
+ shouldIgnoreViaPattern ( text , options . ignorePattern ! )
242
283
) ) ||
243
284
// Ignore if ignoreAccessorPattern is set and an accessor pattern matches.
244
285
( options . ignoreAccessorPattern !== undefined &&
245
286
texts . every ( text =>
246
- isIgnoredAccessorPattern ( text , options . ignoreAccessorPattern ! )
287
+ shouldIgnoreViaAccessorPattern (
288
+ text ,
289
+ options . ignoreAccessorPattern !
290
+ )
247
291
) )
248
292
: false ) ( getNodeTexts ( node , context ) )
249
293
) ;
0 commit comments