Eugeno / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.

Home Page:https://ota-meshi.github.io/eslint-plugin-regexp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

You can check on the Online DEMO.

πŸ“– Documentation

See documents.

πŸ’Ώ Installation

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

Requirements

  • ESLint v6.0.0 and above
  • Node.js v8.10.0 and above

πŸ“– Usage

Create .eslintrc.* file to configure rules. See also: http://eslint.org/docs/user-guide/configuring.

Example .eslintrc.js:

module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // 'eslint:recommended',
    'plugin:regexp/recommended'
  ],
  rules: {
    // override/add rules settings here, such as:
    // 'regexp/rule-name': 'error'
  }
}

Configuration

This plugin provides one config:

  • plugin:regexp/recommended ... This is the recommended configuration for this plugin. See lib/configs/recommended.ts for details.

βœ… Rules

The --fix option on the command line automatically fixes problems reported by rules which have a wrench πŸ”§ below. The rules with the following star ⭐ are included in the plugin:regexp/recommended config.

Rule ID Description
regexp/confusing-quantifier disallow confusing quantifiers
regexp/control-character-escape enforce consistent escaping of control characters πŸ”§
regexp/hexadecimal-escape enforce consistent usage of hexadecimal escape πŸ”§
regexp/letter-case enforce into your favorite case πŸ”§
regexp/match-any enforce match any character style β­πŸ”§
regexp/negation enforce use of escapes on negation πŸ”§
regexp/no-assertion-capturing-group disallow capturing group that captures assertions. ⭐
regexp/no-dupe-characters-character-class disallow duplicate characters in the RegExp character class ⭐
regexp/no-dupe-disjunctions disallow duplicate disjunctions
regexp/no-empty-alternative disallow alternatives without elements
regexp/no-empty-group disallow empty group ⭐
regexp/no-empty-lookarounds-assertion disallow empty lookahead assertion or empty lookbehind assertion ⭐
regexp/no-escape-backspace disallow escape backspace ([\b]) ⭐
regexp/no-invisible-character disallow invisible raw character β­πŸ”§
regexp/no-lazy-ends disallow lazy quantifiers at the end of an expression
regexp/no-legacy-features disallow legacy RegExp features
regexp/no-non-standard-flag disallow non-standard flags
regexp/no-obscure-range disallow obscure character ranges
regexp/no-octal disallow octal escape sequence ⭐
regexp/no-optional-assertion disallow optional assertions
regexp/no-potentially-useless-backreference disallow backreferences that reference a group that might not be matched
regexp/no-standalone-backslash disallow standalone backslashes (\)
regexp/no-trivially-nested-assertion disallow trivially nested assertions πŸ”§
regexp/no-trivially-nested-quantifier disallow nested quantifiers that can be rewritten as one quantifier πŸ”§
regexp/no-unused-capturing-group disallow unused capturing group
regexp/no-useless-assertions disallow assertions that are known to always accept (or reject)
regexp/no-useless-backreference disallow useless backreferences in regular expressions ⭐
regexp/no-useless-character-class disallow character class with one character πŸ”§
regexp/no-useless-dollar-replacements disallow useless $ replacements in replacement string
regexp/no-useless-escape disallow unnecessary escape characters in RegExp
regexp/no-useless-exactly-quantifier disallow unnecessary exactly quantifier ⭐
regexp/no-useless-flag disallow unnecessary regex flags πŸ”§
regexp/no-useless-lazy disallow unnecessarily non-greedy quantifiers πŸ”§
regexp/no-useless-non-capturing-group disallow unnecessary Non-capturing group πŸ”§
regexp/no-useless-non-greedy disallow unnecessarily non-greedy quantifiers πŸ”§
regexp/no-useless-range disallow unnecessary range of characters by using a hyphen πŸ”§
regexp/no-useless-two-nums-quantifier disallow unnecessary {n,m} quantifier β­πŸ”§
regexp/optimal-lookaround-quantifier disallow the alternatives of lookarounds that end with a non-constant quantifier
regexp/order-in-character-class enforces elements order in character class πŸ”§
regexp/prefer-character-class enforce using character class πŸ”§
regexp/prefer-d enforce using \d β­πŸ”§
regexp/prefer-escape-replacement-dollar-char enforces escape of replacement $ character ($$).
regexp/prefer-named-backreference enforce using named backreferences πŸ”§
regexp/prefer-plus-quantifier enforce using + quantifier β­πŸ”§
regexp/prefer-predefined-assertion prefer predefined assertion over equivalent lookarounds πŸ”§
regexp/prefer-quantifier enforce using quantifier πŸ”§
regexp/prefer-question-quantifier enforce using ? quantifier β­πŸ”§
regexp/prefer-range enforce using character class range πŸ”§
regexp/prefer-regexp-exec enforce that RegExp#exec is used instead of String#match if no global flag is provided
regexp/prefer-regexp-test enforce that RegExp#test is used instead of String#match and RegExp#exec πŸ”§
regexp/prefer-star-quantifier enforce using * quantifier β­πŸ”§
regexp/prefer-t enforce using \t β­πŸ”§
regexp/prefer-unicode-codepoint-escapes enforce use of unicode codepoint escapes πŸ”§
regexp/prefer-w enforce using \w β­πŸ”§
regexp/sort-flags require regex flags to be sorted πŸ”§
regexp/unicode-escape enforce consistent usage of unicode escape or unicode codepoint escape πŸ”§

βš™οΈ Settings

See Settings.

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

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

About

ESLint plugin for finding regex mistakes and style guide violations.

https://ota-meshi.github.io/eslint-plugin-regexp/

License:MIT License


Languages

Language:TypeScript 99.4%Language:JavaScript 0.6%