Skip to content

regexp/sort-character-class-elements

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

enforces elements order in character class

📖 Rule Details

This rule checks elements of character classes are sorted.

Now loading...

🔧 Options

json5
{
  "regexp/sort-character-class-elements": ["error", {
    "order": [
      "\\s", // \s or \S
      "\\w", // \w or \W
      "\\d", // \d or \D
      "\\p", // \p{...} or \P{...}
      "*", // Others (A character or range of characters or an element you did not specify.)
      "\\q", // \q{...}
      "[]", // Nesting character class, or character class expression
    ]
  }]
}
  • "order" ... An array of your preferred order. The default is ["\\s", "\\w", "\\d", "\\p", "*", "\\q", "[]"].

🚀 Version

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

🔍 Implementation