pasika 0.10.74 → 0.10.75
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 +89 -1
- package/package.json +1 -1
|
@@ -6092,6 +6092,62 @@ function directPropertyBinding(context, declarator) {
|
|
|
6092
6092
|
function canGroupSource(source) {
|
|
6093
6093
|
return source.type === "Identifier" || source.type === "ThisExpression";
|
|
6094
6094
|
}
|
|
6095
|
+
function isStableObjectSource(source) {
|
|
6096
|
+
if (source.type === "Identifier" || source.type === "ThisExpression") return true;
|
|
6097
|
+
if (source.type !== "MemberExpression") return false;
|
|
6098
|
+
if (source.computed || source.optional || source.property.type !== "Identifier") return false;
|
|
6099
|
+
return isStableObjectSource(source.object);
|
|
6100
|
+
}
|
|
6101
|
+
function objectUsage(scope, sourceText) {
|
|
6102
|
+
let usage = scope.objects.get(sourceText);
|
|
6103
|
+
if (!usage) {
|
|
6104
|
+
usage = { propertyNames: /* @__PURE__ */ new Set(), directMembers: /* @__PURE__ */ new Map() };
|
|
6105
|
+
scope.objects.set(sourceText, usage);
|
|
6106
|
+
}
|
|
6107
|
+
return usage;
|
|
6108
|
+
}
|
|
6109
|
+
function memberIsRead(context, member) {
|
|
6110
|
+
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6111
|
+
if (!parent) return true;
|
|
6112
|
+
if (parent.type === "AssignmentExpression" && parent.left === member) return false;
|
|
6113
|
+
if (parent.type === "UpdateExpression" && parent.argument === member) return false;
|
|
6114
|
+
if (parent.type === "UnaryExpression" && parent.operator === "delete" && parent.argument === member) return false;
|
|
6115
|
+
if ((parent.type === "ForInStatement" || parent.type === "ForOfStatement") && parent.left === member) return false;
|
|
6116
|
+
if ((parent.type === "CallExpression" || parent.type === "NewExpression") && parent.callee === member) return false;
|
|
6117
|
+
if (parent.type === "TaggedTemplateExpression" && parent.tag === member) return false;
|
|
6118
|
+
return true;
|
|
6119
|
+
}
|
|
6120
|
+
function memberIsDirectVariableInitializer(context, member) {
|
|
6121
|
+
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6122
|
+
return parent?.type === "VariableDeclarator" && parent.init === member;
|
|
6123
|
+
}
|
|
6124
|
+
function recordMemberUsage(context, scope, member) {
|
|
6125
|
+
if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
|
|
6126
|
+
if (!isStableObjectSource(member.object) || !memberIsRead(context, member)) return;
|
|
6127
|
+
const sourceText = context.sourceCode.getText(member.object);
|
|
6128
|
+
const usage = objectUsage(scope, sourceText);
|
|
6129
|
+
const propertyName5 = member.property.name;
|
|
6130
|
+
usage.propertyNames.add(propertyName5);
|
|
6131
|
+
if (!memberIsDirectVariableInitializer(context, member) && !usage.directMembers.has(propertyName5)) {
|
|
6132
|
+
usage.directMembers.set(propertyName5, member);
|
|
6133
|
+
}
|
|
6134
|
+
}
|
|
6135
|
+
function recordDestructuringUsage(context, scope, declaration) {
|
|
6136
|
+
if (!scope) return;
|
|
6137
|
+
for (const declarator of declaration.declarations) {
|
|
6138
|
+
if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isStableObjectSource(declarator.init)) continue;
|
|
6139
|
+
const sourceText = context.sourceCode.getText(declarator.init);
|
|
6140
|
+
const usage = objectUsage(scope, sourceText);
|
|
6141
|
+
for (const property of declarator.id.properties) {
|
|
6142
|
+
if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
|
|
6143
|
+
usage.propertyNames.add(property.key.name);
|
|
6144
|
+
}
|
|
6145
|
+
}
|
|
6146
|
+
}
|
|
6147
|
+
function scopeUsageMessage(sourceText, propertyNames) {
|
|
6148
|
+
const names = [...propertyNames].map((name) => `"${name}"`).join(", ");
|
|
6149
|
+
return `${names} are read from "${sourceText}" in the same block. Destructure them together in one declaration. ${DOC5}`;
|
|
6150
|
+
}
|
|
6095
6151
|
function whitespaceKeepsStatementsAdjacent(text) {
|
|
6096
6152
|
if (text.trim() !== "") return false;
|
|
6097
6153
|
return (text.match(/\n/gu) ?? []).length <= 1;
|
|
@@ -6202,13 +6258,45 @@ var preferObjectDestructuringRule = {
|
|
|
6202
6258
|
type: "problem",
|
|
6203
6259
|
fixable: "code",
|
|
6204
6260
|
docs: {
|
|
6205
|
-
description: "Require
|
|
6261
|
+
description: "Require related object-property reads to use one object destructuring declaration."
|
|
6206
6262
|
}
|
|
6207
6263
|
},
|
|
6208
6264
|
create(context) {
|
|
6209
6265
|
const grouped = /* @__PURE__ */ new Set();
|
|
6266
|
+
const usageScopes = [];
|
|
6267
|
+
const currentUsageScope = () => usageScopes.at(-1);
|
|
6268
|
+
const enterUsageScope = () => {
|
|
6269
|
+
usageScopes.push({ objects: /* @__PURE__ */ new Map() });
|
|
6270
|
+
};
|
|
6271
|
+
const exitUsageScope = () => {
|
|
6272
|
+
const scope = usageScopes.pop();
|
|
6273
|
+
if (!scope) return;
|
|
6274
|
+
for (const [sourceText, usage] of scope.objects) {
|
|
6275
|
+
if (usage.propertyNames.size < 2 || usage.directMembers.size === 0) continue;
|
|
6276
|
+
const firstDirectMember = usage.directMembers.values().next().value;
|
|
6277
|
+
if (!firstDirectMember) continue;
|
|
6278
|
+
context.report({
|
|
6279
|
+
node: firstDirectMember,
|
|
6280
|
+
message: scopeUsageMessage(sourceText, usage.propertyNames)
|
|
6281
|
+
});
|
|
6282
|
+
}
|
|
6283
|
+
};
|
|
6210
6284
|
return {
|
|
6285
|
+
Program: enterUsageScope,
|
|
6286
|
+
"Program:exit": exitUsageScope,
|
|
6287
|
+
BlockStatement: enterUsageScope,
|
|
6288
|
+
"BlockStatement:exit": exitUsageScope,
|
|
6289
|
+
FunctionDeclaration: enterUsageScope,
|
|
6290
|
+
"FunctionDeclaration:exit": exitUsageScope,
|
|
6291
|
+
FunctionExpression: enterUsageScope,
|
|
6292
|
+
"FunctionExpression:exit": exitUsageScope,
|
|
6293
|
+
ArrowFunctionExpression: enterUsageScope,
|
|
6294
|
+
"ArrowFunctionExpression:exit": exitUsageScope,
|
|
6295
|
+
MemberExpression(node) {
|
|
6296
|
+
recordMemberUsage(context, currentUsageScope(), node);
|
|
6297
|
+
},
|
|
6211
6298
|
VariableDeclaration(node) {
|
|
6299
|
+
recordDestructuringUsage(context, currentUsageScope(), node);
|
|
6212
6300
|
if (grouped.has(node)) return;
|
|
6213
6301
|
const selection = destructuringSelection(context, node);
|
|
6214
6302
|
if (selection) {
|