{"record":{"id":"02624ae5d4819cbc","repo":"oxc-project/oxc","slug":"unexpected-irregular-whitespace","errorCode":null,"errorMessage":"Unexpected irregular whitespace","messagePattern":"Unexpected irregular whitespace","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_irregular_whitespace.rs","lineNumber":20,"sourceCode":"\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::{\n    identifier::is_irregular_whitespace, line_terminator::is_irregular_line_terminator,\n};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_irregular_whitespace_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected irregular whitespace\")\n        .with_help(\"Try to remove the irregular whitespace\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoIrregularWhitespaceConfig {\n    /// Whether to skip irregular whitespace in string literals.\n    skip_strings: bool,\n    /// Whether to skip irregular whitespace in comments.\n    skip_comments: bool,\n    /// Whether to skip irregular whitespace in regular expression literals.\n    skip_reg_exps: bool,\n    /// Whether to skip irregular whitespace in template literals.\n    skip_templates: bool,\n    /// Whether to skip irregular whitespace in JSX text.\n    #[serde(rename = \"skipJSXText\")]\n    skip_jsx_text: bool,","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_irregular_whitespace.rs#L2-L38","documentation":"Diagnostic from oxlint's eslint/no-irregular-whitespace rule (crates/oxc_linter/src/rules/eslint/no_irregular_whitespace.rs:20). It reports Unicode whitespace/line-terminator characters that are valid in JS strings and comments but illegal or invisible in code positions: NBSP (U+00A0), zero-width space (U+200B), BOM (U+FEFF), line separator (U+2028), and similar. Such characters are visually identical to a normal space, causing confusing 'unexpected token' errors or broken string comparisons.","triggerScenarios":"Copying code from a web page, PDF, or chat message into a .js/.ts file; an editor or IME inserting NBSP inside identifiers, between keywords, or in operator position (e.g. 'const\\u00A0x = 1'); BOM characters embedded mid-file; zero-width characters left by refactoring tools.","commonSituations":"Teams pasting snippets from documentation sites (common source of NBSP); macOS option-space typing NBSP instead of space; files that pass one editor but fail another that renders/strips the characters differently; CI failing on a file that looks clean locally.","solutions":["Replace the irregular whitespace character with a normal space (U+0020) at the reported span; most editors' 'show invisibles' mode highlights it","Run a strip pass over affected files: sed -i 's/\\xC2\\xA0/ /g' (and similar for U+200B/U+FEFF) or use an editor 'strip trailing/zero-width characters' command","Configure the rule's skipStrings/skipComments/skipRegExps/skipTemplates/skipJSON options if the characters are intentional data (e.g. NBSP inside French text strings)"],"exampleFix":"// before (contains U+00A0 between const and x)\nconst\\u00A0x = 1;\n\n// after\nconst x = 1;","handlingStrategy":"validation","validationCode":"// Pre-commit check: fail if a source file contains irregular whitespace in code\nimport { readFileSync } from 'node:fs';\nconst IRREGULAR = /[\\u0085\\u00A0\\u1680\\u180E\\u2000-\\u200F\\u2028\\u2029\\u202F\\u205F\\u3000\\uFEFF]/;\nfor (const file of process.argv.slice(2)) {\n  if (IRREGULAR.test(readFileSync(file, 'utf8'))) {\n    console.error(`irregular whitespace in ${file}`);\n    process.exitCode = 1;\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable 'show invisibles' / render whitespace in your editor","Retype (don't paste) code from PDFs and chat tools, or paste through a plain-text buffer","Add a pre-commit hook that strips or rejects NBSP/zero-width characters","Configure skipStrings/skipComments options where the characters are legitimate data"],"tags":["lint","whitespace","unicode","javascript","copy-paste"],"backgroundTag":"invisible-characters-in-source","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}