eslint-plugin-regexp
Advanced tools
Comparing version
@@ -344,7 +344,10 @@ "use strict"; | ||
} | ||
decrementMax() { | ||
decrementMax(dec = 1) { | ||
if (this.max <= dec) { | ||
return null; | ||
} | ||
if (this.max === Infinity) { | ||
return this; | ||
} | ||
const opt = new NormalizedOptional(this.node, this.flags, this.max - 1); | ||
const opt = new NormalizedOptional(this.node, this.flags, this.max - dec); | ||
opt.normalizedElement = this.normalizedElement; | ||
@@ -460,35 +463,34 @@ return opt; | ||
} | ||
function isCoveredAltNodes(left, right, options) { | ||
let rightLength = right.length; | ||
if (options.canOmitRight) { | ||
while (right[rightLength - 1]) { | ||
const re = right[rightLength - 1]; | ||
if (re.type === "NormalizedOptional") { | ||
rightLength--; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
} | ||
let leftIndex = 0; | ||
let rightIndex = 0; | ||
while (leftIndex < left.length && rightIndex < rightLength) { | ||
const le = left[leftIndex]; | ||
const re = right[rightIndex]; | ||
function isCoveredAltNodes(leftNodes, rightNodes, options) { | ||
const left = options.canOmitRight ? omitEnds(leftNodes) : leftNodes; | ||
const right = options.canOmitRight ? omitEnds(rightNodes) : rightNodes; | ||
while (left.length && right.length) { | ||
const le = left.shift(); | ||
const re = right.shift(); | ||
if (re.type === "NormalizedOptional") { | ||
let leftElement; | ||
if (le.type === "NormalizedOptional") { | ||
leftElement = le.element; | ||
if (!isCoveredForNormalizedNode(le.element, re.element, options)) { | ||
return false; | ||
} | ||
const decrementLe = le.decrementMax(re.max); | ||
if (decrementLe) { | ||
return isCoveredAltNodes([decrementLe, ...left], right, options); | ||
} | ||
const decrementRe = re.decrementMax(le.max); | ||
if (decrementRe) { | ||
return isCoveredAltNodes(left, [decrementRe, ...right], options); | ||
} | ||
} | ||
else { | ||
leftElement = le; | ||
if (!isCoveredForNormalizedNode(le, re.element, options)) { | ||
return false; | ||
} | ||
const decrementRe = re.decrementMax(); | ||
if (decrementRe) { | ||
return isCoveredAltNodes(left, [decrementRe, ...right], options); | ||
} | ||
} | ||
if (!isCoveredForNormalizedNode(leftElement, re.element, options)) { | ||
return false; | ||
} | ||
} | ||
else if (le.type === "NormalizedOptional") { | ||
const skippedLeftItems = left.slice(leftIndex + 1); | ||
if (isCoveredAltNodes(skippedLeftItems, right.slice(rightIndex), options)) { | ||
if (isCoveredAltNodes(left, [re, ...right], options)) { | ||
return true; | ||
@@ -499,4 +501,5 @@ } | ||
} | ||
if (le.max >= 2) { | ||
if (isCoveredAltNodes([le.decrementMax(), ...skippedLeftItems], right.slice(rightIndex + 1), options)) { | ||
const decrementLe = le.decrementMax(); | ||
if (decrementLe) { | ||
if (isCoveredAltNodes([decrementLe, ...left], right, options)) { | ||
return true; | ||
@@ -509,18 +512,18 @@ } | ||
} | ||
leftIndex++; | ||
rightIndex++; | ||
} | ||
if (!options.canOmitRight) { | ||
if (rightIndex < right.length) { | ||
if (right.length) { | ||
return false; | ||
} | ||
} | ||
while (leftIndex < left.length) { | ||
const le = left[leftIndex]; | ||
if (le.type !== "NormalizedOptional") { | ||
return false; | ||
return !left.length; | ||
} | ||
function omitEnds(nodes) { | ||
for (let index = nodes.length - 1; index >= 0; index--) { | ||
const node = nodes[index]; | ||
if (node.type !== "NormalizedOptional") { | ||
return nodes.slice(0, index + 1); | ||
} | ||
leftIndex++; | ||
} | ||
return leftIndex >= left.length; | ||
return []; | ||
} |
{ | ||
"name": "eslint-plugin-regexp", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "ESLint plugin for finding RegExp mistakes and RegExp style guide violations.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
308931
0.12%7657
0.04%