Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
53
Frontend-Learner/node_modules/eslint-plugin-regexp/dist/rules/grapheme-string-literal.js
generated
vendored
Normal file
53
Frontend-Learner/node_modules/eslint-plugin-regexp/dist/rules/grapheme-string-literal.js
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("../utils");
|
||||
const segmenter = new Intl.Segmenter();
|
||||
exports.default = (0, utils_1.createRule)("grapheme-string-literal", {
|
||||
meta: {
|
||||
docs: {
|
||||
description: "enforce single grapheme in string literal",
|
||||
category: "Stylistic Issues",
|
||||
recommended: false,
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
onlySingleCharacters: "Only single characters and graphemes are allowed inside character classes. Use regular alternatives (e.g. `{{alternatives}}`) for strings instead.",
|
||||
},
|
||||
type: "suggestion",
|
||||
},
|
||||
create(context) {
|
||||
function createVisitor(regexpContext) {
|
||||
const { node, getRegexpLocation } = regexpContext;
|
||||
function isMultipleGraphemes(saNode) {
|
||||
if (saNode.elements.length <= 1)
|
||||
return false;
|
||||
const string = String.fromCodePoint(...saNode.elements.map((element) => element.value));
|
||||
const segments = [...segmenter.segment(string)];
|
||||
return segments.length > 1;
|
||||
}
|
||||
function buildAlternativeExample(saNode) {
|
||||
const alternativeRaws = saNode.parent.alternatives
|
||||
.filter(isMultipleGraphemes)
|
||||
.map((alt) => alt.raw);
|
||||
return `(?:${alternativeRaws.join("|")}|[...])`;
|
||||
}
|
||||
return {
|
||||
onStringAlternativeEnter(saNode) {
|
||||
if (!isMultipleGraphemes(saNode))
|
||||
return;
|
||||
context.report({
|
||||
node,
|
||||
loc: getRegexpLocation(saNode),
|
||||
messageId: "onlySingleCharacters",
|
||||
data: {
|
||||
alternatives: buildAlternativeExample(saNode),
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
return (0, utils_1.defineRegexpVisitor)(context, {
|
||||
createVisitor,
|
||||
});
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue