Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
64
Frontend-Learner/node_modules/eslint-plugin-regexp/dist/rules/no-zero-quantifier.js
generated
vendored
Normal file
64
Frontend-Learner/node_modules/eslint-plugin-regexp/dist/rules/no-zero-quantifier.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const regexp_ast_analysis_1 = require("regexp-ast-analysis");
|
||||
const utils_1 = require("../utils");
|
||||
exports.default = (0, utils_1.createRule)("no-zero-quantifier", {
|
||||
meta: {
|
||||
docs: {
|
||||
description: "disallow quantifiers with a maximum of zero",
|
||||
category: "Best Practices",
|
||||
recommended: true,
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
unexpected: "Unexpected zero quantifier. The quantifier and its quantified element can be removed without affecting the pattern.",
|
||||
withCapturingGroup: "Unexpected zero quantifier. The quantifier and its quantified element do not affecting the pattern. Try to remove the elements but be careful because it contains at least one capturing group.",
|
||||
remove: "Remove this zero quantifier.",
|
||||
},
|
||||
type: "suggestion",
|
||||
hasSuggestions: true,
|
||||
},
|
||||
create(context) {
|
||||
function createVisitor(regexpContext) {
|
||||
const { node, getRegexpLocation, fixReplaceNode, patternAst } = regexpContext;
|
||||
return {
|
||||
onQuantifierEnter(qNode) {
|
||||
if (qNode.max === 0) {
|
||||
const containCapturingGroup = (0, regexp_ast_analysis_1.hasSomeDescendant)(qNode, (n) => n.type === "CapturingGroup");
|
||||
if (containCapturingGroup) {
|
||||
context.report({
|
||||
node,
|
||||
loc: getRegexpLocation(qNode),
|
||||
messageId: "withCapturingGroup",
|
||||
});
|
||||
}
|
||||
else {
|
||||
const suggest = [];
|
||||
if (patternAst.raw === qNode.raw) {
|
||||
suggest.push({
|
||||
messageId: "remove",
|
||||
fix: fixReplaceNode(qNode, "(?:)"),
|
||||
});
|
||||
}
|
||||
else if ((0, utils_1.canUnwrapped)(qNode, "")) {
|
||||
suggest.push({
|
||||
messageId: "remove",
|
||||
fix: fixReplaceNode(qNode, ""),
|
||||
});
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
loc: getRegexpLocation(qNode),
|
||||
messageId: "unexpected",
|
||||
suggest,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
return (0, utils_1.defineRegexpVisitor)(context, {
|
||||
createVisitor,
|
||||
});
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue