• Stars
    star
    223
  • Rank 178,458 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ESLint plugin for finding regex mistakes and style guide violations.

Introduction

eslint-plugin-regexp is ESLint plugin for finding RegExp mistakes and RegExp style guide violations.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status Coverage Status

๐Ÿ“› Features

This ESLint plugin provides linting rules relate to better ways to help you avoid problems when using RegExp.

  • Find the wrong usage of regular expressions, and their hints.
  • Enforces a consistent style of regular expressions.
  • Find hints for writing optimized regular expressions.
  • 80 plugin rules for regular expression syntax and features.

You can check on the Online DEMO.

๐Ÿ“– Documentation

See documents.

๐Ÿ’ฟ Installation

npm install --save-dev eslint eslint-plugin-regexp

Requirements

  • ESLint v8.44.0 and above
  • Node.js v18.x, v20.x and above

๐Ÿ“– Usage

Add regexp to the plugins section of your .eslintrc configuration file (you can omit the eslint-plugin- prefix) and either use one of the two configurations available (recommended or all) or configure the rules you want:

The plugin:regexp/recommended config enables a subset of the rules that should be most useful to most users. See lib/configs/recommended.ts for more details.

// .eslintrc.js
module.exports = {
    "plugins": [
        "regexp"
    ],
    "extends": [
         // add more generic rulesets here, such as:
         // 'eslint:recommended',
        "plugin:regexp/recommended"
    ]
}

Advanced Configuration

Override/add specific rules configurations. See also: http://eslint.org/docs/user-guide/configuring.

// .eslintrc.js
module.exports = {
    "plugins": [
        "regexp"
    ],
    "rules": {
        // Override/add rules settings here, such as:
        "regexp/rule-name": "error"
    }
}

Using "plugin:regexp/all"

The plugin:regexp/all config enables all rules. It's meant for testing, not for production use because it changes with every minor and major version of the plugin. Use it at your own risk. See lib/configs/all.ts for more details.

โœ… Rules

๐Ÿ’ผ Configurations enabled in.
โš ๏ธ Configurations set to warn in.
โœ… Set in the plugin:regexp/recommended configuration.
๐Ÿ”ง Automatically fixable by the --fix CLI option.
๐Ÿ’ก Manually fixable by editor suggestions.

Possible Errors

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿ”ง ๐Ÿ’ก
no-contradiction-with-assertion disallow elements that contradict assertions โœ… ๐Ÿ’ก
no-control-character disallow control characters ๐Ÿ’ก
no-dupe-disjunctions disallow duplicate disjunctions โœ… ๐Ÿ’ก
no-empty-alternative disallow alternatives without elements โœ… ๐Ÿ’ก
no-empty-capturing-group disallow capturing group that captures empty. โœ…
no-empty-character-class disallow character classes that match no characters โœ…
no-empty-group disallow empty group โœ…
no-empty-lookarounds-assertion disallow empty lookahead assertion or empty lookbehind assertion โœ…
no-escape-backspace disallow escape backspace ([\b]) โœ… ๐Ÿ’ก
no-invalid-regexp disallow invalid regular expression strings in RegExp constructors โœ…
no-lazy-ends disallow lazy quantifiers at the end of an expression โœ… ๐Ÿ’ก
no-misleading-capturing-group disallow capturing groups that do not behave as one would expect โœ… ๐Ÿ’ก
no-misleading-unicode-character disallow multi-code-point characters in character classes and quantifiers โœ… ๐Ÿ”ง ๐Ÿ’ก
no-missing-g-flag disallow missing g flag in patterns used in String#matchAll and String#replaceAll โœ… ๐Ÿ”ง
no-optional-assertion disallow optional assertions โœ…
no-potentially-useless-backreference disallow backreferences that reference a group that might not be matched โœ…
no-super-linear-backtracking disallow exponential and polynomial backtracking โœ… ๐Ÿ”ง
no-super-linear-move disallow quantifiers that cause quadratic moves
no-useless-assertions disallow assertions that are known to always accept (or reject) โœ… ๐Ÿ’ก
no-useless-backreference disallow useless backreferences in regular expressions โœ…
no-useless-dollar-replacements disallow useless $ replacements in replacement string โœ…
strict disallow not strictly valid regular expressions โœ… ๐Ÿ”ง ๐Ÿ’ก

