Skip to content

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.

// Non-breaking space between variable and equals sign
const value = 1;
// Zero-width space in identifier
const data = 42;
// Irregular line terminator
const result = 1;

When true, irregular whitespace inside template literals is allowed. Defaults to false.

// With skipTemplates: true, this is allowed
const value = `template with non-breaking space`;

When true, irregular whitespace inside comments is allowed. Defaults to false.

// With skipComments: true, this is allowed
// Comment with non-breaking space

When true, irregular whitespace inside regular expression literals is allowed. Defaults to false.

// With skipRegularExpressions: true, this is allowed
const pattern = / /;

When true, irregular whitespace inside JSX text content is allowed. Defaults to false.

// With skipJSXText: true, this is allowed
const element = <div> </div>;

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.