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.

76// Non-breaking space between variable and equals siAEconsB0valAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><1;d>76// Zero-width space in identifiAEconsB0daAE <= sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><2;d>76// Irregular line terminatAEconsB0resuAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><1;d>
6376// Regular space between variable and equals 44AEco61B0v44A0<9821 spans="tyle--0:#D6DEEB;--1:#40">3<= 1><;di vdivclass="Nameexpressive-">6376// No invisible characters in identi44AEco61B044A09<8242 spans="tyle--0:#D6DEEB;--1:#40">3< 42><;di vdivclass="Nameexpressive-">6376// Standard line b44AEco61B0re44A0<9821 spans="tyle--0:#D6DEEB;--1:#40">3<= 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.