The actual snapshot is saved in prefer-regexp-test.mjs.snap
.
Generated by AVA.
1 | const re = /a/; const bar = !foo.match(re)
Output
`␊
1 | const re = /a/; const bar = !re.test(foo)␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = !foo.match(re)␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; const bar = Boolean(foo.match(re))
Output
`␊
1 | const re = /a/; const bar = Boolean(re.test(foo))␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = Boolean(foo.match(re))␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; if (foo.match(re)) {}
Output
`␊
1 | const re = /a/; if (re.test(foo)) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if (foo.match(re)) {}␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; const bar = foo.match(re) ? 1 : 2
Output
`␊
1 | const re = /a/; const bar = re.test(foo) ? 1 : 2␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = foo.match(re) ? 1 : 2␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; while (foo.match(re)) foo = foo.slice(1);
Output
`␊
1 | const re = /a/; while (re.test(foo)) foo = foo.slice(1);␊
`
Error 1/1
`␊
> 1 | const re = /a/; while (foo.match(re)) foo = foo.slice(1);␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; do {foo = foo.slice(1)} while (foo.match(re));
Output
`␊
1 | const re = /a/; do {foo = foo.slice(1)} while (re.test(foo));␊
`
Error 1/1
`␊
> 1 | const re = /a/; do {foo = foo.slice(1)} while (foo.match(re));␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; for (; foo.match(re); ) foo = foo.slice(1);
Output
`␊
1 | const re = /a/; for (; re.test(foo); ) foo = foo.slice(1);␊
`
Error 1/1
`␊
> 1 | const re = /a/; for (; foo.match(re); ) foo = foo.slice(1);␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; const bar = !re.exec(foo)
Output
`␊
1 | const re = /a/; const bar = !re.test(foo)␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = !re.exec(foo)␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; const bar = Boolean(re.exec(foo))
Output
`␊
1 | const re = /a/; const bar = Boolean(re.test(foo))␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = Boolean(re.exec(foo))␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; if (re.exec(foo)) {}
Output
`␊
1 | const re = /a/; if (re.test(foo)) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if (re.exec(foo)) {}␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; const bar = re.exec(foo) ? 1 : 2
Output
`␊
1 | const re = /a/; const bar = re.test(foo) ? 1 : 2␊
`
Error 1/1
`␊
> 1 | const re = /a/; const bar = re.exec(foo) ? 1 : 2␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; while (re.exec(foo)) foo = foo.slice(1);
Output
`␊
1 | const re = /a/; while (re.test(foo)) foo = foo.slice(1);␊
`
Error 1/1
`␊
> 1 | const re = /a/; while (re.exec(foo)) foo = foo.slice(1);␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; do {foo = foo.slice(1)} while (re.exec(foo));
Output
`␊
1 | const re = /a/; do {foo = foo.slice(1)} while (re.test(foo));␊
`
Error 1/1
`␊
> 1 | const re = /a/; do {foo = foo.slice(1)} while (re.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; for (; re.exec(foo); ) foo = foo.slice(1);
Output
`␊
1 | const re = /a/; for (; re.test(foo); ) foo = foo.slice(1);␊
`
Error 1/1
`␊
> 1 | const re = /a/; for (; re.exec(foo); ) foo = foo.slice(1);␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const re = /a/; if ((0, foo).match(re)) {}
Output
`␊
1 | const re = /a/; if ((re).test((0, foo))) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if ((0, foo).match(re)) {}␊
| ^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; if ((0, foo).match((re))) {}
Output
`␊
1 | const re = /a/; if ((re).test((0, foo))) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if ((0, foo).match((re))) {}␊
| ^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; if ((foo).match(re)) {}
Output
`␊
1 | const re = /a/; if ((re).test(foo)) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if ((foo).match(re)) {}␊
| ^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; if ((foo).match((re))) {}
Output
`␊
1 | const re = /a/; if ((re).test((foo))) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if ((foo).match((re))) {}␊
| ^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(/re/)) {}
Output
`␊
1 | if (/re/.test(foo)) {}␊
`
Error 1/1
`␊
> 1 | if (foo.match(/re/)) {}␊
| ^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const re = /a/; if (foo.match(re)) {}
Output
`␊
1 | const re = /a/; if (re.test(foo)) {}␊
`
Error 1/1
`␊
> 1 | const re = /a/; if (foo.match(re)) {}␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | const bar = {bar: /a/}; if (foo.match(bar.baz)) {}
Error 1/1
`␊
> 1 | const bar = {bar: /a/}; if (foo.match(bar.baz)) {}␊
| ^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const bar = {bar: /a/}; if (bar.baz.test(foo)) {}␊
`
1 | if (foo.match(bar.baz())) {}
Error 1/1
`␊
> 1 | if (foo.match(bar.baz())) {}␊
| ^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if (bar.baz().test(foo)) {}␊
`
1 | if (foo.match(new RegExp("re", "g"))) {}
Output
`␊
1 | if (new RegExp("re", "g").test(foo)) {}␊
`
Error 1/1
`␊
> 1 | if (foo.match(new RegExp("re", "g"))) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(new SomeRegExp())) {}
Error 1/1
`␊
> 1 | if (foo.match(new SomeRegExp())) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if (new SomeRegExp().test(foo)) {}␊
`
1 | if (foo.match(new SomeRegExp)) {}
Error 1/1
`␊
> 1 | if (foo.match(new SomeRegExp)) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if ((new SomeRegExp).test(foo)) {}␊
`
1 | if (foo.match(bar?.baz)) {}
Error 1/1
`␊
> 1 | if (foo.match(bar?.baz)) {}␊
| ^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if (bar?.baz.test(foo)) {}␊
`
1 | if (foo.match(bar?.baz())) {}
Error 1/1
`␊
> 1 | if (foo.match(bar?.baz())) {}␊
| ^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if (bar?.baz().test(foo)) {}␊
`
1 | if (foo.match(bar || baz)) {}
Error 1/1
`␊
> 1 | if (foo.match(bar || baz)) {}␊
| ^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if ((bar || baz).test(foo)) {}␊
`
1 | async function a() {
2 | if (foo.match(await bar())) {}
3 | }
Error 1/1
`␊
1 | async function a() {␊
> 2 | if (foo.match(await bar())) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
3 | }␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | async function a() {␊
2 | if ((await bar()).test(foo)) {}␊
3 | }␊
`
1 | if ((foo).match(/re/)) {}
Output
`␊
1 | if ((/re/).test(foo)) {}␊
`
Error 1/1
`␊
> 1 | if ((foo).match(/re/)) {}␊
| ^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if ((foo).match(new SomeRegExp)) {}
Error 1/1
`␊
> 1 | if ((foo).match(new SomeRegExp)) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if ((new SomeRegExp).test(foo)) {}␊
`
1 | if ((foo).match(bar?.baz)) {}
Error 1/1
`␊
> 1 | if ((foo).match(bar?.baz)) {}␊
| ^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if ((bar?.baz).test(foo)) {}␊
`
1 | if ((foo).match(bar?.baz())) {}
Error 1/1
`␊
> 1 | if ((foo).match(bar?.baz())) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if ((bar?.baz()).test(foo)) {}␊
`
1 | const bar = false; const baz = /a/; if ((foo).match(bar || baz)) {}
Output
`␊
1 | const bar = false; const baz = /a/; if ((bar || baz).test(foo)) {}␊
`
Error 1/1
`␊
> 1 | const bar = false; const baz = /a/; if ((foo).match(bar || baz)) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | async function a() {
2 | if ((foo).match(await bar())) {}
3 | }
Error 1/1
`␊
1 | async function a() {␊
> 2 | if ((foo).match(await bar())) {}␊
| ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
3 | }␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | async function a() {␊
2 | if ((await bar()).test(foo)) {}␊
3 | }␊
`
1 | const re = [/a/]; if (foo.match([re][0])) {}
Error 1/1
`␊
> 1 | const re = [/a/]; if (foo.match([re][0])) {}␊
| ^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const re = [/a/]; if ([re][0].test(foo)) {}␊
`
1 | async function a() {
2 | if (
3 | /* 1 */ foo() /* 2 */
4 | ./* 3 */ match /* 4 */ (
5 | /* 5 */ await /* 6 */ bar() /* 7 */
6 | ,
7 | /* 8 */
8 | )
9 | ) {}
10 | }
Error 1/1
`␊
1 | async function a() {␊
2 | if (␊
> 3 | /* 1 */ foo() /* 2 */␊
| ^^^^^^^^^^^^^␊
> 4 | ./* 3 */ match /* 4 */ (␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^␊
> 5 | /* 5 */ await /* 6 */ bar() /* 7 */␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^␊
> 6 | ,␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^␊
> 7 | /* 8 */␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^␊
> 8 | )␊
| ^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
9 | ) {}␊
10 | }␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | async function a() {␊
2 | if (␊
3 | /* 1 */ (await /* 6 */ bar()) /* 2 */␊
4 | ./* 3 */ test /* 4 */ (␊
5 | /* 5 */ foo() /* 7 */␊
6 | ,␊
7 | /* 8 */␊
8 | )␊
9 | ) {}␊
10 | }␊
`
1 | const string = '[.!?]\s*$';
2 | if (foo.match(string)) {
3 | }
Error 1/1
`␊
1 | const string = '[.!?]\\s*$';␊
> 2 | if (foo.match(string)) {␊
| ^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
3 | }␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const string = '[.!?]\\s*$';␊
2 | if (string.test(foo)) {␊
3 | }␊
`
1 | const regex = new RegExp('[.!?]\s*$');
2 | if (foo.match(regex)) {}
Output
`␊
1 | const regex = new RegExp('[.!?]\\s*$');␊
2 | if (regex.test(foo)) {}␊
`
Error 1/1
`␊
1 | const regex = new RegExp('[.!?]\\s*$');␊
> 2 | if (foo.match(regex)) {}␊
| ^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(unknown)) {}
Error 1/1
`␊
> 1 | if (foo.match(unknown)) {}␊
| ^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | if (unknown.test(foo)) {}␊
`
1 | if (foo.match(/a/g));
Output
`␊
1 | if (/a/g.test(foo));␊
`
Error 1/1
`␊
> 1 | if (foo.match(/a/g));␊
| ^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(/a/y));
Output
`␊
1 | if (/a/y.test(foo));␊
`
Error 1/1
`␊
> 1 | if (foo.match(/a/y));␊
| ^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(/a/gy));
Output
`␊
1 | if (/a/gy.test(foo));␊
`
Error 1/1
`␊
> 1 | if (foo.match(/a/gy));␊
| ^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(/a/ig));
Output
`␊
1 | if (/a/ig.test(foo));␊
`
Error 1/1
`␊
> 1 | if (foo.match(/a/ig));␊
| ^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (foo.match(new RegExp("a", "g")));
Output
`␊
1 | if (new RegExp("a", "g").test(foo));␊
`
Error 1/1
`␊
> 1 | if (foo.match(new RegExp("a", "g")));␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
`
1 | if (/a/g.exec(foo));
Output
`␊
1 | if (/a/g.test(foo));␊
`
Error 1/1
`␊
> 1 | if (/a/g.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | if (/a/y.exec(foo));
Output
`␊
1 | if (/a/y.test(foo));␊
`
Error 1/1
`␊
> 1 | if (/a/y.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | if (/a/gy.exec(foo));
Output
`␊
1 | if (/a/gy.test(foo));␊
`
Error 1/1
`␊
> 1 | if (/a/gy.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | if (/a/yi.exec(foo));
Output
`␊
1 | if (/a/yi.test(foo));␊
`
Error 1/1
`␊
> 1 | if (/a/yi.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | if (new RegExp("a", "g").exec(foo));
Output
`␊
1 | if (new RegExp("a", "g").test(foo));␊
`
Error 1/1
`␊
> 1 | if (new RegExp("a", "g").exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | if (new RegExp("a", "y").exec(foo));
Output
`␊
1 | if (new RegExp("a", "y").test(foo));␊
`
Error 1/1
`␊
> 1 | if (new RegExp("a", "y").exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const regex = /weird/g;
2 | if (foo.match(regex));
Error 1/1
`␊
1 | const regex = /weird/g;␊
> 2 | if (foo.match(regex));␊
| ^^^^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const regex = /weird/g;␊
2 | if (regex.test(foo));␊
`
1 | const regex = /weird/g;
2 | if (regex.exec(foo));
Error 1/1
`␊
1 | const regex = /weird/g;␊
> 2 | if (regex.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const regex = /weird/g;␊
2 | if (regex.test(foo));␊
`
1 | const regex = /weird/y;
2 | if (regex.exec(foo));
Output
`␊
1 | const regex = /weird/y;␊
2 | if (regex.test(foo));␊
`
Error 1/1
`␊
1 | const regex = /weird/y;␊
> 2 | if (regex.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | const regex = /weird/gyi;
2 | if (regex.exec(foo));
Error 1/1
`␊
1 | const regex = /weird/gyi;␊
> 2 | if (regex.exec(foo));␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | const regex = /weird/gyi;␊
2 | if (regex.test(foo));␊
`
1 | let re = new RegExp('foo', 'g');
2 | if(str.match(re));
Error 1/1
`␊
1 | let re = new RegExp('foo', 'g');␊
> 2 | if(str.match(re));␊
| ^^^^^^^^^^^^^ Prefer \`RegExp#test(…)\` over \`String#match(…)\`.␊
␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`RegExp#test(…)\`.␊
1 | let re = new RegExp('foo', 'g');␊
2 | if(re.test(str));␊
`
1 | !/a/u.exec(foo)
Output
`␊
1 | !/a/u.test(foo)␊
`
Error 1/1
`␊
> 1 | !/a/u.exec(foo)␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`
1 | !/a/v.exec(foo)
Output
`␊
1 | !/a/v.test(foo)␊
`
Error 1/1
`␊
> 1 | !/a/v.exec(foo)␊
| ^^^^ Prefer \`.test(…)\` over \`.exec(…)\`.␊
`