ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.
https://ota-meshi.github.io/eslint-plugin-regexp/
MIT License
701 stars 10 forks source link

Rule idea: `no-useless-constructor` #783

Closed silverwind closed 1 week ago

silverwind commented 1 week ago

Motivation Saw this abuse in the wild.

Description Avoid useless RegExp constructor around literals.

Examples

/* ✗ BAD */
var foo = new RegExp(/regex/)

/* ✓ GOOD */
var foo = /regex/
ota-meshi commented 1 week ago

Thanks for the rule suggestion. However, is it different from the prefer-regex-literals rule in ESLint core?

https://eslint.org/docs/latest/rules/prefer-regex-literals#disallowredundantwrapping

silverwind commented 1 week ago

It is the same as disallowRedundantWrapping, I wasn't aware of that option. Added it to my config. Thanks for pointing it out.