pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/sort-character-class-elements |
enforces elements order in character class |
v0.12.0 |
🔧 This rule is automatically fixable by the --fix
CLI option.
enforces elements order in character class
This rule checks elements of character classes are sorted.
/* eslint regexp/sort-character-class-elements: "error" */
/* ✓ GOOD */
var foo = /[abcdef]/
var foo = /[ab-f]/
/* ✗ BAD */
var foo = /[bcdefa]/
var foo = /[b-fa]/
{
"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.)
]
}]
}
"order"
... An array of your preferred order. The default is["\\s", "\\w", "\\d", "\\p", "*",]
.
This rule was introduced in eslint-plugin-regexp v0.12.0