no-regex-spaces

Disallow several spaces in a row in a regular expression

warn by defaultfixable

In /error code/ you can't tell at a glance whether there are two, three or four spaces. {3} spells it out.

The rule checks regular expression literals and strings passed to RegExp. Spaces inside a character class such as [ ] aren't reported.

--fix replaces the spaces with one space and a count.

This rule is on by default.

Configure#

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"no-regex-spaces" = "off" # or "error"

Examples#

example.js2 problems
const line = /error   code/;
const header = new RegExp("name  value");
example.jsNo problems
const line = /error {3}code/;
const header = new RegExp("name {2}value");
const anyGap = /name +value/;