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

Further explanation for no-unused-capturing-group #346

Closed
RunDevelopment opened this issue Sep 28, 2021 · 3 comments · Fixed by #348
Closed

Further explanation for no-unused-capturing-group #346

RunDevelopment opened this issue Sep 28, 2021 · 3 comments · Fixed by #348
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@RunDevelopment
Copy link
Collaborator

I coincidentally found stylelint/eslint-config-stylelint#141 today and I thought that the discussion around no-unused-capturing-group was interesting.

In the documentation of no-unused-capturing-group, we say that non-capturing groups should be used to "optimize regular expressions" (as in "improve performance") but I don't think that's the only reason non-capturing groups should be preferred.

Using non-capturing groups also communicates intend more clearly. A capturing group is similar to a variable in that its value (the captured text) is stored and can be accessed, and like with variables, unused capturing groups are code smell. If a regex contains a capturing group, then I'll expect its captured text to be used in some form or another.

If it's alright with you @ota-meshi, then I'll add this reasoning to the documentation.

@RunDevelopment RunDevelopment added the documentation Improvements or additions to documentation label Sep 28, 2021
@RunDevelopment RunDevelopment self-assigned this Sep 28, 2021
@ota-meshi
Copy link
Owner

I think it's good for people to add it to the documentation 👍. I think that not many people (including me) are familiar with regexp best practices.

@RunDevelopment
Copy link
Collaborator Author

I think that not many people (including me) are familiar with regexp best practices.

Neither am I. Those were just my thoughts on unused capturing groups.

@ota-meshi
Copy link
Owner

I think your thoughts are true! I think we need to add it to the documentation

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

Successfully merging a pull request may close this issue.

2 participants