Since eslint-plugin-clean-regex
has been deprecated, users are advised to migrate to eslint-plugin-regexp
for continued support and improvements.
The following will outline how each rule configuration is to migrated to eslint-plugin-regexp
.
Some rules were more or less copied one-to-one, so migrating these rules is as simple as changing clean-regex/<rule X>
to regexp/<rule Y>
. All of the following rules can migrated using this simple change:
clean-regex/confusing-quantifier
->regexp/confusing-quantifier
clean-regex/no-empty-alternative
->regexp/no-empty-alternative
clean-regex/no-empty-backreference
->regexp/no-useless-backreference
clean-regex/no-empty-lookaround
->regexp/no-empty-lookarounds-assertion
clean-regex/no-lazy-ends
->regexp/no-lazy-ends
clean-regex/no-obscure-range
->regexp/no-obscure-range
clean-regex/no-octal-escape
->regexp/no-octal
clean-regex/no-optional-assertion
->regexp/no-optional-assertion
clean-regex/no-potentially-empty-backreference
->regexp/no-potentially-useless-backreference
clean-regex/no-trivially-nested-lookaround
->regexp/no-trivially-nested-assertion
clean-regex/no-trivially-nested-quantifier
->regexp/no-trivially-nested-quantifier
clean-regex/no-unnecessary-assertions
->regexp/no-useless-assertions
clean-regex/no-unnecessary-character-class
->regexp/no-useless-character-class
clean-regex/no-unnecessary-flag
->regexp/no-useless-flag
clean-regex/no-unnecessary-lazy
->regexp/no-useless-lazy
clean-regex/no-unnecessary-quantifier
->regexp/no-useless-quantifier
clean-regex/no-zero-quantifier
->regexp/no-zero-quantifier
clean-regex/optimal-concatenation-quantifier
->regexp/optimal-quantifier-concatenation
clean-regex/optimal-lookaround-quantifier
->regexp/optimal-lookaround-quantifier
clean-regex/prefer-character-class
->regexp/prefer-character-class
clean-regex/prefer-predefined-assertion
->regexp/prefer-predefined-assertion
clean-regex/simple-constant-quantifier
->regexp/no-useless-two-nums-quantifier
clean-regex/sort-flags
->regexp/sort-flags
Note: The corresponding eslint-plugin-regexp
rule is guaranteed to have all of the functionality of the eslint-plugin-clean-regex
rule. However, the eslint-plugin-regexp
rules might also report more.
Use regexp/match-any
instead.
regexp/match-any
has slightly different options:
mode: "dot"
->allows: ["dotAll"]
mode: "char-class"
->allows: ["[^]"]
(use the string from thecharClass
option)mode: "dot-if-dotAll"
->allows: ["[^]", "dotAll"]
(use the string from thecharClass
option)
(This isn't a perfect replacement but it's close.)
Use regexp/no-dupe-disjunctions
instead.
regexp/no-dupe-disjunctions
can report a lot more than clean-regex/disjoint-alternatives
but won't by default to filter out noise. Use report: "all"
make it report everything that clean-regex/disjoint-alternatives
reports.
Use regexp/strict
instead.
regexp/strict
does a lot more than just identity escapes and is less configurable. I recommend using regexp/strict
because it implements a configuration for identity escapes that is compatible with Unicode regexes and future additions to JavaScript regexes.
Use regexp/no-empty-capturing-group
instead.
regexp/no-empty-capturing-group
does exactly what clean-regex/no-constant-capturing-group
does with ignoreNonEmpty: true
(default). Reporting non-empty constant capturing groups isn't as useful, so it hasn't been added to eslint-plugin-regexp
.
Use regexp/no-useless-non-capturing-group
instead.
Options are migrated as such:
allowTop: false
->allowTop: "never"
allowTop: true
->allowTop: "always"
Use regexp/no-dupe-characters-character-class
, regexp/no-useless-range
, and regexp/prefer-range
instead.
All three rules together perform the function of clean-regex/optimized-character-class
.
Use regexp/prefer-d
and regexp/prefer-w
instead.
The allowDigitRange
translates to regexp/prefer-d
's insideCharacterClass
option as follows:
allowDigitRange: false
->insideCharacterClass: "d"
(default)allowDigitRange: true
(default) ->insideCharacterClass: "ignore"
Use regexp/prefer-plus-quantifier
, regexp/prefer-question-quantifier
, and regexp/prefer-star-quantifier
instead.
All three rules together perform the function of clean-regex/prefer-predefined-quantifiers
.
eslint-plugin-regexp
's recommended config is a lot stricter and includes a lot more rules than eslint-plugin-clean-regex
's recommended config. A configuration of eslint-plugin-regexp
's rules that is (almost) equivalent to eslint-plugin-clean-regex
's recommended config can be found here:
{
"plugins": [
"regexp"
],
"rules": {
"regexp/confusing-quantifier": "warn",
"regexp/disjoint-alternatives": ["warn", { "report": "all" }],
"regexp/match-any": "warn",
"regexp/no-dupe-characters-character-class": "warn",
"regexp/no-empty-alternative": "warn",
"regexp/no-empty-capturing-group": "warn",
"regexp/no-empty-lookarounds-assertion": "error",
"regexp/no-lazy-ends": "warn",
"regexp/no-obscure-range": "error",
"regexp/no-optional-assertion": "error",
"regexp/no-potentially-useless-backreference": "warn",
"regexp/no-trivially-nested-assertion": "warn",
"regexp/no-trivially-nested-quantifier": "warn",
"regexp/no-unnecessary-group": "warn",
"regexp/no-useless-assertions": "error",
"regexp/no-useless-backreference": "error",
"regexp/no-useless-character-class": "warn",
"regexp/no-useless-flag": "warn",
"regexp/no-useless-lazy": "warn",
"regexp/no-useless-quantifier": "warn",
"regexp/no-useless-range": "warn",
"regexp/no-useless-two-nums-quantifier": "warn",
"regexp/no-zero-quantifier": "error",
"regexp/optimal-lookaround-quantifier": "warn",
"regexp/optimal-quantifier-concatenation": "warn",
"regexp/prefer-character-class": "warn",
"regexp/prefer-plus-quantifier": "warn",
"regexp/prefer-predefined-assertion": "warn",
"regexp/prefer-question-quantifier": "warn",
"regexp/prefer-range": "warn",
"regexp/prefer-star-quantifier": "warn",
"regexp/regexp/prefer-d": "warn",
"regexp/regexp/prefer-w": "warn",
"regexp/sort-flags": "warn",
"regexp/strict": "error"
}
}