πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-regexp

Package Overview
Dependencies
Maintainers
2
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-regexp - npm Package Compare versions

Comparing version

to
2.0.0-next.13

dist/rules/grapheme-string-literal.js

26

dist/rules/no-misleading-unicode-character.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const grapheme_splitter_1 = __importDefault(require("grapheme-splitter"));
const mention_1 = require("../utils/mention");
const splitter = new grapheme_splitter_1.default();
const segmenter = new Intl.Segmenter();
function startsWithSurrogate(s) {

@@ -43,18 +39,17 @@ if (s.length < 2) {

const before = alt.raw.slice(start - alt.start, quant.element.end - alt.start);
const graphemes = splitter.splitGraphemes(before);
const grapheme = graphemes[graphemes.length - 1];
return grapheme;
const segments = [...segmenter.segment(before)];
const segment = segments[segments.length - 1];
return segment.segment;
}
function getGraphemeProblems(cc, flags) {
let offset = cc.negate ? 2 : 1;
const offset = cc.negate ? 2 : 1;
const ignoreElements = cc.elements.filter((element) => element.type === "CharacterClass" ||
element.type === "ExpressionCharacterClass" ||
element.type === "ClassStringDisjunction");
const graphemes = splitter.splitGraphemes(cc.raw.slice(offset, -1));
const problems = [];
for (const grapheme of graphemes) {
const problem = getProblem(grapheme, flags);
for (const { segment, index } of segmenter.segment(cc.raw.slice(offset, -1))) {
const problem = getProblem(segment, flags);
if (problem !== null) {
const start = offset + cc.start;
const end = start + grapheme.length;
const start = offset + index + cc.start;
const end = start + segment.length;
if (ignoreElements.some((ignore) => ignore.start <= start && end <= ignore.end)) {

@@ -64,3 +59,3 @@ continue;

problems.push({
grapheme,
grapheme: segment,
problem,

@@ -72,3 +67,2 @@ start,

}
offset += grapheme.length;
}

@@ -75,0 +69,0 @@ return problems;

@@ -36,3 +36,4 @@ "use strict";

if (!alternativesText.length) {
const escape = isNeedEscapedInCharacterClass(csdNode, saNode)
const escape = isNeedEscapeForAdjacentPreviousCharacter(csdNode, saNode) ||
isNeedEscapeForAdjacentNextCharacter(csdNode, saNode)
? "\\"

@@ -48,3 +49,3 @@ : "";

}
const escape = isNeedEscapedInCharacterClass(csdNode, saNode)
const escape = isNeedEscapeForAdjacentPreviousCharacter(csdNode, saNode)
? "\\"

@@ -58,3 +59,3 @@ : "";

};
function isNeedEscapedInCharacterClass(disjunction, character) {
function isNeedEscapeForAdjacentPreviousCharacter(disjunction, character) {
const char = character.raw;

@@ -69,2 +70,7 @@ if (unicode_set_1.RESERVED_DOUBLE_PUNCTUATOR_CHARS.has(char) &&

}
function isNeedEscapeForAdjacentNextCharacter(disjunction, character) {
const char = character.raw;
return (unicode_set_1.RESERVED_DOUBLE_PUNCTUATOR_CHARS.has(char) &&
pattern[disjunction.end] === char);
}
}

@@ -71,0 +77,0 @@ return (0, utils_1.defineRegexpVisitor)(context, {

@@ -40,2 +40,8 @@ "use strict";

at: { result: "element" },
findLast: { elementParameters: [0], result: "element" },
findLastIndex: { elementParameters: [0] },
toReversed: { result: "array" },
toSorted: { elementParameters: [0, 1], result: "array" },
toSpliced: { result: "array" },
with: { result: "array" },
};

@@ -42,0 +48,0 @@ function* extractCapturingGroupReferences(node, flags, typeTracer, countOfCapturingGroup, context, options) {

@@ -9,2 +9,3 @@ "use strict";

const control_character_escape_1 = __importDefault(require("../rules/control-character-escape"));
const grapheme_string_literal_1 = __importDefault(require("../rules/grapheme-string-literal"));
const hexadecimal_escape_1 = __importDefault(require("../rules/hexadecimal-escape"));

@@ -96,2 +97,3 @@ const letter_case_1 = __importDefault(require("../rules/letter-case"));

control_character_escape_1.default,
grapheme_string_literal_1.default,
hexadecimal_escape_1.default,

@@ -98,0 +100,0 @@ letter_case_1.default,

@@ -140,3 +140,3 @@ "use strict";

});
return (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { toString: function_1.RETURN_STRING, toLocaleString: function_1.RETURN_STRING, pop: RETURN_ARRAY_ELEMENT, push: function_1.RETURN_NUMBER, concat: RETURN_CONCAT, join: function_1.RETURN_STRING, reverse: RETURN_SELF, shift: RETURN_ARRAY_ELEMENT, slice: RETURN_SELF, sort: RETURN_SELF, splice: RETURN_SELF, unshift: function_1.RETURN_NUMBER, indexOf: function_1.RETURN_NUMBER, lastIndexOf: function_1.RETURN_NUMBER, every: function_1.RETURN_BOOLEAN, some: function_1.RETURN_BOOLEAN, forEach: function_1.RETURN_VOID, map: RETURN_MAP, filter: RETURN_SELF, reduce: null, reduceRight: null, find: RETURN_ARRAY_ELEMENT, findIndex: function_1.RETURN_NUMBER, fill: function_1.RETURN_UNKNOWN_ARRAY, copyWithin: RETURN_SELF, entries: RETURN_ENTRIES, keys: RETURN_KEYS, values: RETURN_VALUES, includes: function_1.RETURN_BOOLEAN, flatMap: function_1.RETURN_UNKNOWN_ARRAY, flat: function_1.RETURN_UNKNOWN_ARRAY, at: RETURN_ARRAY_ELEMENT, length: number_1.NUMBER, 0: null, [Symbol.iterator]: null, [Symbol.unscopables]: null }));
return (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { toString: function_1.RETURN_STRING, toLocaleString: function_1.RETURN_STRING, pop: RETURN_ARRAY_ELEMENT, push: function_1.RETURN_NUMBER, concat: RETURN_CONCAT, join: function_1.RETURN_STRING, reverse: RETURN_SELF, shift: RETURN_ARRAY_ELEMENT, slice: RETURN_SELF, sort: RETURN_SELF, splice: RETURN_SELF, unshift: function_1.RETURN_NUMBER, indexOf: function_1.RETURN_NUMBER, lastIndexOf: function_1.RETURN_NUMBER, every: function_1.RETURN_BOOLEAN, some: function_1.RETURN_BOOLEAN, forEach: function_1.RETURN_VOID, map: RETURN_MAP, filter: RETURN_SELF, reduce: null, reduceRight: null, find: RETURN_ARRAY_ELEMENT, findIndex: function_1.RETURN_NUMBER, fill: function_1.RETURN_UNKNOWN_ARRAY, copyWithin: RETURN_SELF, entries: RETURN_ENTRIES, keys: RETURN_KEYS, values: RETURN_VALUES, includes: function_1.RETURN_BOOLEAN, flatMap: function_1.RETURN_UNKNOWN_ARRAY, flat: function_1.RETURN_UNKNOWN_ARRAY, at: RETURN_ARRAY_ELEMENT, findLast: RETURN_ARRAY_ELEMENT, findLastIndex: function_1.RETURN_NUMBER, toReversed: RETURN_SELF, toSorted: RETURN_SELF, toSpliced: RETURN_SELF, with: RETURN_SELF, length: number_1.NUMBER, 0: null, [Symbol.iterator]: null, [Symbol.unscopables]: null }));
});

@@ -133,2 +133,3 @@ "use strict";

fromEntries: null,
hasOwn: function_1.RETURN_BOOLEAN,
prototype: null,

@@ -135,0 +136,0 @@ });

