@@ -123,16 +123,14 @@ export default createRule({
123
123
return
124
124
}
125
125
126
- let argument : ESTree . Node = node . arguments [ 0 ]
127
- if ( ! argument ) return
126
+ const [ argument ] = node . arguments
127
+ const title = dereference ( context , argument ) ?? argument
128
+ if ( ! title ) return
128
129
129
- // Attempt to dereference the argument if it's a variable
130
- argument = dereference ( context , argument ) ?? argument
131
-
132
- if ( ! isStringNode ( argument ) ) {
130
+ if ( ! isStringNode ( title ) ) {
133
131
if (
134
- argument . type === 'BinaryExpression' &&
135
- doesBinaryExpressionContainStringNode ( argument )
132
+ title . type === 'BinaryExpression' &&
133
+ doesBinaryExpressionContainStringNode ( title )
136
134
) {
137
135
return
138
136
}
@@ -143,21 +141,21 @@ export default createRule({
143
141
( call . type === 'test' && ignoreTypeOfTestName ) ||
144
142
( call . type === 'step' && ignoreTypeOfStepName )
145
143
) &&
146
- ( argument as ESTree . Node ) . type !== 'TemplateLiteral'
144
+ ( title as ESTree . Node ) . type !== 'TemplateLiteral'
147
145
) {
148
146
context . report ( {
149
- loc : argument . loc ! ,
147
+ loc : title . loc ! ,
150
148
messageId : 'titleMustBeString' ,
151
149
} )
152
150
}
153
151
154
152
return
155
153
}
156
154
157
- const title = getStringValue ( argument )
155
+ const titleString = getStringValue ( title )
158
156
const functionName = call . type
159
157
160
- if ( ! title ) {
158
+ if ( ! titleString ) {
161
159
context . report ( {
162
160
data : { functionName : call . type } ,
163
161
messageId : 'emptyTitle' ,
@@ -168,52 +166,55 @@ export default createRule({
168
166
}
169
167
170
168
if ( disallowedWords . length > 0 ) {
171
- const disallowedMatch = disallowedWordsRegexp . exec ( title )
169
+ const disallowedMatch = disallowedWordsRegexp . exec ( titleString )
172
170
173
171
if ( disallowedMatch ) {
174
172
context . report ( {
175
173
data : { word : disallowedMatch [ 1 ] } ,
176
174
messageId : 'disallowedWord' ,
177
- node : argument ,
175
+ node : title ,
178
176
} )
179
177
180
178
return
181
179
}
182
180
}
183
181
184
- if ( ignoreSpaces === false && title . trim ( ) . length !== title . length ) {
182
+ if (
183
+ ignoreSpaces === false &&
184
+ titleString . trim ( ) . length !== titleString . length
185
+ ) {
185
186
context . report ( {
186
187
fix : ( fixer ) => [
187
188
fixer . replaceTextRange (
188
- argument . range ! ,
189
- quoteStringValue ( argument )
189
+ title . range ! ,
190
+ quoteStringValue ( title )
190
191
. replace ( / ^ ( [ ` ' " ] ) + ?/ u, '$1' )
191
192
. replace ( / + ?( [ ` ' " ] ) $ / u, '$1' ) ,
192
193
) ,
193
194
] ,
194
195
messageId : 'accidentalSpace' ,
195
- node : argument ,
196
+ node : title ,
196
197
} )
197
198
}
198
199
199
- const [ firstWord ] = title . split ( ' ' )
200
+ const [ firstWord ] = titleString . split ( ' ' )
200
201
if ( firstWord . toLowerCase ( ) === functionName ) {
201
202
context . report ( {
202
203
fix : ( fixer ) => [
203
204
fixer . replaceTextRange (
204
- argument . range ! ,
205
- quoteStringValue ( argument ) . replace ( / ^ ( [ ` ' " ] ) .+ ? / u, '$1' ) ,
205
+ title . range ! ,
206
+ quoteStringValue ( title ) . replace ( / ^ ( [ ` ' " ] ) .+ ? / u, '$1' ) ,
206
207
) ,
207
208
] ,
208
209
messageId : 'duplicatePrefix' ,
209
- node : argument ,
210
+ node : title ,
210
211
} )
211
212
}
212
213
213
214
const [ mustNotMatchPattern , mustNotMatchMessage ] =
214
215
mustNotMatchPatterns [ functionName ] ?? [ ]
215
216
216
- if ( mustNotMatchPattern && mustNotMatchPattern . test ( title ) ) {
217
+ if ( mustNotMatchPattern && mustNotMatchPattern . test ( titleString ) ) {
217
218
context . report ( {
218
219
data : {
219
220
functionName,
@@ -223,7 +224,7 @@ export default createRule({
223
224
messageId : mustNotMatchMessage
224
225
? 'mustNotMatchCustom'
225
226
: 'mustNotMatch' ,
226
- node : argument ,
227
+ node : title ,
227
228
} )
228
229
229
230
return
@@ -232,15 +233,15 @@ export default createRule({
232
233
const [ mustMatchPattern , mustMatchMessage ] =
233
234
mustMatchPatterns [ functionName ] ?? [ ]
234
235
235
- if ( mustMatchPattern && ! mustMatchPattern . test ( title ) ) {
236
+ if ( mustMatchPattern && ! mustMatchPattern . test ( titleString ) ) {
236
237
context . report ( {
237
238
data : {
238
239
functionName,
239
240
message : mustMatchMessage ?? '' ,
240
241
pattern : String ( mustMatchPattern ) ,
241
242
} ,
242
243
messageId : mustMatchMessage ? 'mustMatchCustom' : 'mustMatch' ,
243
- node : argument ,
244
+ node : title ,
244
245
} )
245
246
246
247
return
0 commit comments