Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex plugins #227

Closed
fregante opened this issue Jun 8, 2017 · 3 comments
Closed

Add regex plugins #227

fregante opened this issue Jun 8, 2017 · 3 comments

Comments

@fregante
Copy link
Member

fregante commented Jun 8, 2017

eslint-plugin-no-unsafe-regex

"unsafe regex" as defined by substack/safe-regex

detect possibly catastrophic, exponential-time regular expressions

Examples of bad regexes:

/^(a?){25}(a){25}$/,
RegExp(Array(27).join('a?') + Array(27).join('a')),
/(x+x+)+y/,
/foo|(x+x+)+y/,
/(a+){10}y/,
/(a+){2}y/,
/(.*){1,32000}[bc]/

eslint-plugin-optimize-regex

Example

/[a-zA-Z_0-9][A-Z_\\da-z]*\\e{1,}/ can be optimized to /\\w+e+/
@fregante fregante changed the title Add eslint-plugin-no-unsafe-regex Add regex plugins Jun 8, 2017
@sindresorhus
Copy link
Member

Yeah. Looks useful. Pull request welcomez.

bdougherty added a commit to bdougherty/xo that referenced this issue Jan 19, 2018
bdougherty added a commit to bdougherty/xo that referenced this issue Jan 19, 2018
bdougherty added a commit to bdougherty/xo that referenced this issue Jan 20, 2018
bdougherty added a commit to bdougherty/xo that referenced this issue Jan 20, 2018
bdougherty added a commit to bdougherty/xo that referenced this issue Jan 20, 2018
bdougherty added a commit to bdougherty/eslint-plugin-unicorn that referenced this issue Jan 20, 2018
@bdougherty
Copy link

So the regex-shorthand rule covers some of the cases for optimize-regex, but it's simpler so it doesn't cover everything.

The author of the optimize-regex plugin is open to a PR that fixes node 4 compatibility, so I can do that if you're still open to adding that plugin. Otherwise, I can add a rule to eslint-plugin-unicorn that uses regexp-tree. In that case it may be better to replace or update the existing rule.

@fregante
Copy link
Member Author

These have been added (but the first one was removed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants