Skip to content

regexInvisibleCharacters

Reports invisible characters in regex patterns that should use escape sequences instead.

✅ This rule is included in the ts logical and logicalStrict presets.

Invisible characters like tabs, non-breaking spaces, zero-width spaces, and other whitespace characters are difficult to distinguish visually. When these characters appear literally in regex patterns, they can lead to confusion and hard-to-debug issues. Using explicit escape sequences makes the intent clear and the code more maintainable.

Regular spaces (U+0020) are allowed since they are commonly visible in most editors and fonts.

// Tab character embedded in regex (invisible)
const pattern = / /;
// Non-breaking space embedded in regex
const pattern = / /;
// Zero-width space embedded in regex
const pattern = //;

This rule is not configurable.

If you have tooling that renders invisible characters distinctively, or if your codebase intentionally uses literal invisible characters in regex patterns for specific matching requirements, you might prefer to disable this rule. Some specialized text processing may require literal invisible character matching.

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