Introduction
eslint-plugin-regexp is ESLint plugin for finding RegExp mistakes and RegExp style guide violations.
![Coverage Status](https://coveralls.io/repos/github/ota-meshi/eslint-plugin-regexp/badge.svg?branch=master)
: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.
- 80 plugin rules for regular expression syntax and features.
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 eslint.config.js
or .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 (New Config)
The plugin.configs["flat/recommended"]
config enables a subset of the rules that should be most useful to most users.
See lib/configs/rules/recommended.ts for more details.
import * as regexpPlugin from "eslint-plugin-regexp"
export default [
regexpPlugin.configs["flat/recommended"],
];
The recommended configuration (Legacy Config)
The plugin:regexp/recommended
config enables a subset of the rules that should be most useful to most users.
See lib/configs/rules/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.
import * as regexpPlugin from "eslint-plugin-regexp"
export default [
{
plugins: { regexp: regexpPlugin }
rules: {
"regexp/rule-name": "error"
}
}
];
module.exports = {
"plugins": [
"regexp"
],
"rules": {
"regexp/rule-name": "error"
}
}
Using the all configuration
The plugin.configs["flat/all"]
/ 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/rules/all.ts for more details.
:white_check_mark: Rules
πΌ Configurations enabled in.
β οΈ Configurations set to warn in.
π’ Set in the flat/recommended
configuration.
π΅ Set in the recommended
configuration.
π§ Automatically fixable by the --fix
CLI option.
π‘ Manually fixable by editor suggestions.
Possible Errors
Best Practices
Stylistic Issues
Removed
- :no_entry: These rules have been removed in a previous major release, after they have been deprecated for a while.
: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).