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

Latest commit

 

History

History
39 lines (29 loc) · 1.05 KB

no-obscure-range.md

File metadata and controls

39 lines (29 loc) · 1.05 KB

no-obscure-range

Disallow obscure ranges in character classes.

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

Source file
Test file

Description

The range operator (the - inside character classes) can easily be misused (most unintentionally) to construct non-obvious character class. This rule will disallow all but obvious uses of the range operator.

Examples

Examples of valid code for this rule:

/[a-z]/
/[J-O]/
/[1-9]/
/[\x00-\x40]/
/[\0-\uFFFF]/
/[\0-\u{10FFFF}]/u
/[\1-\5]/
/[\cA-\cZ]/

Examples of invalid code for this rule:

/[A-\x43]/   // what's \x43? Bring me my ASCII table!
/[\41-\x45]/ // the minimum isn't hexadecimal
/[*/+-^&|]/  // because of +-^, it also matches all characters A-Z (among others)