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

Forbid expression that whole expression is a group #814

Open
fisker opened this issue Mar 5, 2025 · 0 comments
Open

Forbid expression that whole expression is a group #814

fisker opened this issue Mar 5, 2025 · 0 comments
Labels
enhancement New feature or request new rule

Comments

@fisker
Copy link

fisker commented Mar 5, 2025

Motivation

I can't find a case that grouping /(.)/ can't be avoid, if used in String.match, match[0] can be used instead of match[1], if want a substitution, $& can be used instead of $1. Maybe I was wrong about this, but there are certainly cases we can avoid group.

Description

See above

Examples

/* ✓ GOOD */
var [matched] = foo.match(/a/);
foo.replace(/a/, '-$&');

/* ✗ BAD */
var [, matched] = foo.match(/(a)/);
foo.replace(/(a)/, '-$1');
@fisker fisker added enhancement New feature or request new rule labels Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

No branches or pull requests

1 participant