Lint Rules

noMultipleSpacesInRegularExpressionLiterals (since v0.7.0)

This rule is recommended by Rome.

Disallow unclear usage of multiple space characters in regular expression literals

Examples

Invalid

/   /
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:2 lint/correctness/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/
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:2 lint/correctness/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   /
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:5 lint/correctness/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/
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:5 lint/correctness/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/
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:5 lint/correctness/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)/
correctness/noMultipleSpacesInRegularExpressionLiterals.js:1:11 lint/correctness/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 /