Skip to content

Latest commit

 

History

History
83 lines (54 loc) · 2.01 KB

no-useless-character-class.md

File metadata and controls

83 lines (54 loc) · 2.01 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-useless-character-class
disallow character class with one character
v0.3.0

regexp/no-useless-character-class

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

🔧 This rule is automatically fixable by the --fix CLI option.

disallow character class with one character

📖 Rule Details

This rule reports character classes that defines only one character.

Character classes that define only one character have the same effect even if you remove the brackets.

/* eslint regexp/no-useless-character-class: "error" */

/* ✓ GOOD */
var foo = /abc/;

/* ✗ BAD */
var foo = /a[b]c/;

🔧 Options

{
  "regexp/no-useless-character-class": ["error", {
    "ignores": ["="]
  }]
}
  • "ignores" ... An array of characters and character classes to ignores. Default ["="].

The default value is "=" to prevent conflicts with the no-div-regex rule. Note that if you do not specify "=", there may be conflicts with the no-div-regex rule.

"ignores": ["a"]

/* eslint regexp/no-useless-character-class: ["error", { "ignores": ["a"] }] */

/* ✓ GOOD */
var foo = /[a]bc/;

/* ✗ BAD */
var foo = /a[b]c/;

👫 Related rules

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.3.0

🔍 Implementation