{"record":{"id":"386212b6e9d11548","repo":"oxc-project/oxc","slug":"multiple-consecutive-spaces-are-hard-to-count","errorCode":null,"errorMessage":"Multiple consecutive spaces are hard to count.","messagePattern":"Multiple consecutive spaces are hard to count\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs","lineNumber":23,"sourceCode":"};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_regular_expression::{\n    ConstructorParser, Options,\n    ast::{Character, Pattern},\n    visit::{RegExpAstKind, Visit},\n};\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::Rule,\n};\n\nfn no_regex_spaces_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Multiple consecutive spaces are hard to count.\")\n        .with_help(format!(\"Use a quantifier: ` {{{size}}}`\", size = span.size()))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoRegexSpaces;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow 2+ consecutive spaces in regular expressions.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// In a regular expression, it is hard to tell how many spaces are\n    /// intended to be matched. It is better to use only one space and\n    /// then specify how many spaces are expected using a quantifier.\n    ///","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs#L5-L41","documentation":"oxlint's port of ESLint `no-regex-spaces`. A regex containing two or more consecutive literal space characters is flagged because the human eye cannot reliably count the spaces. The help text suggests the fix directly: replace the run with one space plus an explicit quantifier (` {n}`), and the rule provides an autofix that rewrites the run in place.","triggerScenarios":"Any regex literal or `new RegExp(\"...\")` source containing 2+ consecutive spaces: `/foo  bar/`, `/a   b/`, `new RegExp(\"x  y\")`. The diagnostic span size equals the length of the space run, which feeds the suggested ` {size}` quantifier.","commonSituations":"Patterns for parsing fixed-width log columns or ASCII tables; copy-pasting a pattern whose `{2}` quantifier was lost; editors that trim trailing whitespace silently changing the pattern's meaning.","solutions":["Replace the run of N spaces with a single space and a quantifier: `/ {3}/` instead of `/   /`.","Run `oxlint --fix` to apply the rule's autofix automatically.","Use `\\s{3}` or `[ ]{3}` if your toolchain collapses literal space runs."],"exampleFix":"// before\nconst re = /foo   bar/;\n\n// after\nconst re = /foo {3}bar/;","handlingStrategy":"validation","validationCode":"// Flag regex sources with 2+ consecutive spaces before they reach review\nfunction hasUnquantifiedSpaces(reSource) {\n  return / {2,}(?!\\})/.test(reSource);\n}\nmodule.exports = { hasUnquantifiedSpaces };","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write regexes with explicit quantifiers (` {3}`, `\\s{2,}`) from the start.","Run `oxlint --fix` in CI — this rule's fix is mechanical and safe.","Keep regexes in constants with unit tests so whitespace edits surface immediately."],"tags":["lint","eslint","no-regex-spaces","regex","autofix"],"backgroundTag":"regex-quantifier-syntax","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}