no-regex-spaces
C#JavaJavaScript / TypeScriptPHPPythonsuspiciousno fixdefault: offjs/eslint-recommendedjs/biome-recommended
What it does
Section titled “What it does”Reports two or more spaces outside a character class in the constant string given to new Regex(...) and the static methods of Regex.
Why it matters
Section titled “Why it matters”Several spaces in a row are hard to count, and a pattern that has them is easily changed by an editor that collapses white space or by a reader who counts wrongly. The number of spaces is part of what the pattern matches.
To fix, write the number as a count (a {3}b).
Example
Section titled “Example”class A { void f(String s) {... Pattern.compile("a b");... Pattern.compile("a b"); Other.compile("a b");...Configuration
Section titled “Configuration”csharp: lint: rules: no-regex-spaces: warn # off (default), warn, errorjava: lint: rules: no-regex-spaces: warn # off (default), warn, errorjs: lint: rules: no-regex-spaces: warn # off (default), warn, errorphp: lint: rules: no-regex-spaces: warn # off (default), warn, errorpython: lint: rules: no-regex-spaces: warn # off (default), warn, errorEnabled by the presets: js/eslint-recommended, js/biome-recommended.
Suppress one line with sudsy-disable-next-line no-regex-spaces in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-regex-spaces |
full |