@@ -65,2 +65,2 @@ "use strict";

exports.buildRegExpConstructor = buildRegExpConstructor;
const getPrototypes = (0, common_1.cache)(() => (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { exec: function_1.RETURN_STRING_ARRAY, test: function_1.RETURN_BOOLEAN, source: string_1.STRING, global: boolean_1.BOOLEAN, ignoreCase: boolean_1.BOOLEAN, multiline: boolean_1.BOOLEAN, lastIndex: number_1.NUMBER, compile: function_1.RETURN_REGEXP, flags: string_1.STRING, sticky: boolean_1.BOOLEAN, unicode: boolean_1.BOOLEAN, dotAll: boolean_1.BOOLEAN, [Symbol.match]: null, [Symbol.replace]: null, [Symbol.search]: null, [Symbol.split]: null, [Symbol.matchAll]: null })));
const getPrototypes = (0, common_1.cache)(() => (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { exec: function_1.RETURN_STRING_ARRAY, test: function_1.RETURN_BOOLEAN, source: string_1.STRING, global: boolean_1.BOOLEAN, ignoreCase: boolean_1.BOOLEAN, multiline: boolean_1.BOOLEAN, lastIndex: number_1.NUMBER, compile: function_1.RETURN_REGEXP, flags: string_1.STRING, sticky: boolean_1.BOOLEAN, unicode: boolean_1.BOOLEAN, dotAll: boolean_1.BOOLEAN, hasIndices: boolean_1.BOOLEAN, [Symbol.match]: null, [Symbol.replace]: null, [Symbol.search]: null, [Symbol.split]: null, [Symbol.matchAll]: null })));

