pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/no-contradiction-with-assertion |
disallow elements that contradict assertions |
v1.2.0 |
💼 This rule is enabled in the ✅ plugin:regexp/recommended
config.
💡 This rule is manually fixable by editor suggestions.
disallow elements that contradict assertions
This rule reports elements that contradict an assertion. All elements reported by this rule fall into one of two categories:
-
An element/alternative that can never be entered.
This means that the element is dead code and can be removed. Example:
/* eslint regexp/no-contradiction-with-assertion: "error" */ var foo = /(?=a)(\w|-)/; var foo = /(?=a)b*a/;
-
An element that is always entered.
Right now, only quantifiers with a minimum of 0 are reported in this category. They are contradictory because the minimum of 0 is changed by the assertion to be effectively 1. Example:
/* eslint regexp/no-contradiction-with-assertion: "error" */ var foo = /a\b-?a/; var foo = /^foo$[\s\S]*?^end foo/m;
This rule is quite similar to regexp/no-useless-assertions. While regexp/no-useless-assertions tries to find assertions that contradict the pattern, this rule tries to find parts of the pattern that contradict assertions.
/* eslint regexp/no-contradiction-with-assertion: "error" */
/* ✓ GOOD */
var foo = /a\b-a/;
var foo = /a\ba/; // handled by regexp/no-useless-assertions
/* ✗ BAD */
var foo = /a\b-?a/;
var foo = /a\b(a|-)/;
var foo = /a\ba*-/;
Nothing.
This rule was introduced in eslint-plugin-regexp v1.2.0