Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Latest commit

 

History

History
151 lines (109 loc) · 9.96 KB

MIGRATION.md

File metadata and controls

151 lines (109 loc) · 9.96 KB

Migration guide

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.

One to one

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:

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.

Other rules

clean-regex/consistent-match-all-characters

Use regexp/match-any instead.

regexp/match-any has slightly different options:

  • mode: "dot" -> allows: ["dotAll"]
  • mode: "char-class" -> allows: ["[^]"] (use the string from the charClass option)
  • mode: "dot-if-dotAll" -> allows: ["[^]", "dotAll"] (use the string from the charClass option)
    (This isn't a perfect replacement but it's close.)

clean-regex/disjoint-alternatives

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.

clean-regex/identity-escape

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.

clean-regex/no-constant-capturing-group

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.

clean-regex/no-unnecessary-group

Use regexp/no-useless-non-capturing-group instead.

Options are migrated as such:

  • allowTop: false -> allowTop: "never"
  • allowTop: true -> allowTop: "always"

clean-regex/optimized-character-class

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.

clean-regex/prefer-predefined-character-set

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"

clean-regex/prefer-predefined-quantifiers

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.

Recommended config

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"
    }
}