@@ -49,2 +49,2 @@ "use strict";

exports.buildStringConstructor = buildStringConstructor;
const getPrototypes = (0, common_1.cache)(() => (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { toString: function_1.RETURN_STRING, charAt: function_1.RETURN_STRING, charCodeAt: function_1.RETURN_NUMBER, concat: function_1.RETURN_STRING, indexOf: function_1.RETURN_NUMBER, lastIndexOf: function_1.RETURN_NUMBER, localeCompare: function_1.RETURN_NUMBER, match: function_1.RETURN_STRING_ARRAY, replace: function_1.RETURN_STRING, search: function_1.RETURN_NUMBER, slice: function_1.RETURN_STRING, split: function_1.RETURN_STRING_ARRAY, substring: function_1.RETURN_STRING, toLowerCase: function_1.RETURN_STRING, toLocaleLowerCase: function_1.RETURN_STRING, toUpperCase: function_1.RETURN_STRING, toLocaleUpperCase: function_1.RETURN_STRING, trim: function_1.RETURN_STRING, substr: function_1.RETURN_STRING, valueOf: function_1.RETURN_STRING, codePointAt: function_1.RETURN_NUMBER, includes: function_1.RETURN_BOOLEAN, endsWith: function_1.RETURN_BOOLEAN, normalize: function_1.RETURN_STRING, repeat: function_1.RETURN_STRING, startsWith: function_1.RETURN_BOOLEAN, anchor: function_1.RETURN_STRING, big: function_1.RETURN_STRING, blink: function_1.RETURN_STRING, bold: function_1.RETURN_STRING, fixed: function_1.RETURN_STRING, fontcolor: function_1.RETURN_STRING, fontsize: function_1.RETURN_STRING, italics: function_1.RETURN_STRING, link: function_1.RETURN_STRING, small: function_1.RETURN_STRING, strike: function_1.RETURN_STRING, sub: function_1.RETURN_STRING, sup: function_1.RETURN_STRING, padStart: function_1.RETURN_STRING, padEnd: function_1.RETURN_STRING, trimLeft: function_1.RETURN_STRING, trimRight: function_1.RETURN_STRING, trimStart: function_1.RETURN_STRING, trimEnd: function_1.RETURN_STRING, matchAll: null, at: function_1.RETURN_STRING, length: number_1.NUMBER, 0: exports.STRING, [Symbol.iterator]: null })));
const getPrototypes = (0, common_1.cache)(() => (0, common_1.createObject)(Object.assign(Object.assign({}, (0, object_1.getObjectPrototypes)()), { toString: function_1.RETURN_STRING, charAt: function_1.RETURN_STRING, charCodeAt: function_1.RETURN_NUMBER, concat: function_1.RETURN_STRING, indexOf: function_1.RETURN_NUMBER, lastIndexOf: function_1.RETURN_NUMBER, localeCompare: function_1.RETURN_NUMBER, match: function_1.RETURN_STRING_ARRAY, replace: function_1.RETURN_STRING, search: function_1.RETURN_NUMBER, slice: function_1.RETURN_STRING, split: function_1.RETURN_STRING_ARRAY, substring: function_1.RETURN_STRING, toLowerCase: function_1.RETURN_STRING, toLocaleLowerCase: function_1.RETURN_STRING, toUpperCase: function_1.RETURN_STRING, toLocaleUpperCase: function_1.RETURN_STRING, trim: function_1.RETURN_STRING, substr: function_1.RETURN_STRING, valueOf: function_1.RETURN_STRING, codePointAt: function_1.RETURN_NUMBER, includes: function_1.RETURN_BOOLEAN, endsWith: function_1.RETURN_BOOLEAN, normalize: function_1.RETURN_STRING, repeat: function_1.RETURN_STRING, startsWith: function_1.RETURN_BOOLEAN, anchor: function_1.RETURN_STRING, big: function_1.RETURN_STRING, blink: function_1.RETURN_STRING, bold: function_1.RETURN_STRING, fixed: function_1.RETURN_STRING, fontcolor: function_1.RETURN_STRING, fontsize: function_1.RETURN_STRING, italics: function_1.RETURN_STRING, link: function_1.RETURN_STRING, small: function_1.RETURN_STRING, strike: function_1.RETURN_STRING, sub: function_1.RETURN_STRING, sup: function_1.RETURN_STRING, padStart: function_1.RETURN_STRING, padEnd: function_1.RETURN_STRING, trimLeft: function_1.RETURN_STRING, trimRight: function_1.RETURN_STRING, trimStart: function_1.RETURN_STRING, trimEnd: function_1.RETURN_STRING, matchAll: null, replaceAll: function_1.RETURN_STRING, at: function_1.RETURN_STRING, length: number_1.NUMBER, 0: exports.STRING, [Symbol.iterator]: null })));
{
"name": "eslint-plugin-regexp",
"version": "2.0.0-next.12",
"version": "2.0.0-next.13",
"description": "ESLint plugin for finding RegExp mistakes and RegExp style guide violations.",

@@ -90,2 +90,3 @@ "engines": {

"eslint-plugin-yml": "^1.0.0",
"intl-segmenter-polyfill": "^0.4.4",
"markdownlint-cli": "^0.37.0",

@@ -109,3 +110,2 @@ "mocha": "^10.0.0",

"comment-parser": "^1.4.0",
"grapheme-splitter": "^1.0.4",
"jsdoctypeparser": "^9.0.0",

@@ -112,0 +112,0 @@ "refa": "^0.12.1",

@@ -26,2 +26,3 @@ # Introduction

- Find hints for writing optimized regular expressions.
- 80 plugin rules for regular expression syntax and features.

@@ -183,2 +184,3 @@ You can check on the [Online DEMO](https://ota-meshi.github.io/eslint-plugin-regexp/playground/).

| :------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------- | :- | :- | :- | :- |
| [grapheme-string-literal](https://ota-meshi.github.io/eslint-plugin-regexp/rules/grapheme-string-literal.html) | enforce single grapheme in string literal | | | | |
| [hexadecimal-escape](https://ota-meshi.github.io/eslint-plugin-regexp/rules/hexadecimal-escape.html) | enforce consistent usage of hexadecimal escape | | | πŸ”§ | |

@@ -185,0 +187,0 @@ | [letter-case](https://ota-meshi.github.io/eslint-plugin-regexp/rules/letter-case.html) | enforce into your favorite case | | | πŸ”§ | |