All Projects → RunDevelopment → eslint-plugin-clean-regex

RunDevelopment / eslint-plugin-clean-regex

Licence: MIT License
An ESLint plugin for writing better regular expressions.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to eslint-plugin-clean-regex

retrie
Efficient Trie-based regex unions for blacklist/whitelist filtering and one-pass mapping-based string replacing
Stars: ✭ 35 (-87.5%)
Mutual labels:  regexp
eslint-plugin-qunit
ESLint plugin containing rules useful for QUnit tests.
Stars: ✭ 26 (-90.71%)
Mutual labels:  eslint-plugin
eslint-plugin-es5
ESLint plugin for ES5 users.
Stars: ✭ 52 (-81.43%)
Mutual labels:  eslint-plugin
eslint-plugin-nestjs
POC. ESLint rules for nestjs framework
Stars: ✭ 30 (-89.29%)
Mutual labels:  eslint-plugin
String.prototype.matchAll
Spec-compliant polyfill for String.prototype.matchAll, in ES2020
Stars: ✭ 14 (-95%)
Mutual labels:  regexp
eslint-plugin-sql
SQL linting rules for ESLint.
Stars: ✭ 56 (-80%)
Mutual labels:  eslint-plugin
stringx
Drop-in replacements for base R string functions powered by stringi
Stars: ✭ 14 (-95%)
Mutual labels:  regexp
eslint-plugin-ember-best-practices
Static analysis tools for enforcing best practices in Ember
Stars: ✭ 77 (-72.5%)
Mutual labels:  eslint-plugin
eslint-plugin
😎 基于 @lint-md,提供 eslint-plugin,让 lint-md 玩家在 IDE 中得到愉悦的文档编写体验。
Stars: ✭ 22 (-92.14%)
Mutual labels:  eslint-plugin
rexreplace
Smooth find & replace CLI as it should be: simple file selection with globs, flexible patterns with regex and dynamic replacements from js code.
Stars: ✭ 19 (-93.21%)
Mutual labels:  regexp
micell
A collection of functions for front-end development
Stars: ✭ 16 (-94.29%)
Mutual labels:  regexp
eslint-plugin-expect-type
ESLint plugin with $ExpectType, $ExpectError, and $ExpectTypeSnapshot type assertions
Stars: ✭ 27 (-90.36%)
Mutual labels:  eslint-plugin
mention-hashtag
Extract mentions (@mention) or hashtags (#hashtag) from any text
Stars: ✭ 16 (-94.29%)
Mutual labels:  regexp
eslint-plugin-decorator-position
ESLint plugin for enforcing decorator position
Stars: ✭ 32 (-88.57%)
Mutual labels:  eslint-plugin
eslint-config-get-off-my-lawn
A highly opinionated, sharable config of ESLint rules to produce beautiful, readable JavaScript.
Stars: ✭ 44 (-84.29%)
Mutual labels:  eslint-plugin
eslint-plugin-strict-vue
Vue eslint plugin with rules to make you code stricter: enforce jsdoc, restrict rootGetters, rootState and more.
Stars: ✭ 28 (-90%)
Mutual labels:  eslint-plugin
ElementFinder
Fetch data from HTML and XML via xpath/css and prepare it with regexp
Stars: ✭ 29 (-89.64%)
Mutual labels:  regexp
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.
Stars: ✭ 19 (-93.21%)
Mutual labels:  eslint-plugin
subst
Search and des... argh... replace in many files at once. Use regexp and power of Python to replace what you want.
Stars: ✭ 20 (-92.86%)
Mutual labels:  regexp
eslint-plugin
Enforcing best practices for Effector
Stars: ✭ 69 (-75.36%)
Mutual labels:  eslint-plugin

eslint-plugin-clean-regex

Actions Status npm

An ESLint plugin for writing better regular expressions.

⚠️ Deprecated ⚠️

This project is deprecated.

Please use eslint-plugin-regexp instead.

What happened?

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.

Migration

See the migration guide.

About

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!

Getting started

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:

{
    "plugins": [
        "clean-regex"
    ],
    "rules": {
        "clean-regex/rule-name": 2
    }
}

You can also use the recommended config:

{
    "plugins": [
        "clean-regex"
    ],
    "extends": [
        "plugin:clean-regex/recommended"
    ]
}

The setting of every rule in the recommended config can be found in the table below.

Highlights

Some highlights of the working and working-together of rules in the recommended config.

Optimize character classes

Before:

- /[0-9]/i
- /[^\s]/
- /[a-fA-F0-9]/i
- /[a-zA-Z0-9_-]/
- /[a-z\d\w]/
- /[\S\d]/
- /[\w\p{ASCII}]/u

After:

- /\d/
- /\S/
- /[a-f0-9]/i
- /[\w-]/
- /\w/
- /\S/
- /\p{ASCII}/u

Simplify patterns

Before:

- /(?:\w|\d)+/
- /(?:a|(b)|c|(?:d)|(?:ee)){0,}/
- /(?<!\w)a+(?=$)/mi
- /[\s\S]#[\0-\uFFFF]/ysi
- /\d*\w(?:[a-z_]|\d+)*/im

After:

- /\w+/
- /(?:[acd]|(b)|ee)*/
- /\ba+$/im
- /.#./sy
- /\w+/

Detect non-functional code and potential errors

- /\1(a)/        // `\1` won't work
- /a+b*?/        // `b*?` can be removed
- /(?:\b)?a/     // `(?:\b)?` can be removed
- /[a-z]+|Foo/i  // `Foo` can be removed
- /(?=a?)\w\Ba/  // `(?=a?)` and `\B` always accept and can be removed
- /[*/+-^&|]/    // `+-^` will match everything from \x2B to \x5E including all character A to Z

Supported Rules

Fixable rules are denoted with a 🔧.

Problems

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).
🔧 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.

Suggestions

Rule Description
🔧 consistent-match-all-characters Use one character class consistently whenever all characters have to be matched.
🔧 identity-escape How to handle identity escapes.
no-constant-capturing-group Disallow capturing groups that can match only one word.
🔧 no-trivially-nested-lookaround Disallow lookarounds that only contain another assertion.
🔧 no-trivially-nested-quantifier Disallow nested quantifiers that can be rewritten as one quantifier.
🔧 no-unnecessary-character-class Disallow unnecessary character classes.
🔧 no-unnecessary-flag Disallow unnecessary regex flags.
🔧 no-unnecessary-group Disallow unnecessary non-capturing groups.
🔧 no-unnecessary-lazy Disallow unnecessarily lazy quantifiers.
🔧 no-unnecessary-quantifier Disallow unnecessary quantifiers.
🔧 optimal-concatenation-quantifier Use optimal quantifiers for concatenated quantified characters.
🔧 optimized-character-class Disallows unnecessary elements in character classes.
🔧 prefer-character-class Prefer character classes wherever possible instead of alternations.
🔧 prefer-predefined-assertion Prefer predefined assertions over equivalent lookarounds.
🔧 prefer-predefined-character-set Prefer predefined character sets instead of their more verbose form.
🔧 prefer-predefined-quantifiers Prefer predefined quantifiers (+*?) instead of their more verbose form.
🔧 simple-constant-quantifier Prefer simple constant quantifiers over the range form.
🔧 sort-flags Requires the regex flags to be sorted.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].