noMultipleSpacesInRegularExpressionLiterals (since v0.7.0)
This rule is recommended by Rome.
Disallow unclear usage of multiple space characters in regular expression literals
Examples
Invalid
/ / error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:2
│
1 │ / /
│ ^^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {3}/
| @@ -1 +1 @@
0 | - / /
0 | + / {3}/
/ foo/ error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:2
│
1 │ / foo/
│ ^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {2}/
| @@ -1 +1 @@
0 | - / foo/
0 | + / {2}foo/
/foo / error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:5
│
1 │ /foo /
│ ^^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {3}/
| @@ -1 +1 @@
0 | - /foo /
0 | + /foo {3}/
/foo bar/ error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:5
│
1 │ /foo bar/
│ ^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {2}/
| @@ -1 +1 @@
0 | - /foo bar/
0 | + /foo {2}bar/
/foo bar baz/ error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:5
│
1 │ /foo bar baz/
│ ^^^^^^^^^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {7}/
| @@ -1 +1 @@
0 | - /foo bar baz/
0 | + /foo {3}bar {4}baz/
/foo [ba]r b(a|z)/ error[regex/noMultipleSpacesInRegularExpressionLiterals]: This regular expression contains unclear uses of multiple spaces.
┌─ regex/noMultipleSpacesInRegularExpressionLiterals.js:1:11
│
1 │ /foo [ba]r b(a|z)/
│ ^^
Suggested fix: It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {2}/
| @@ -1 +1 @@
0 | - /foo [ba]r b(a|z)/
0 | + /foo [ba]r {2}b(a|z)/
Valid
/foo {2}bar/ /foo bar baz/ /foo bar baz/ /foo /