eslint-plugin-regexp
ESLint plugin for finding RegExp mistakes and RegExp style guide violations.
Last updated a year ago by ota-meshi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install eslint-plugin-regexp 
SYNC missed versions from official npm registry.

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

:name_badge: 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.

You can check on the Online DEMO.

:book: Documentation

See documents.

:cd: Installation

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

Requirements

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

:book: 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 recommended configuration

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.

:white_check_mark: 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-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-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 🔧
require-unicode-regexp enforce the use of the u flag 🔧
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 💼 ⚠️ 🔧 💡
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 🔧

Deprecated

Name Description 💼 ⚠️ 🔧 💡
no-assertion-capturing-group disallow capturing group that captures empty.
no-useless-exactly-quantifier disallow unnecessary exactly quantifier
no-useless-non-greedy disallow unnecessarily non-greedy quantifiers 🔧
order-in-character-class enforces elements order in character class 🔧
prefer-t enforce using \t 🔧

:gear: Settings

See Settings.

:traffic_light: Semantic Versioning Policy

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

:beers: 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.

:lock: License

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

Current Tags

  • 2.6.0                                ...           latest (7 months ago)
  • 2.0.0-next.15                                ...           next (a year ago)

76 Versions

  • 2.6.0                                ...           7 months ago
  • 2.5.0                                ...           9 months ago
  • 2.4.0                                ...           9 months ago
  • 2.3.0                                ...           10 months ago
  • 2.2.0                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 2.0.0-next.15                                ...           a year ago
  • 2.0.0-next.14                                ...           a year ago
  • 2.0.0-next.13                                ...           a year ago
  • 2.0.0-next.12                                ...           a year ago
  • 2.0.0-next.11                                ...           a year ago
  • 2.0.0-next.10                                ...           a year ago
  • 2.0.0-next.9                                ...           a year ago
  • 2.0.0-next.8                                ...           a year ago
  • 2.0.0-next.7                                ...           a year ago
  • 2.0.0-next.6                                ...           a year ago
  • 2.0.0-next.5                                ...           a year ago
  • 2.0.0-next.4                                ...           a year ago
  • 2.0.0-next.3                                ...           a year ago
  • 2.0.0-next.2                                ...           a year ago
  • 2.0.0-next.1                                ...           a year ago
  • 2.0.0-next.0                                ...           a year ago
  • 1.15.0                                ...           2 years ago
  • 1.14.0                                ...           2 years ago
  • 1.13.0                                ...           2 years ago
  • 1.12.0                                ...           2 years ago
  • 1.11.0                                ...           2 years ago
  • 1.10.0                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.8.0                                ...           2 years ago
  • 1.7.0                                ...           3 years ago
  • 1.6.0                                ...           3 years ago
  • 1.5.1                                ...           3 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.1                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.13.2                                ...           3 years ago
  • 0.13.1                                ...           3 years ago
  • 0.13.0                                ...           3 years ago
  • 0.12.1                                ...           4 years ago
  • 0.12.0                                ...           4 years ago
  • 0.11.0                                ...           4 years ago
  • 0.10.0                                ...           4 years ago
  • 0.9.0                                ...           4 years ago
  • 0.8.0                                ...           4 years ago
  • 0.7.5                                ...           4 years ago
  • 0.7.4                                ...           4 years ago
  • 0.7.3                                ...           4 years ago
  • 0.7.2                                ...           4 years ago
  • 0.7.1                                ...           4 years ago
  • 0.7.0                                ...           4 years ago
  • 0.6.3                                ...           4 years ago
  • 0.6.2                                ...           4 years ago
  • 0.6.1                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.3                                ...           4 years ago
  • 0.4.2                                ...           4 years ago
  • 0.4.1                                ...           4 years ago
  • 0.4.0                                ...           4 years ago
  • 0.3.1                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.2                                ...           4 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.0                                ...           4 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE