Skip to content

Latest commit

 

History

History
78 lines (52 loc) · 2.45 KB

no-misleading-unicode-character.md

File metadata and controls

78 lines (52 loc) · 2.45 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-misleading-unicode-character
disallow multi-code-point characters in character classes and quantifiers
v1.2.0

regexp/no-misleading-unicode-character

💼 This rule is enabled in the ✅ plugin:regexp/recommended config.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

disallow multi-code-point characters in character classes and quantifiers

📖 Rule Details

This rule reports misleading Unicode characters.

Some Unicode characters like '❇️', '🏳️‍🌈', and '👨‍👩‍👦' consist of multiple code points. This causes problems in character classes and around quantifiers. E.g.

> /^[🏳🌈]$/.test("🏳️‍🌈")
false
> /^👨👩👦{2,4}$/.test("👨‍👩‍👦👨‍👩‍👦")
false

This rule is inspired by the no-misleading-character-class rule.

/* eslint regexp/no-misleading-unicode-character: "error" */

/* ✓ GOOD */
var foo = /👍+/u;
var foo = /👨👩👦/;

/* ✗ BAD */
var foo = /👍+/;
var foo = /[🏳🌈👨👩👦]/;

🔧 Options

{
  "regexp/no-unused-capturing-group": ["error", {
    "fixable": true
  }]
}
  • fixable: true | false

    This option controls whether the rule is fixable. Defaults to false.

    This rule is not fixable by default. Misleading Unicode characters can typically be fixed automatically by assuming that users want to treat one displayed character as one regex character. However, this assumption is not useful in all languages, so this rule provides suggestions instead of fixes by default.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.2.0

🔍 Implementation