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

Make regex-shorthand rule use regexp-tree for regex literals #437

Merged
merged 2 commits into from Nov 24, 2019

Conversation

jdanil
Copy link
Contributor

@jdanil jdanil commented Nov 16, 2019

Continuing on from #261 to fix #157.

  • Updated to use regexp-tree to optimize for more cases.
  • Updated error messages to include more detailed information.
  • Fixed regex-shorthand code errors in eslint-plugin-unicorn.

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@jdanil jdanil changed the title update to use for regex literals update regex-shorthand to use regexp-tree for regex literals Nov 16, 2019
@fisker
Copy link
Collaborator

fisker commented Nov 16, 2019

wow, so many regexp in codebase can be optimized

@fisker
Copy link
Collaborator

fisker commented Nov 16, 2019

@jdanil
Copy link
Contributor Author

jdanil commented Nov 16, 2019

wow, so many regexp in codebase can be optimized

Yah a couple. Most of the changes are re-ordering though.

looks the same as https://github.com/BrainMaestro/eslint-plugin-optimize-regex/blob/master/lib/rules/optimize-regex.js to me

Yep. That's what #261 was based off of too. But just for regex literals. RegExp with string arguments is still using clean-regexp.

@fisker
Copy link
Collaborator

fisker commented Nov 17, 2019

@jdanil off topic , how did you fix those RegExps? I'm not sure yarn lint error message is clear enough

@sindresorhus sindresorhus changed the title update regex-shorthand to use regexp-tree for regex literals Make regex-shorthand to use regexp-tree for regex literals Nov 19, 2019
@sindresorhus sindresorhus changed the title Make regex-shorthand to use regexp-tree for regex literals Make regex-shorthand rule use regexp-tree for regex literals Nov 24, 2019
@sindresorhus sindresorhus merged commit 3554c17 into sindresorhus:master Nov 24, 2019
@jdanil
Copy link
Contributor Author

jdanil commented Dec 3, 2019

@jdanil off topic , how did you fix those RegExps? I'm not sure yarn lint error message is clear enough

I used the optimised regex from regexp-tree. The only problem I had with some of the optimised regex was that regexp-tree tries to order groups alphabetically I think. It would have symbols followed by alphanumeric characters, so some of the symbols needed to be escaped.

@fisker
Copy link
Collaborator

fisker commented Dec 3, 2019

@jdanil I mean did you fix them by npm run lint --fix or ?

I put a message here, https://travis-ci.org/sindresorhus/eslint-plugin-unicorn/jobs/612730929#L266

But not sure is it clear

@jdanil
Copy link
Contributor Author

jdanil commented Dec 3, 2019

@jdanil I mean did you fix them by npm run lint --fix or ?

I put a message here, https://travis-ci.org/sindresorhus/eslint-plugin-unicorn/jobs/612730929#L266

But not sure is it clear

Ohh. No I missed that script and comment.
I was actually surprised to see the updated rule running on the PR in travis!
I just updated all the issues it reported because I didn't know I could run the autofix.
Thanks for pointing it out 🙂

@fisker
Copy link
Collaborator

fisker commented Dec 5, 2019

@jdanil thanks for your feedback.

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

Successfully merging this pull request may close these issues.

The regex-shorthand rule has a false-negative
3 participants