Skip to content

Forbid expression that whole expression is a group #814

@fisker

Description

@fisker

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');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions