File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ export default createRule({
84
84
) {
85
85
const [ , flags ] = node . arguments ;
86
86
return (
87
+ flags &&
87
88
flags . type === AST_NODE_TYPES . Literal &&
88
89
typeof flags . value === 'string' &&
89
90
flags . value . includes ( 'g' )
Original file line number Diff line number Diff line change @@ -230,6 +230,33 @@ function test(pattern: string) {
230
230
output : `
231
231
function test(pattern: string) {
232
232
new RegExp(pattern, undefined).exec('check');
233
+ }
234
+ ` ,
235
+ } ,
236
+ {
237
+ // https://github.com/typescript-eslint/typescript-eslint/issues/3941
238
+ code : `
239
+ function temp(text: string): void {
240
+ text.match(new RegExp(\`\${'hello'}\`));
241
+ text.match(new RegExp(\`\${'hello'.toString()}\`));
242
+ }
243
+ ` ,
244
+ errors : [
245
+ {
246
+ messageId : 'regExpExecOverStringMatch' ,
247
+ line : 3 ,
248
+ column : 8 ,
249
+ } ,
250
+ {
251
+ messageId : 'regExpExecOverStringMatch' ,
252
+ line : 4 ,
253
+ column : 8 ,
254
+ } ,
255
+ ] ,
256
+ output : `
257
+ function temp(text: string): void {
258
+ new RegExp(\`\${'hello'}\`).exec(text);
259
+ new RegExp(\`\${'hello'.toString()}\`).exec(text);
233
260
}
234
261
` ,
235
262
} ,
You can’t perform that action at this time.
0 commit comments