@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/prefer-regexp-test"
3
3
4
4
const tester = new RuleTester ( {
5
5
parserOptions : {
6
- ecmaVersion : 2020 ,
6
+ ecmaVersion : "latest" ,
7
7
sourceType : "module" ,
8
8
} ,
9
9
} )
@@ -33,6 +33,11 @@ tester.run("prefer-regexp-test", rule as any, {
33
33
const a = pattern.exec(text)
34
34
const b = text.match(pattern)
35
35
` ,
36
+ `
37
+ const text = 'something';
38
+ const pattern = /thin[[g]]/v;
39
+ if (pattern.test(text)) {}
40
+ ` ,
36
41
] ,
37
42
invalid : [
38
43
{
@@ -186,5 +191,37 @@ tester.run("prefer-regexp-test", rule as any, {
186
191
"Use the `RegExp#test()` method instead of `String#match`, if you need a boolean." ,
187
192
] ,
188
193
} ,
194
+ {
195
+ code : `
196
+ const text = 'something';
197
+ const pattern = /thin[[g]]/v;
198
+ if (pattern.exec(text)) {}
199
+ if (text.match(pattern)) {}
200
+ ` ,
201
+ output : `
202
+ const text = 'something';
203
+ const pattern = /thin[[g]]/v;
204
+ if (pattern.test(text)) {}
205
+ if (pattern.test(text)) {}
206
+ ` ,
207
+ errors : [
208
+ {
209
+ message :
210
+ "Use the `RegExp#test()` method instead of `RegExp#exec`, if you need a boolean." ,
211
+ line : 4 ,
212
+ column : 25 ,
213
+ endLine : 4 ,
214
+ endColumn : 29 ,
215
+ } ,
216
+ {
217
+ message :
218
+ "Use the `RegExp#test()` method instead of `String#match`, if you need a boolean." ,
219
+ line : 5 ,
220
+ column : 17 ,
221
+ endLine : 5 ,
222
+ endColumn : 36 ,
223
+ } ,
224
+ ] ,
225
+ } ,
189
226
] ,
190
227
} )
0 commit comments