eslint-plugin-regexp
Advanced tools
Comparing version
@@ -11,5 +11,14 @@ "use strict"; | ||
}, | ||
schema: [], | ||
schema: [ | ||
{ | ||
type: "object", | ||
properties: { | ||
disallowNeverMatch: { type: "boolean" }, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
messages: { | ||
duplicated: "The disjunctions are duplicated.", | ||
neverExecute: "This disjunction can never match. Its condition is covered by previous conditions in the disjunctions.", | ||
}, | ||
@@ -19,13 +28,19 @@ type: "suggestion", | ||
create(context) { | ||
var _a; | ||
const disallowNeverMatch = Boolean((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.disallowNeverMatch); | ||
const sourceCode = context.getSourceCode(); | ||
function createVisitor(node) { | ||
function createVisitor(node, _p, flags) { | ||
function verify(regexpNode) { | ||
const otherAlts = []; | ||
const leftAlts = []; | ||
for (const alt of regexpNode.alternatives) { | ||
const dupeAlt = otherAlts.find((o) => regexp_ast_1.isEqualNodes(alt, o, (a, _b) => { | ||
if (a.type === "CapturingGroup") { | ||
return false; | ||
} | ||
return null; | ||
})); | ||
const dupeAlt = disallowNeverMatch | ||
? leftAlts.find((leftAlt) => regexp_ast_1.isCoveredNode(leftAlt, alt, { | ||
flags: { left: flags, right: flags }, | ||
})) | ||
: leftAlts.find((leftAlt) => regexp_ast_1.isEqualNodes(leftAlt, alt, (a, _b) => { | ||
if (a.type === "CapturingGroup") { | ||
return false; | ||
} | ||
return null; | ||
})); | ||
if (dupeAlt) { | ||
@@ -35,8 +50,10 @@ context.report({ | ||
loc: utils_1.getRegexpLocation(sourceCode, node, alt), | ||
messageId: "duplicated", | ||
messageId: disallowNeverMatch && | ||
!regexp_ast_1.isEqualNodes(dupeAlt, alt) | ||
? "neverExecute" | ||
: "duplicated", | ||
}); | ||
continue; | ||
} | ||
else { | ||
otherAlts.push(alt); | ||
} | ||
leftAlts.push(alt); | ||
} | ||
@@ -43,0 +60,0 @@ } |
@@ -59,2 +59,5 @@ "use strict"; | ||
} | ||
usedAllUnnamed() { | ||
this.unused.clear(); | ||
} | ||
isAllUsed() { | ||
@@ -300,5 +303,2 @@ return !this.unused.size && !this.unusedNames.size; | ||
} | ||
if (!typeTracer.isString(node.arguments[0])) { | ||
return; | ||
} | ||
capturingData.markAsUsed(); | ||
@@ -365,5 +365,2 @@ } | ||
} | ||
if (!typeTracer.isString(node.arguments[0])) { | ||
return; | ||
} | ||
capturingData.markAsUsed(); | ||
@@ -472,2 +469,13 @@ verifyForExecResult(node, capturingData); | ||
} | ||
function verifyForSplit(node) { | ||
const capturingData = getCapturingData(node.arguments[0]); | ||
if (capturingData == null || capturingData.isAllUsed()) { | ||
return; | ||
} | ||
if (!typeTracer.isString(node.callee.object)) { | ||
return; | ||
} | ||
capturingData.markAsUsed(); | ||
capturingData.usedAllUnnamed(); | ||
} | ||
function createVisitor(node, _pattern, flags, regexpNode) { | ||
@@ -495,2 +503,3 @@ const capturingData = new CapturingData(node, flags); | ||
exec: 1, | ||
split: 1, | ||
})) { | ||
@@ -518,4 +527,7 @@ return; | ||
} | ||
else if (node.callee.property.name === "split") { | ||
verifyForSplit(node); | ||
} | ||
} }); | ||
}, | ||
}); |
@@ -82,3 +82,3 @@ "use strict"; | ||
? "character class range" | ||
: "character set", | ||
: "character class escape", | ||
additional: element.type === "CharacterClassRange" | ||
@@ -85,0 +85,0 @@ ? " and range" |
@@ -13,3 +13,3 @@ "use strict"; | ||
messages: { | ||
unexpected: 'Unexpected character set "{{expr}}". Use "{{instead}}" instead.', | ||
unexpected: 'Unexpected {{type}} "{{expr}}". Use "{{instead}}" instead.', | ||
}, | ||
@@ -40,2 +40,5 @@ type: "suggestion", | ||
data: { | ||
type: reportNode.type === "CharacterClass" | ||
? "character class" | ||
: "character class range", | ||
expr: reportNode.raw, | ||
@@ -42,0 +45,0 @@ instead, |
@@ -192,3 +192,5 @@ "use strict"; | ||
? "characters" | ||
: "character sets", | ||
: buffer.target.kind === "any" | ||
? "any characters" | ||
: "character class escapes", | ||
quantifier: buffer.getQuantifier(), | ||
@@ -195,0 +197,0 @@ }, |
@@ -32,3 +32,3 @@ "use strict"; | ||
messages: { | ||
unexpected: 'Unexpected character set "{{expr}}". Use "{{instead}}" instead.', | ||
unexpected: 'Unexpected {{type}} "{{expr}}". Use "{{instead}}" instead.', | ||
}, | ||
@@ -85,2 +85,3 @@ type: "suggestion", | ||
data: { | ||
type: "character class", | ||
expr: ccNode.raw, | ||
@@ -104,2 +105,3 @@ instead, | ||
data: { | ||
type: "character class ranges", | ||
expr: `[${unexpectedElements | ||
@@ -106,0 +108,0 @@ .map((e) => e.raw) |
@@ -84,4 +84,3 @@ "use strict"; | ||
} | ||
if ("bigint" in node && | ||
node.bigint) { | ||
if ("bigint" in node && node.bigint) { | ||
return type_data_1.BIGINT; | ||
@@ -88,0 +87,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CP_SMALL_Z = exports.CP_SMALL_A = exports.CP_DIGIT_NINE = exports.CP_DIGIT_ZERO = exports.CP_BOM = exports.CP_IDEOGRAPHIC_SPACE = exports.CP_BRAILLE_PATTERN_BLANK = exports.CP_MMSP = exports.CP_NNBSP = exports.CP_PARAGRAPH_SEPARATOR = exports.CP_LINE_SEPARATOR = exports.CP_RLM = exports.CP_LRM = exports.CP_ZWJ = exports.CP_ZWNJ = exports.CP_ZWSP = exports.CP_HAIR_SPACE = exports.CP_EN_QUAD = exports.CP_MONGOLIAN_VOWEL_SEPARATOR = exports.CP_OGHAM_SPACE_MARK = exports.CP_NBSP = exports.CP_NEL = exports.CP_TILDE = exports.CP_CLOSING_BRACE = exports.CP_PIPE = exports.CP_OPENING_BRACE = exports.CP_BACKTICK = exports.CP_CARET = exports.CP_CLOSING_BRACKET = exports.CP_BACK_SLASH = exports.CP_OPENING_BRACKET = exports.CP_AT = exports.CP_QUESTION = exports.CP_COLON = exports.CP_SLASH = exports.CP_DOT = exports.CP_MINUS = exports.CP_PLUS = exports.CP_STAR = exports.CP_CLOSING_PAREN = exports.CP_OPENING_PAREN = exports.CP_DOLLAR = exports.CP_BAN = exports.CP_SPACE = exports.CP_CR = exports.CP_FF = exports.CP_VT = exports.CP_LF = exports.CP_TAB = exports.CP_BACKSPACE = void 0; | ||
exports.invisibleEscape = exports.isInvisible = exports.isWord = exports.isSpace = exports.isSymbol = exports.isLetter = exports.isUppercaseLetter = exports.isLowercaseLetter = exports.isDigit = exports.CP_RANGES_WORDS = exports.CP_RANGE_SPACES = exports.CP_RANGE_CAPITAL_LETTER = exports.CP_RANGE_SMALL_LETTER = exports.CP_RANGE_DIGIT = exports.CPS_SINGLE_SPACES = exports.CP_LOW_LINE = exports.CP_CAPITAL_Z = exports.CP_CAPITAL_A = void 0; | ||
exports.invisibleEscape = exports.isInvisible = exports.isWord = exports.isSpace = exports.isSymbol = exports.toUpperCodePoint = exports.toLowerCodePoint = exports.isLetter = exports.isUppercaseLetter = exports.isLowercaseLetter = exports.isDigit = exports.CP_RANGES_WORDS = exports.CP_RANGE_SPACES = exports.CP_RANGE_CAPITAL_LETTER = exports.CP_RANGE_SMALL_LETTER = exports.CP_RANGE_DIGIT = exports.CPS_SINGLE_SPACES = exports.CP_LOW_LINE = exports.CP_CAPITAL_Z = exports.CP_CAPITAL_A = void 0; | ||
exports.CP_BACKSPACE = 8; | ||
@@ -103,2 +103,16 @@ exports.CP_TAB = 9; | ||
exports.isLetter = isLetter; | ||
function toLowerCodePoint(codePoint) { | ||
if (isUppercaseLetter(codePoint)) { | ||
return codePoint + 0x0020; | ||
} | ||
return codePoint; | ||
} | ||
exports.toLowerCodePoint = toLowerCodePoint; | ||
function toUpperCodePoint(codePoint) { | ||
if (isLowercaseLetter(codePoint)) { | ||
return codePoint - 0x0020; | ||
} | ||
return codePoint; | ||
} | ||
exports.toUpperCodePoint = toUpperCodePoint; | ||
function isSymbol(codePoint) { | ||
@@ -105,0 +119,0 @@ return (isCodePointInRange(codePoint, [exports.CP_BAN, exports.CP_SLASH]) || |
{ | ||
"name": "eslint-plugin-regexp", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"description": "ESLint plugin for finding RegExp mistakes and RegExp style guide violations.", | ||
@@ -52,3 +52,3 @@ "main": "dist/index.js", | ||
"@types/eslint-scope": "^3.7.0", | ||
"@types/estree": "~0.0.45", | ||
"@types/estree": "^0.0.47", | ||
"@types/mocha": "^8.0.0", | ||
@@ -64,3 +64,3 @@ "@types/node": "^14.0.13", | ||
"eslint-plugin-eslint-plugin": "^2.3.0", | ||
"eslint-plugin-json-schema-validator": "^0.4.0", | ||
"eslint-plugin-json-schema-validator": "^1.0.0", | ||
"eslint-plugin-jsonc": "^1.0.0", | ||
@@ -67,0 +67,0 @@ "eslint-plugin-node": "^11.1.0", |
306543
7.46%74
4.23%7596
8.01%