pasika 0.10.76 → 0.10.77
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 +140 -28
- package/package.json +1 -1
|
@@ -5096,6 +5096,15 @@ var ContractOwnershipIndex = class {
|
|
|
5096
5096
|
if (typeDeclarations.length === 0) return { kind: "missing", ownership: "unknown" };
|
|
5097
5097
|
return this.endpointFromDeclarations(typeDeclarations);
|
|
5098
5098
|
}
|
|
5099
|
+
sourceBinding(node, name) {
|
|
5100
|
+
if (!ts7.isVariableDeclaration(node) || !node.initializer) {
|
|
5101
|
+
return { kind: "missing", ownership: "unknown" };
|
|
5102
|
+
}
|
|
5103
|
+
const sourceType = this.checker.getTypeAtLocation(node.initializer);
|
|
5104
|
+
const declarations = this.propertyDeclarations(sourceType, name);
|
|
5105
|
+
if (declarations.length === 0) return { kind: "missing", ownership: "unknown" };
|
|
5106
|
+
return this.endpointFromDeclarations(declarations);
|
|
5107
|
+
}
|
|
5099
5108
|
targetProperty(node, name) {
|
|
5100
5109
|
if (!ts7.isPropertyAssignment(node) && !ts7.isShorthandPropertyAssignment(node)) {
|
|
5101
5110
|
return { kind: "missing", ownership: "unknown" };
|
|
@@ -5314,6 +5323,10 @@ function contractOwnershipResolver(context) {
|
|
|
5314
5323
|
const tsNode = nodeMap.get(node);
|
|
5315
5324
|
return tsNode ? index.sourceMember(tsNode) : { kind: "missing", ownership: "unknown" };
|
|
5316
5325
|
},
|
|
5326
|
+
sourceBinding(node, name) {
|
|
5327
|
+
const tsNode = nodeMap.get(node);
|
|
5328
|
+
return tsNode ? index.sourceBinding(tsNode, name) : { kind: "missing", ownership: "unknown" };
|
|
5329
|
+
},
|
|
5317
5330
|
targetProperty(node, name) {
|
|
5318
5331
|
const tsNode = nodeMap.get(node);
|
|
5319
5332
|
return tsNode ? index.targetProperty(tsNode, name) : { kind: "missing", ownership: "unknown" };
|
|
@@ -5398,6 +5411,48 @@ function semanticMappingMessage(propertyName5, sourcePropertyName) {
|
|
|
5398
5411
|
function unknownContractOwnershipMessage(propertyName5, sourcePropertyName) {
|
|
5399
5412
|
return `Cannot determine contract ownership for mapping "${propertyName5}" from "${sourcePropertyName}". Define or propagate a concrete contract, make the boundary schema explicit, or connect a mirrored external schema to its defineApiContract. ${DOC4}`;
|
|
5400
5413
|
}
|
|
5414
|
+
function destructuredBindingSource(context, identifier) {
|
|
5415
|
+
const initialScope = context.sourceCode.getScope(identifier);
|
|
5416
|
+
for (let scope = initialScope; scope !== null; scope = scope.upper) {
|
|
5417
|
+
const variable = scope.variables.find(({ name }) => name === identifier.name);
|
|
5418
|
+
if (!variable) continue;
|
|
5419
|
+
for (const definition of variable.defs) {
|
|
5420
|
+
if (definition.type !== "Variable") continue;
|
|
5421
|
+
const declarator = definition.node;
|
|
5422
|
+
if (declarator.id.type !== "ObjectPattern") continue;
|
|
5423
|
+
for (const property of declarator.id.properties) {
|
|
5424
|
+
if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
|
|
5425
|
+
let binding;
|
|
5426
|
+
if (property.value.type === "Identifier") binding = property.value;
|
|
5427
|
+
if (property.value.type === "AssignmentPattern" && property.value.left.type === "Identifier") {
|
|
5428
|
+
binding = property.value.left;
|
|
5429
|
+
}
|
|
5430
|
+
if (binding?.name === identifier.name) {
|
|
5431
|
+
return { declarator, propertyName: property.key.name };
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
return void 0;
|
|
5436
|
+
}
|
|
5437
|
+
return void 0;
|
|
5438
|
+
}
|
|
5439
|
+
function contractMappingViolation(propertyName5, sourcePropertyName, sourceResolution, targetResolution) {
|
|
5440
|
+
if (sourceResolution.kind === "non-contract" || targetResolution.kind === "non-contract") return void 0;
|
|
5441
|
+
if ((sourceResolution.ownership === "third-party" || sourceResolution.ownership === "platform") && targetResolution.kind !== "missing") {
|
|
5442
|
+
return void 0;
|
|
5443
|
+
}
|
|
5444
|
+
if ((targetResolution.ownership === "third-party" || targetResolution.ownership === "platform") && sourceResolution.kind !== "missing") {
|
|
5445
|
+
return void 0;
|
|
5446
|
+
}
|
|
5447
|
+
const hasDataContract = sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
|
|
5448
|
+
if (!hasDataContract) return void 0;
|
|
5449
|
+
if (sourceResolution.kind === "missing" || targetResolution.kind === "missing" || sourceResolution.ownership === "unknown" || targetResolution.ownership === "unknown") {
|
|
5450
|
+
return unknownContractOwnershipMessage(propertyName5, sourcePropertyName);
|
|
5451
|
+
}
|
|
5452
|
+
if (sourceResolution.kind !== "data-contract") return void 0;
|
|
5453
|
+
if (sourceResolution.ownership !== "first-party" || targetResolution.ownership !== "first-party") return void 0;
|
|
5454
|
+
return semanticMappingMessage(propertyName5, sourcePropertyName);
|
|
5455
|
+
}
|
|
5401
5456
|
var noRedundantAliasRule = {
|
|
5402
5457
|
meta: {
|
|
5403
5458
|
schema: [],
|
|
@@ -5464,12 +5519,28 @@ var noRedundantAliasRule = {
|
|
|
5464
5519
|
if (node.value.type === "Identifier") {
|
|
5465
5520
|
if (node.shorthand) return;
|
|
5466
5521
|
const source = node.value.name;
|
|
5522
|
+
if (propertyName5 === source) {
|
|
5523
|
+
context.report({
|
|
5524
|
+
node,
|
|
5525
|
+
message: objectPropertyMessage(propertyName5, source),
|
|
5526
|
+
fix(fixer) {
|
|
5527
|
+
return fixer.replaceText(node, propertyName5);
|
|
5528
|
+
}
|
|
5529
|
+
});
|
|
5530
|
+
return;
|
|
5531
|
+
}
|
|
5532
|
+
const bindingSource = destructuredBindingSource(context, node.value);
|
|
5533
|
+
if (!bindingSource || !ownershipResolver) return;
|
|
5534
|
+
const sourcePropertyName2 = bindingSource.propertyName;
|
|
5535
|
+
if (normalizePropertyName(propertyName5) === normalizePropertyName(sourcePropertyName2)) return;
|
|
5536
|
+
if (FRAMEWORK_MAPPING_KEYS.has(propertyName5) || isNamedMemberValue(sourcePropertyName2)) return;
|
|
5537
|
+
const sourceResolution2 = ownershipResolver.sourceBinding(bindingSource.declarator, sourcePropertyName2);
|
|
5538
|
+
const targetResolution2 = ownershipResolver.targetProperty(node, propertyName5);
|
|
5539
|
+
const hasDataContract = sourceResolution2.kind === "data-contract" || targetResolution2.kind === "data-contract";
|
|
5540
|
+
if (!hasDataContract) return;
|
|
5467
5541
|
context.report({
|
|
5468
5542
|
node,
|
|
5469
|
-
message: objectPropertyMessage(propertyName5, source)
|
|
5470
|
-
fix(fixer) {
|
|
5471
|
-
return propertyName5 === source ? fixer.replaceText(node, propertyName5) : null;
|
|
5472
|
-
}
|
|
5543
|
+
message: contractMappingViolation(propertyName5, sourcePropertyName2, sourceResolution2, targetResolution2) ?? objectPropertyMessage(propertyName5, source)
|
|
5473
5544
|
});
|
|
5474
5545
|
return;
|
|
5475
5546
|
}
|
|
@@ -5482,27 +5553,16 @@ var noRedundantAliasRule = {
|
|
|
5482
5553
|
if (!ownershipResolver) return;
|
|
5483
5554
|
const sourceResolution = ownershipResolver.sourceMember(node.value);
|
|
5484
5555
|
const targetResolution = ownershipResolver.targetProperty(node, propertyName5);
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
const hasDataContract = sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
|
|
5493
|
-
if (!hasDataContract) return;
|
|
5494
|
-
if (sourceResolution.kind === "missing" || targetResolution.kind === "missing" || sourceResolution.ownership === "unknown" || targetResolution.ownership === "unknown") {
|
|
5495
|
-
context.report({
|
|
5496
|
-
node,
|
|
5497
|
-
message: unknownContractOwnershipMessage(propertyName5, sourcePropertyName)
|
|
5498
|
-
});
|
|
5499
|
-
return;
|
|
5500
|
-
}
|
|
5501
|
-
if (sourceResolution.kind !== "data-contract") return;
|
|
5502
|
-
if (sourceResolution.ownership !== "first-party" || targetResolution.ownership !== "first-party") return;
|
|
5556
|
+
const violation = contractMappingViolation(
|
|
5557
|
+
propertyName5,
|
|
5558
|
+
sourcePropertyName,
|
|
5559
|
+
sourceResolution,
|
|
5560
|
+
targetResolution
|
|
5561
|
+
);
|
|
5562
|
+
if (!violation) return;
|
|
5503
5563
|
context.report({
|
|
5504
5564
|
node,
|
|
5505
|
-
message:
|
|
5565
|
+
message: violation
|
|
5506
5566
|
});
|
|
5507
5567
|
},
|
|
5508
5568
|
TSTypeAliasDeclaration(node) {
|
|
@@ -6073,6 +6133,7 @@ function directPropertyBinding(context, declarator) {
|
|
|
6073
6133
|
if (declarator.init?.type !== "MemberExpression") return void 0;
|
|
6074
6134
|
const member = declarator.init;
|
|
6075
6135
|
if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
|
|
6136
|
+
if (!memberCanBecomeLocal(member)) return void 0;
|
|
6076
6137
|
if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
|
|
6077
6138
|
const propertyName5 = member.property.name;
|
|
6078
6139
|
const localName = declarator.id.name;
|
|
@@ -6098,6 +6159,52 @@ function isStableObjectSource(source) {
|
|
|
6098
6159
|
if (source.computed || source.optional || source.property.type !== "Identifier") return false;
|
|
6099
6160
|
return isStableObjectSource(source.object);
|
|
6100
6161
|
}
|
|
6162
|
+
function rootIdentifierName(node) {
|
|
6163
|
+
if (node.type === "Identifier") return node.name;
|
|
6164
|
+
if (node.type !== "MemberExpression" || node.object.type === "Super") return void 0;
|
|
6165
|
+
return rootIdentifierName(node.object);
|
|
6166
|
+
}
|
|
6167
|
+
function isCompliantLocalName(propertyName5) {
|
|
6168
|
+
return !propertyName5.includes("_");
|
|
6169
|
+
}
|
|
6170
|
+
function propertyNameOf(node) {
|
|
6171
|
+
if (node.type !== "Property" || node.computed) return void 0;
|
|
6172
|
+
if (node.key.type === "Identifier") return node.key.name;
|
|
6173
|
+
if (node.key.type === "Literal" && typeof node.key.value === "string") return node.key.value;
|
|
6174
|
+
return void 0;
|
|
6175
|
+
}
|
|
6176
|
+
function renamedDirectMapping(context, member) {
|
|
6177
|
+
let current = member;
|
|
6178
|
+
const ancestors = context.sourceCode.getAncestors(member);
|
|
6179
|
+
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
6180
|
+
const parent = ancestors[index];
|
|
6181
|
+
if (!parent) break;
|
|
6182
|
+
if (parent.type === "MemberExpression" && parent.object === current) {
|
|
6183
|
+
current = parent;
|
|
6184
|
+
continue;
|
|
6185
|
+
}
|
|
6186
|
+
if (parent.type !== "Property" || parent.value !== current) return void 0;
|
|
6187
|
+
const targetName = propertyNameOf(parent);
|
|
6188
|
+
const sourceName = !current.computed && current.property.type === "Identifier" ? current.property.name : void 0;
|
|
6189
|
+
if (targetName === void 0 || sourceName === void 0 || targetName === sourceName) return void 0;
|
|
6190
|
+
return { property: parent, sourceMember: current, targetName };
|
|
6191
|
+
}
|
|
6192
|
+
return void 0;
|
|
6193
|
+
}
|
|
6194
|
+
function memberCanBecomeLocal(member) {
|
|
6195
|
+
if (rootIdentifierName(member) === "locales") return false;
|
|
6196
|
+
return member.property.type === "Identifier" && isCompliantLocalName(member.property.name);
|
|
6197
|
+
}
|
|
6198
|
+
function directMappingRequiresQualifiedAccess(context, ownershipResolver, member) {
|
|
6199
|
+
const mapping = renamedDirectMapping(context, member);
|
|
6200
|
+
if (!mapping || !ownershipResolver) return false;
|
|
6201
|
+
const sourceResolution = ownershipResolver.sourceMember(mapping.sourceMember);
|
|
6202
|
+
const targetResolution = ownershipResolver.targetProperty(mapping.property, mapping.targetName);
|
|
6203
|
+
return sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
|
|
6204
|
+
}
|
|
6205
|
+
function memberCanBeDestructured(context, ownershipResolver, member) {
|
|
6206
|
+
return memberCanBecomeLocal(member) && !directMappingRequiresQualifiedAccess(context, ownershipResolver, member);
|
|
6207
|
+
}
|
|
6101
6208
|
function objectUsage(scope, sourceText) {
|
|
6102
6209
|
let usage = scope.objects.get(sourceText);
|
|
6103
6210
|
if (!usage) {
|
|
@@ -6121,8 +6228,9 @@ function memberIsDirectVariableInitializer(context, member) {
|
|
|
6121
6228
|
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6122
6229
|
return parent?.type === "VariableDeclarator" && parent.init === member;
|
|
6123
6230
|
}
|
|
6124
|
-
function recordMemberUsage(context, scope, member) {
|
|
6231
|
+
function recordMemberUsage(context, scope, ownershipResolver, member) {
|
|
6125
6232
|
if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
|
|
6233
|
+
if (!memberCanBeDestructured(context, ownershipResolver, member)) return;
|
|
6126
6234
|
if (!isStableObjectSource(member.object) || !memberIsRead(context, member)) return;
|
|
6127
6235
|
const sourceText = context.sourceCode.getText(member.object);
|
|
6128
6236
|
const usage = objectUsage(scope, sourceText);
|
|
@@ -6136,11 +6244,13 @@ function recordDestructuringUsage(context, scope, declaration) {
|
|
|
6136
6244
|
if (!scope) return;
|
|
6137
6245
|
for (const declarator of declaration.declarations) {
|
|
6138
6246
|
if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isStableObjectSource(declarator.init)) continue;
|
|
6247
|
+
if (rootIdentifierName(declarator.init) === "locales") continue;
|
|
6139
6248
|
const sourceText = context.sourceCode.getText(declarator.init);
|
|
6140
6249
|
const usage = objectUsage(scope, sourceText);
|
|
6141
6250
|
const propertyNames = /* @__PURE__ */ new Set();
|
|
6142
6251
|
for (const property of declarator.id.properties) {
|
|
6143
6252
|
if (property.type !== "Property" || property.computed || property.key.type !== "Identifier") continue;
|
|
6253
|
+
if (!isCompliantLocalName(property.key.name)) continue;
|
|
6144
6254
|
propertyNames.add(property.key.name);
|
|
6145
6255
|
usage.propertyNames.add(property.key.name);
|
|
6146
6256
|
}
|
|
@@ -6212,12 +6322,13 @@ function destructuringSelection(context, declaration) {
|
|
|
6212
6322
|
if (declaration.declarations.length !== 1) return void 0;
|
|
6213
6323
|
const declarator = declaration.declarations[0];
|
|
6214
6324
|
if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
|
|
6325
|
+
if (rootIdentifierName(declarator.init) === "locales") return void 0;
|
|
6215
6326
|
if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
|
|
6216
6327
|
const bindingTexts = [];
|
|
6217
6328
|
const localNames = [];
|
|
6218
6329
|
const propertyNames = [];
|
|
6219
6330
|
for (const property of declarator.id.properties) {
|
|
6220
|
-
if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
|
|
6331
|
+
if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || !isCompliantLocalName(property.key.name) || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
|
|
6221
6332
|
return void 0;
|
|
6222
6333
|
}
|
|
6223
6334
|
bindingTexts.push(context.sourceCode.getText(property));
|
|
@@ -6286,6 +6397,7 @@ var preferObjectDestructuringRule = {
|
|
|
6286
6397
|
}
|
|
6287
6398
|
},
|
|
6288
6399
|
create(context) {
|
|
6400
|
+
const ownershipResolver = contractOwnershipResolver(context);
|
|
6289
6401
|
const grouped = /* @__PURE__ */ new Set();
|
|
6290
6402
|
const usageScopes = [];
|
|
6291
6403
|
const currentUsageScope = () => usageScopes.at(-1);
|
|
@@ -6347,7 +6459,7 @@ ${indentation}`;
|
|
|
6347
6459
|
ArrowFunctionExpression: enterUsageScope,
|
|
6348
6460
|
"ArrowFunctionExpression:exit": exitUsageScope,
|
|
6349
6461
|
MemberExpression(node) {
|
|
6350
|
-
recordMemberUsage(context, currentUsageScope(), node);
|
|
6462
|
+
recordMemberUsage(context, currentUsageScope(), ownershipResolver, node);
|
|
6351
6463
|
},
|
|
6352
6464
|
VariableDeclaration(node) {
|
|
6353
6465
|
recordDestructuringUsage(context, currentUsageScope(), node);
|
|
@@ -7111,7 +7223,7 @@ import path49 from "path";
|
|
|
7111
7223
|
function isCamelCase(name) {
|
|
7112
7224
|
return /^[a-z][a-zA-Z0-9]*$/.test(name);
|
|
7113
7225
|
}
|
|
7114
|
-
function
|
|
7226
|
+
function rootIdentifierName2(node) {
|
|
7115
7227
|
let current = node;
|
|
7116
7228
|
for (; ; ) {
|
|
7117
7229
|
if (current.type === "Identifier") return current.name;
|
|
@@ -7156,7 +7268,7 @@ var schemaCasingRule = {
|
|
|
7156
7268
|
const container = declaration.parent;
|
|
7157
7269
|
const isModuleLevel = container.type === "Program" || container.type === "ExportNamedDeclaration" && container.parent.type === "Program";
|
|
7158
7270
|
if (!isModuleLevel) return;
|
|
7159
|
-
if (!node.init ||
|
|
7271
|
+
if (!node.init || rootIdentifierName2(node.init) !== zodLocalName) return;
|
|
7160
7272
|
const { name } = node.id;
|
|
7161
7273
|
if (isCamelCase(name)) return;
|
|
7162
7274
|
context.report({
|