Best Practices

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿ”ง ๐Ÿ’ก
confusing-quantifier disallow confusing quantifiers โœ…
control-character-escape enforce consistent escaping of control characters โœ… ๐Ÿ”ง
negation enforce use of escapes on negation โœ… ๐Ÿ”ง
no-dupe-characters-character-class disallow duplicate characters in the RegExp character class โœ… ๐Ÿ”ง
no-empty-string-literal disallow empty string literals in character classes โœ…
no-extra-lookaround-assertions disallow unnecessary nested lookaround assertions โœ… ๐Ÿ”ง
no-invisible-character disallow invisible raw character โœ… ๐Ÿ”ง
no-legacy-features disallow legacy RegExp features โœ…
no-non-standard-flag disallow non-standard flags โœ…
no-obscure-range disallow obscure character ranges โœ…
no-octal disallow octal escape sequence ๐Ÿ’ก
no-standalone-backslash disallow standalone backslashes (\)
no-trivially-nested-assertion disallow trivially nested assertions โœ… ๐Ÿ”ง
no-trivially-nested-quantifier disallow nested quantifiers that can be rewritten as one quantifier โœ… ๐Ÿ”ง
no-unused-capturing-group disallow unused capturing group โœ… ๐Ÿ”ง ๐Ÿ’ก
no-useless-character-class disallow character class with one character โœ… ๐Ÿ”ง
no-useless-flag disallow unnecessary regex flags โœ… ๐Ÿ”ง
no-useless-lazy disallow unnecessarily non-greedy quantifiers โœ… ๐Ÿ”ง
no-useless-quantifier disallow quantifiers that can be removed โœ… ๐Ÿ”ง ๐Ÿ’ก
no-useless-range disallow unnecessary character ranges โœ… ๐Ÿ”ง
no-useless-set-operand disallow unnecessary elements in expression character classes โœ… ๐Ÿ”ง
no-useless-string-literal disallow string disjunction of single characters in \q{...} โœ… ๐Ÿ”ง
no-useless-two-nums-quantifier disallow unnecessary {n,m} quantifier โœ… ๐Ÿ”ง
no-zero-quantifier disallow quantifiers with a maximum of zero โœ… ๐Ÿ’ก
optimal-lookaround-quantifier disallow the alternatives of lookarounds that end with a non-constant quantifier โœ… ๐Ÿ’ก
optimal-quantifier-concatenation require optimal quantifiers for concatenated quantifiers โœ… ๐Ÿ”ง
prefer-escape-replacement-dollar-char enforces escape of replacement $ character ($$).
prefer-predefined-assertion prefer predefined assertion over equivalent lookarounds โœ… ๐Ÿ”ง
prefer-quantifier enforce using quantifier ๐Ÿ”ง
prefer-range enforce using character class range โœ… ๐Ÿ”ง
prefer-regexp-exec enforce that RegExp#exec is used instead of String#match if no global flag is provided
prefer-regexp-test enforce that RegExp#test is used instead of String#match and RegExp#exec ๐Ÿ”ง
prefer-set-operation prefer character class set operations instead of lookarounds โœ… ๐Ÿ”ง
require-unicode-regexp enforce the use of the u flag ๐Ÿ”ง
require-unicode-sets-regexp enforce the use of the v flag ๐Ÿ”ง
simplify-set-operations require simplify set operations โœ… ๐Ÿ”ง
sort-alternatives sort alternatives if order doesn't matter ๐Ÿ”ง
use-ignore-case use the i flag if it simplifies the pattern โœ… ๐Ÿ”ง

Stylistic Issues

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿ”ง ๐Ÿ’ก
grapheme-string-literal enforce single grapheme in string literal
hexadecimal-escape enforce consistent usage of hexadecimal escape ๐Ÿ”ง
letter-case enforce into your favorite case ๐Ÿ”ง
match-any enforce match any character style โœ… ๐Ÿ”ง
no-useless-escape disallow unnecessary escape characters in RegExp โœ… ๐Ÿ”ง
no-useless-non-capturing-group disallow unnecessary non-capturing group โœ… ๐Ÿ”ง
prefer-character-class enforce using character class โœ… ๐Ÿ”ง
prefer-d enforce using \d โœ… ๐Ÿ”ง
prefer-lookaround prefer lookarounds over capturing group that do not replace ๐Ÿ”ง
prefer-named-backreference enforce using named backreferences ๐Ÿ”ง
prefer-named-capture-group enforce using named capture groups
prefer-named-replacement enforce using named replacement ๐Ÿ”ง
prefer-plus-quantifier enforce using + quantifier โœ… ๐Ÿ”ง
prefer-question-quantifier enforce using ? quantifier โœ… ๐Ÿ”ง
prefer-result-array-groups enforce using result array groups ๐Ÿ”ง
prefer-star-quantifier enforce using * quantifier โœ… ๐Ÿ”ง
prefer-unicode-codepoint-escapes enforce use of unicode codepoint escapes โœ… ๐Ÿ”ง
prefer-w enforce using \w โœ… ๐Ÿ”ง
sort-character-class-elements enforces elements order in character class ๐Ÿ”ง
sort-flags require regex flags to be sorted โœ… ๐Ÿ”ง
unicode-escape enforce consistent usage of unicode escape or unicode codepoint escape ๐Ÿ”ง

Removed

  • โ›” These rules have been removed in a previous major release, after they have been deprecated for a while.
Rule ID Replaced by Removed in version
no-assertion-capturing-group regexp/no-empty-capturing-group v2.0.0
no-useless-exactly-quantifier regexp/no-useless-quantifier, regexp/no-zero-quantifier v2.0.0
no-useless-non-greedy regexp/no-useless-lazy v2.0.0
order-in-character-class regexp/sort-character-class-elements v2.0.0
prefer-t regexp/control-character-escape v2.0.0

