irregularWhitespaces
Reports irregular whitespace characters that can cause issues with code parsing and display.
✅ This rule is included in the ts logical presets.
Irregular whitespace characters are Unicode characters that look like regular spaces but may be interpreted differently by tools and parsers.
These include non-breaking spaces (\u00A0), zero-width spaces (\u200B), and various other Unicode space characters.
They are often accidentally introduced through copy-paste from external sources such as word processors, web pages, or PDFs. When present in code, they can cause confusing syntax errors, unexpected behavior in string comparisons, or display issues across different editors.
Examples
Section titled “Examples”// Non-breaking space between variable and equals signconst value = 1;// Zero-width space in identifierconst data = 42;// Irregular line terminatorconst result = 1;// Regular space between variable and equals signconst value = 1;// No invisible characters in identifierconst data = 42;// Standard line breakconst result = 1;Options
Section titled “Options”skipTemplates
Section titled “skipTemplates”When true, irregular whitespace inside template literals is allowed.
Defaults to false.
// With skipTemplates: true, this is allowedconst value = `template with non-breaking space`;skipComments
Section titled “skipComments”When true, irregular whitespace inside comments is allowed.
Defaults to false.
// With skipComments: true, this is allowed// Comment with non-breaking spaceskipRegularExpressions
Section titled “skipRegularExpressions”When true, irregular whitespace inside regular expression literals is allowed.
Defaults to false.
// With skipRegularExpressions: true, this is allowedconst pattern = / /;skipJSXText
Section titled “skipJSXText”When true, irregular whitespace inside JSX text content is allowed.
Defaults to false.
// With skipJSXText: true, this is allowedconst element = <div> </div>;When Not To Use It
Section titled “When Not To Use It”If your codebase intentionally uses irregular whitespace characters for specific purposes, such as matching text that contains non-breaking spaces, you may want to disable this rule or configure the skip options. You might also disable this rule if you have other tools in your workflow that already normalize whitespace characters.
Further Reading
Section titled “Further Reading”- MDN: Whitespace in JavaScript
- Unicode Line Breaking Algorithm
- Wikipedia: Non-breaking space
- Wikipedia: Zero-width space
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noIrregularWhitespace - Deno:
no-irregular-whitespace - ESLint:
no-irregular-whitespace - Oxlint:
eslint/no-irregular-whitespace