Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 507 Bytes

no-useless-assertions.md

File metadata and controls

21 lines (15 loc) · 507 Bytes

Pattern: Assertion that always accepts or rejects

Issue: -

Description

Some assertions are unnecessary because the rest of the pattern forces them to always be accept (or reject).

Examples

/* eslint regexp/no-useless-assertions: "error" */
/* ✓ GOOD */
var foo = /\bfoo\b/;

/* ✗ BAD */
var foo = /#\bfoo/;    // \b will always accept
var foo = /foo\bbar/;  // \b will always reject
var foo = /$foo/;      // $ will always reject
var foo = /(?=\w)\d+/; // (?=\w) will always accept