โš™๏ธ Settings

See Settings.

๐Ÿšฅ Semantic Versioning Policy

eslint-plugin-regexp follows Semantic Versioning and ESLint's Semantic Versioning Policy.

๐Ÿป Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

See CONTRIBUTING.md.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run update runs in order to update readme and recommended configuration.
  • npm run new [new rule name] runs to create the files needed for the new rule.
  • npm run docs:watch starts the website locally.

๐Ÿ”’ License

See the LICENSE file for license rights and limitations (MIT).

More Repositories

1

eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
TypeScript
173
star
2

eslint-plugin-astro

ESLint plugin for Astro component
TypeScript
117
star
3

stylelint-config-recommended-vue

The recommended shareable Vue config for Stylelint.
JavaScript
72
star
4

eslint-plugin-es-x

ESLint plugin about ECMAScript syntactic features.
JavaScript
64
star
5

eslint-plugin-json-schema-validator

ESLint plugin that validates data using JSON Schema Validator.
TypeScript
64
star
6

eslint-plugin-yml

This ESLint plugin provides linting rules for YAML.
TypeScript
64
star
7

jsonc-eslint-parser

JSON, JSONC and JSON5 parser for use with ESLint plugins.
TypeScript
54
star
8

astro-eslint-parser

Astro component parser for ESLint
TypeScript
43
star
9

vuepress-plugin-full-text-search2

VuePress v2 plugin that adds full-text search box.
TypeScript
31
star
10

stylelint-config-html

The shareable HTML config for Stylelint.
JavaScript
29
star
11

stylelint-plugin-stylus

stylelint plugin for Stylus
JavaScript
24
star
12

eslint-plugin-css

An ESLint plugin that provides rules to verify CSS definition objects.
TypeScript
19
star
13

eslint-plugin-lodash-template

ESLint plugin for John Resig-style micro template, Lodash's template, Underscore's template and EJS.
JavaScript
16
star
14

eslint-plugin-toml

This ESLint plugin provides linting rules for TOML.
TypeScript
15
star
15

stylelint-config-standard-vue

The standard shareable Vue config for Stylelint.
JavaScript
15
star
16

postcss-styl

PostCSS parser plugin for converting Stylus syntax to PostCSS AST.
JavaScript
15
star
17

postcss-html

PostCSS syntax for parsing HTML (and HTML-like)
JavaScript
14
star
18

typescript-eslint-parser-for-extra-files

An experimental ESLint custom parser for Vue, Svelte, and Astro for use with TypeScript. It provides type information in combination with each framework's ESLint custom parser.
TypeScript
13
star
19

eslint-plugin-node-dependencies

ESLint plugin to check Node.js dependencies.
TypeScript
12
star
20

vite-plugin-eslint4b

Vite plugin for running ESLint on browser
TypeScript
9
star
21

vite-plugin-svelte-md

Markdown with Svelte for Vite
TypeScript
9
star
22

toml-eslint-parser

A TOML parser that produces output compatible with ESLint
TypeScript
9
star
23

estree-halstead

Halstead complexity measures for ESTree
TypeScript
8
star
24

eslint-plugin-vue-demo

eslint-plugin-vue Online Playground
Vue
5
star
25

eslint-plugin

ESLint configuration plugin for me.
JavaScript
4
star
26

chromeextension_selectbox_filter

JavaScript
4
star
27

eslint-online-playground

ESLint Online Playground
TypeScript
3
star
28

shine-and-bright

Dark and Light Theme Switch CSS
CSS
3
star
29

mrpm

npm package
JavaScript
3
star
30

data-table-performance-test

Grid/Data Table/Spreadsheet Components Performance Test
JavaScript
2
star
31

yaml-eslint-parser

A YAML parser that produces output compatible with ESLint
TypeScript
2
star
32

eslint-plugin-promise-playground

eslint-plugin-promise Online Playground
Svelte
2
star
33

stylelint4b

stylelint which works in browsers
JavaScript
1
star
34

spring-webflux-x-cheetah-grid-example

Vue
1
star
35

vue-fes-japan-online-2022-slide

Vue Fes Japan Online 2022 ็™บ่กจใ‚นใƒฉใ‚คใƒ‰
TypeScript
1
star
36

image-matcher

JavaScript
1
star
37

eslint-config-vue-preset

Provides various shareable configs for `eslint-plugin-vue`.
JavaScript
1
star
38

postcss-calc-ast-parser

Parse the `calc()` function defined in CSS and convert it to AST.
TypeScript
1
star
39

stylelint-demo-poc

TypeScript
1
star
40

vue_components_example_materialize

Vue.js v2ใ‚’ไฝฟใฃใŸใ‚ณใƒณใƒใƒผใƒใƒณใƒˆไฝœๆˆใ‚ตใƒณใƒ—ใƒซ๏ผˆMaterializeๅˆฉ็”จ๏ผ‰
JavaScript
1
star