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

Latest commit

 

History

History
33 lines (23 loc) · 1.25 KB

prefer-predefined-character-set.md

File metadata and controls

33 lines (23 loc) · 1.25 KB

prefer-predefined-character-set 🔧

Prefer predefined character sets instead of their more verbose form.

configuration in plugin:clean-regex/recommended: "warn"

Source file
Test file

Description

This will replace the verbose character class elements version of of the \d and \w character sets with their character set representation.

Note: This will not remove any character classes. Use the no-unnecessary-character-class rule for that.

allowDigitRange: boolean

This option determines whether a digit range (0-9) is allowed or whether it should be replaced with \d. Note that if the digit range is the whole character class is equivalent to \d, then a digit range will always be replaced with \d. The value defaults to true.

Examples

/[0-9]/      // -> /[\d]/
/[0-9a-z_-]/ // -> /[\w-]/
/[0-9a-f]/   // -> /[\da-f]/ with `allowDigitRange: false`
/[0-9a-f]/   // unchanged with `allowDigitRange: true` (default)