Skip to content

regexp/prefer-d

💼 This rule is enabled in the following configs: 🟢 flat/recommended, 🔵 recommended.

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

enforce using \d

📖 Rule Details

This rule is aimed at using \d instead of [0-9] in regular expressions.

Now loading...

🔧 Options

json5
{
  "regexp/prefer-d": [
    "error",
    {
        "insideCharacterClass": "d"
    }
  ]
}

insideCharacterClass

This option control how character class element equivalent to \d will be treated.

Note: This option does not affect character classes equivalent to \d. E.g. [\d], [0-9], and [0123456789] are unaffected. It also does not affect expression non-nested operands equivalent to \d. E.g. [\d&&x], and [\d--x] are unaffected.

  • insideCharacterClass: "d"

    Character class element equivalent to \d will be reported and replaced with \d.

    Now loading...
  • insideCharacterClass: "range"

    Character class element equivalent to \d will be reported and replaced with the range 0-9.

    Now loading...
  • insideCharacterClass: "ignore" (default)

    Character class element will not be reported.

    Now loading...

🚀 Version

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

🔍 Implementation