Gathering detailed insights and metrics for eslint-plugin-clean-regex
Gathering detailed insights and metrics for eslint-plugin-clean-regex
Gathering detailed insights and metrics for eslint-plugin-clean-regex
Gathering detailed insights and metrics for eslint-plugin-clean-regex
An ESLint plugin for writing better regular expressions.
npm install eslint-plugin-clean-regex
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (97.74%)
JavaScript (2.26%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
270 Stars
247 Commits
2 Forks
6 Watchers
2 Branches
2 Contributors
Updated on Jun 12, 2025
Latest Version
0.5.2
Package Id
eslint-plugin-clean-regex@0.5.2
Size
36.09 kB
NPM Version
6.14.10
Node Version
14.15.4
Published on
Oct 11, 2021
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
An ESLint plugin for writing better regular expressions.
This project is deprecated.
Please use eslint-plugin-regexp
instead.
eslint-plugin-clean-regex
and eslint-plugin-regexp
have joined forces. We decided to work together on one ESLint plugin for JavaScript regexes. Since maintaining two plugins with similar rules takes too much work, I decided to stop working on eslint-plugin-clean-regex
.
As of right now, eslint-plugin-regexp
supports all rules of eslint-plugin-clean-regex
along improvements to those rules and with many more useful rules.
See the migration guide.
This is an ESLint plugin to lint JavaScript regular expressions. Its goal is to help both beginners and experts to write better regular expressions by pointing out errors and suggesting improvements.
The plugin offers rules for possible errors, best practices, and coding style in regular expressions.
Right now, this project is still young (and many rules are opinionated). Feel free to open an issue if you think rules are too strict/lax/inflexible. Suggestions and feature requests are welcome as well!
You'll need to install ESLint and eslint-plugin-clean-regex
:
$ npm i eslint eslint-plugin-clean-regex --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-clean-regex
globally.
Add clean-regex
to the plugins section of your .eslintrc
configuration file (you can omit the eslint-plugin-
prefix) and configure the rules you want:
1{ 2 "plugins": [ 3 "clean-regex" 4 ], 5 "rules": { 6 "clean-regex/rule-name": 2 7 } 8}
You can also use the recommended config:
1{ 2 "plugins": [ 3 "clean-regex" 4 ], 5 "extends": [ 6 "plugin:clean-regex/recommended" 7 ] 8}
The setting of every rule in the recommended config can be found in the table below.
Some highlights of the working and working-together of rules in the recommended config.
Before:
1- /[0-9]/i 2- /[^\s]/ 3- /[a-fA-F0-9]/i 4- /[a-zA-Z0-9_-]/ 5- /[a-z\d\w]/ 6- /[\S\d]/ 7- /[\w\p{ASCII}]/u
After:
1- /\d/ 2- /\S/ 3- /[a-f0-9]/i 4- /[\w-]/ 5- /\w/ 6- /\S/ 7- /\p{ASCII}/u
Before:
1- /(?:\w|\d)+/ 2- /(?:a|(b)|c|(?:d)|(?:ee)){0,}/ 3- /(?<!\w)a+(?=$)/mi 4- /[\s\S]#[\0-\uFFFF]/ysi 5- /\d*\w(?:[a-z_]|\d+)*/im
After:
1- /\w+/ 2- /(?:[acd]|(b)|ee)*/ 3- /\ba+$/im 4- /.#./sy 5- /\w+/
1- /\1(a)/ // `\1` won't work 2- /a+b*?/ // `b*?` can be removed 3- /(?:\b)?a/ // `(?:\b)?` can be removed 4- /[a-z]+|Foo/i // `Foo` can be removed 5- /(?=a?)\w\Ba/ // `(?=a?)` and `\B` always accept and can be removed 6- /[*/+-^&|]/ // `+-^` will match everything from \x2B to \x5E including all character A to Z
Fixable rules are denoted with a :wrench:.
Rule | Description | |
---|---|---|
confusing-quantifier | Warn about confusing quantifiers. | |
disjoint-alternatives | Disallow different alternatives that can match the same words. | |
no-empty-alternative | Disallow alternatives without elements. | |
no-empty-backreference | Disallow backreferences that will always be replaced with the empty string. | |
no-empty-lookaround | Disallow lookarounds that can match the empty string. | |
no-lazy-ends | Disallow lazy quantifiers at the end of an expression. | |
no-obscure-range | Disallow obscure ranges in character classes. | |
no-octal-escape | Disallow octal escapes outside of character classes. | |
no-optional-assertion | Disallow optional assertions. | |
no-potentially-empty-backreference | Disallow backreferences that reference a group that might not be matched. | |
no-unnecessary-assertions | Disallow assertions that are known to always accept (or reject). | |
:wrench: | no-zero-quantifier | Disallow quantifiers with a maximum of 0. |
optimal-lookaround-quantifier | Disallows the alternatives of lookarounds that end with a non-constant quantifier. |
Rule | Description | |
---|---|---|
:wrench: | consistent-match-all-characters | Use one character class consistently whenever all characters have to be matched. |
:wrench: | identity-escape | How to handle identity escapes. |
no-constant-capturing-group | Disallow capturing groups that can match only one word. | |
:wrench: | no-trivially-nested-lookaround | Disallow lookarounds that only contain another assertion. |
:wrench: | no-trivially-nested-quantifier | Disallow nested quantifiers that can be rewritten as one quantifier. |
:wrench: | no-unnecessary-character-class | Disallow unnecessary character classes. |
:wrench: | no-unnecessary-flag | Disallow unnecessary regex flags. |
:wrench: | no-unnecessary-group | Disallow unnecessary non-capturing groups. |
:wrench: | no-unnecessary-lazy | Disallow unnecessarily lazy quantifiers. |
:wrench: | no-unnecessary-quantifier | Disallow unnecessary quantifiers. |
:wrench: | optimal-concatenation-quantifier | Use optimal quantifiers for concatenated quantified characters. |
:wrench: | optimized-character-class | Disallows unnecessary elements in character classes. |
:wrench: | prefer-character-class | Prefer character classes wherever possible instead of alternations. |
:wrench: | prefer-predefined-assertion | Prefer predefined assertions over equivalent lookarounds. |
:wrench: | prefer-predefined-character-set | Prefer predefined character sets instead of their more verbose form. |
:wrench: | prefer-predefined-quantifiers | Prefer predefined quantifiers (+*?) instead of their more verbose form. |
:wrench: | simple-constant-quantifier | Prefer simple constant quantifiers over the range form. |
:wrench: | sort-flags | Requires the regex flags to be sorted. |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
project is archived
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More