Skip to main content

noMultipleSpacesInRegularExpressionLiterals (since v0.7.0)

Disallow unclear usage of multiple space characters in regular expression literals

Examples

Invalid

/   /
warning[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/
warning[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   /
warning[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/
warning[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/
warning[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)/
warning[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 /