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