What is eslint-plugin-regexp?
eslint-plugin-regexp is an ESLint plugin that provides linting rules for regular expressions. It helps developers write more efficient, readable, and secure regular expressions by catching common mistakes and suggesting improvements.
What are eslint-plugin-regexp's main functionalities?
No Unnecessary Escape
This rule disallows unnecessary escape characters in regular expressions. In the example, the backslash before the dot is unnecessary and should be removed.
/* eslint regexp/no-useless-escape: 'error' */
const regex = /\./;
No Obscure Character Class
This rule disallows obscure character class ranges that can be confusing or error-prone. In the example, the character class is clear and does not contain obscure ranges.
/* eslint regexp/no-obscure-range: 'error' */
const regex = /[a-zA-Z]/;
No Unnecessary Quantifier
This rule disallows unnecessary quantifiers in regular expressions. In the example, the quantifier {1} is unnecessary and should be removed.
/* eslint regexp/no-useless-quantifier: 'error' */
const regex = /a{1}/;
No Empty Character Class
This rule disallows empty character classes in regular expressions. In the example, the character class is empty and should be corrected.
/* eslint regexp/no-empty-character-class: 'error' */
const regex = /[]/;
Other packages similar to eslint-plugin-regexp
eslint-plugin-security
eslint-plugin-security is an ESLint plugin that helps identify potential security issues in JavaScript code. While it covers a broader range of security concerns, it includes some rules related to regular expressions, such as detecting potential ReDoS (Regular Expression Denial of Service) vulnerabilities. It is more general in scope compared to eslint-plugin-regexp.
eslint-plugin-unicorn
eslint-plugin-unicorn is a collection of various ESLint rules aimed at improving code quality and consistency. It includes some rules for regular expressions, such as preventing potential ReDoS attacks and suggesting more readable patterns. However, it is not as focused on regular expressions as eslint-plugin-regexp.
Introduction
eslint-plugin-regexp is ESLint plugin for finding RegExp mistakes and RegExp style guide violations.

: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 v6.0.0 and above
- Node.js v8.10.0 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 the recommended configuration 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 https://github.com/ota-meshi/eslint-plugin-regexp/blob/master/lib/configs/recommended.ts for more details.
module.exports = {
"plugins": [
"regexp"
],
"extends": [
"plugin:regexp/recommended"
]
}
Advanced Configuration
Override/add specific rules configurations. See also: http://eslint.org/docs/user-guide/configuring.
module.exports = {
"plugins": [
"regexp"
],
"rules": {
"regexp/rule-name": "error"
}
}
:white_check_mark: Rules
The --fix
option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
The rules with the following star :star: are included in the plugin:regexp/recommended
config.
Possible Errors
Best Practices
Stylistic Issues
:gear: Settings
See Settings.
:beers: 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.
:lock: License
See the LICENSE file for license rights and limitations (MIT).