Skip to content

Latest commit

 

History

History
88 lines (55 loc) · 2.39 KB

no-contradiction-with-assertion.md

File metadata and controls

88 lines (55 loc) · 2.39 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-contradiction-with-assertion
disallow elements that contradict assertions
v1.2.0

regexp/no-contradiction-with-assertion

💼 This rule is enabled in the ✅ plugin:regexp/recommended config.

💡 This rule is manually fixable by editor suggestions.

disallow elements that contradict assertions

📖 Rule Details

This rule reports elements that contradict an assertion. All elements reported by this rule fall into one of two categories:

  1. 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/;
  2. 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*-/;

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.2.0

🔍 Implementation