Multiple Spaces

Identifier: regex.lint.literal.multipleSpaces (off by default)

When it triggers: Two or more literal spaces in a row are hard to count; ` {n} says how many. A style rule: turn it on with “literal.multipleSpaces”: true under checks.lint.rules. Only spaces written bare are counted: under x or xx, or after (?x), they are not literal, and quoted (\Q \E), escaped or class spaces are not bare. A quantifier on the last space enters the count: the tip for /a +/ is {2,}`.

Example:

// INFO: how many spaces?
preg_match('/a   b/', 'a   b');   // 1

// PREFERRED
preg_match('/a {3}b/', 'a   b');  // 1

Fix: Write the space once with its count.


Try it. Open /a b/ in the playground: the rule is off by default, so the Diagnostics tab shows the findings of the rules that are on.

Edit on GitHub Feedback