pasika 0.10.60 → 0.10.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint/pasika/index.js +42 -1
- package/package.json +1 -1
|
@@ -5027,6 +5027,42 @@ function objectPropertyMessage(propertyName4, source, identifierValue) {
|
|
|
5027
5027
|
if (source === propertyName4) return `Use property shorthand for "${propertyName4}". ${DOC4}`;
|
|
5028
5028
|
return `"${propertyName4}" maps the local "${source}" inline. Rename the producer to "${propertyName4}" and use property shorthand. ${DOC4}`;
|
|
5029
5029
|
}
|
|
5030
|
+
function findVariable(context, node) {
|
|
5031
|
+
let scope = context.sourceCode.getScope(node);
|
|
5032
|
+
while (scope) {
|
|
5033
|
+
const variable = scope.set.get(node.name);
|
|
5034
|
+
if (variable) return variable;
|
|
5035
|
+
scope = scope.upper;
|
|
5036
|
+
}
|
|
5037
|
+
return void 0;
|
|
5038
|
+
}
|
|
5039
|
+
function isExportedVariable2(context, variable) {
|
|
5040
|
+
return variable.defs.some(
|
|
5041
|
+
(definition) => definition.type === "Variable" && context.sourceCode.getAncestors(definition.parent).at(-1)?.type === "ExportNamedDeclaration"
|
|
5042
|
+
);
|
|
5043
|
+
}
|
|
5044
|
+
function canRenameIdentifierProducer(context, node) {
|
|
5045
|
+
const variable = findVariable(context, node);
|
|
5046
|
+
if (!variable || isExportedVariable2(context, variable)) return false;
|
|
5047
|
+
const definition = variable.defs[0];
|
|
5048
|
+
if (!definition || variable.defs.length !== 1) return false;
|
|
5049
|
+
if (definition.type === "ImportBinding") return false;
|
|
5050
|
+
if (definition.type === "Variable" && definition.parent.kind !== "const") return false;
|
|
5051
|
+
if (definition.type !== "Variable" && definition.type !== "Parameter") return false;
|
|
5052
|
+
return variable.references.filter((reference) => reference.isRead()).length === 1;
|
|
5053
|
+
}
|
|
5054
|
+
function memberRootIdentifier(node) {
|
|
5055
|
+
let current = node;
|
|
5056
|
+
while (current.type === "MemberExpression") current = current.object;
|
|
5057
|
+
return current.type === "Identifier" ? current : void 0;
|
|
5058
|
+
}
|
|
5059
|
+
function canBindMemberExpression(context, node) {
|
|
5060
|
+
const root = memberRootIdentifier(node);
|
|
5061
|
+
if (!root) return true;
|
|
5062
|
+
if (/^[A-Z]/u.test(root.name)) return false;
|
|
5063
|
+
const variable = findVariable(context, root);
|
|
5064
|
+
return !variable?.defs.some((definition) => definition.type === "ImportBinding");
|
|
5065
|
+
}
|
|
5030
5066
|
var noRedundantAliasRule = {
|
|
5031
5067
|
meta: {
|
|
5032
5068
|
schema: [],
|
|
@@ -5054,7 +5090,12 @@ var noRedundantAliasRule = {
|
|
|
5054
5090
|
if (node.value.type !== "Identifier" && node.value.type !== "MemberExpression") return;
|
|
5055
5091
|
const propertyName4 = node.key.name;
|
|
5056
5092
|
const source = context.sourceCode.getText(node.value);
|
|
5057
|
-
if (node.value.type === "Identifier"
|
|
5093
|
+
if (node.value.type === "Identifier") {
|
|
5094
|
+
if (node.shorthand) return;
|
|
5095
|
+
if (source !== propertyName4 && !canRenameIdentifierProducer(context, node.value)) return;
|
|
5096
|
+
} else if (!canBindMemberExpression(context, node.value)) {
|
|
5097
|
+
return;
|
|
5098
|
+
}
|
|
5058
5099
|
context.report({
|
|
5059
5100
|
node,
|
|
5060
5101
|
message: objectPropertyMessage(propertyName4, source, node.value.type === "Identifier")
|