pasika 0.10.92 → 0.10.94
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 +61 -10
- package/package.json +1 -1
|
@@ -4508,6 +4508,18 @@ function keyName(key) {
|
|
|
4508
4508
|
function reportFor(context, node, message) {
|
|
4509
4509
|
context.report({ node, message });
|
|
4510
4510
|
}
|
|
4511
|
+
function isLocaleWrapper(node) {
|
|
4512
|
+
return ["TSAsExpression", "TSSatisfiesExpression"].includes(node.type) && "expression" in node && typeof node.expression === "object" && "type" in node.expression;
|
|
4513
|
+
}
|
|
4514
|
+
function localeObject(node) {
|
|
4515
|
+
let current = node;
|
|
4516
|
+
while (current) {
|
|
4517
|
+
if (current.type === "ObjectExpression") return current;
|
|
4518
|
+
if (!isLocaleWrapper(current)) return void 0;
|
|
4519
|
+
current = current.expression;
|
|
4520
|
+
}
|
|
4521
|
+
return void 0;
|
|
4522
|
+
}
|
|
4511
4523
|
function checkKey(context, node, name) {
|
|
4512
4524
|
if (!ENGLISH.test(name)) {
|
|
4513
4525
|
reportFor(
|
|
@@ -4544,13 +4556,22 @@ var localeKeyShapeRule = {
|
|
|
4544
4556
|
},
|
|
4545
4557
|
create(context) {
|
|
4546
4558
|
if (!isLocalesFile(context.filename)) return {};
|
|
4547
|
-
function visitObject(node) {
|
|
4559
|
+
function visitObject(node, namespace) {
|
|
4548
4560
|
for (const property of node.properties) {
|
|
4549
4561
|
if (property.type !== "Property") continue;
|
|
4550
4562
|
const name = keyName(property.key);
|
|
4551
4563
|
if (name === void 0) continue;
|
|
4552
|
-
|
|
4553
|
-
|
|
4564
|
+
const nested = localeObject(property.value);
|
|
4565
|
+
if (nested) {
|
|
4566
|
+
if (namespace !== void 0) {
|
|
4567
|
+
reportFor(
|
|
4568
|
+
context,
|
|
4569
|
+
property,
|
|
4570
|
+
`Locale "${namespace}.${name}" must not be a nested object. Keep string keys directly inside the "${namespace}" feature namespace. See docs/next-codebase-guide/rules/locales-rule.md`
|
|
4571
|
+
);
|
|
4572
|
+
} else {
|
|
4573
|
+
visitObject(nested, name);
|
|
4574
|
+
}
|
|
4554
4575
|
} else if (property.value.type === "Literal" && typeof property.value.value === "string") {
|
|
4555
4576
|
checkKey(context, property, name);
|
|
4556
4577
|
}
|
|
@@ -4559,8 +4580,9 @@ var localeKeyShapeRule = {
|
|
|
4559
4580
|
return {
|
|
4560
4581
|
VariableDeclarator(node) {
|
|
4561
4582
|
if (node.id.type !== "Identifier" || node.id.name !== "locales") return;
|
|
4562
|
-
|
|
4563
|
-
|
|
4583
|
+
const root = localeObject(node.init);
|
|
4584
|
+
if (!root) return;
|
|
4585
|
+
visitObject(root);
|
|
4564
4586
|
}
|
|
4565
4587
|
};
|
|
4566
4588
|
}
|
|
@@ -6489,6 +6511,27 @@ function enumValueResolver(context) {
|
|
|
6489
6511
|
return typeSymbol ? isEnumSymbol(typeSymbol) : localEnumBinding(context, node);
|
|
6490
6512
|
};
|
|
6491
6513
|
}
|
|
6514
|
+
function detachableCallResolver(context) {
|
|
6515
|
+
const services = typedParserServices(context.sourceCode.parserServices);
|
|
6516
|
+
if (!services) return () => false;
|
|
6517
|
+
const checker = services.program.getTypeChecker();
|
|
6518
|
+
const { esTreeNodeToTSNodeMap: nodeMap } = services;
|
|
6519
|
+
const isUnboundFunctionType = (type) => ts9.isFunctionTypeNode(type) && !type.parameters.some((parameter) => ts9.isIdentifier(parameter.name) && parameter.name.text === "this");
|
|
6520
|
+
return (member) => {
|
|
6521
|
+
const node = nodeMap.get(member);
|
|
6522
|
+
if (!node || !ts9.isPropertyAccessExpression(node)) return false;
|
|
6523
|
+
const symbol = checker.getSymbolAtLocation(node.name);
|
|
6524
|
+
const declarations = symbol?.declarations;
|
|
6525
|
+
if (!declarations?.length) return false;
|
|
6526
|
+
return declarations.every((declaration) => {
|
|
6527
|
+
if (ts9.isPropertySignature(declaration) || ts9.isPropertyDeclaration(declaration)) {
|
|
6528
|
+
return declaration.type !== void 0 && isUnboundFunctionType(declaration.type) || ts9.isPropertyDeclaration(declaration) && declaration.initializer !== void 0 && ts9.isArrowFunction(declaration.initializer);
|
|
6529
|
+
}
|
|
6530
|
+
if (ts9.isPropertyAssignment(declaration)) return ts9.isArrowFunction(declaration.initializer);
|
|
6531
|
+
return false;
|
|
6532
|
+
});
|
|
6533
|
+
};
|
|
6534
|
+
}
|
|
6492
6535
|
function directMappingRequiresQualifiedAccess(context, ownershipResolver, member) {
|
|
6493
6536
|
const mapping = renamedDirectMapping(context, member);
|
|
6494
6537
|
if (!mapping || !ownershipResolver) return false;
|
|
@@ -6507,14 +6550,15 @@ function objectUsage(scope, sourceText) {
|
|
|
6507
6550
|
}
|
|
6508
6551
|
return usage;
|
|
6509
6552
|
}
|
|
6510
|
-
function memberIsRead(context, member) {
|
|
6553
|
+
function memberIsRead(context, member, detachableCall) {
|
|
6511
6554
|
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6512
6555
|
if (!parent) return true;
|
|
6513
6556
|
if (parent.type === "AssignmentExpression" && parent.left === member) return false;
|
|
6514
6557
|
if (parent.type === "UpdateExpression" && parent.argument === member) return false;
|
|
6515
6558
|
if (parent.type === "UnaryExpression" && parent.operator === "delete" && parent.argument === member) return false;
|
|
6516
6559
|
if ((parent.type === "ForInStatement" || parent.type === "ForOfStatement") && parent.left === member) return false;
|
|
6517
|
-
if (
|
|
6560
|
+
if (parent.type === "CallExpression" && parent.callee === member) return detachableCall(member);
|
|
6561
|
+
if (parent.type === "NewExpression" && parent.callee === member) return false;
|
|
6518
6562
|
if (parent.type === "TaggedTemplateExpression" && parent.tag === member) return false;
|
|
6519
6563
|
return true;
|
|
6520
6564
|
}
|
|
@@ -6522,10 +6566,10 @@ function memberIsDirectVariableInitializer(context, member) {
|
|
|
6522
6566
|
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6523
6567
|
return parent?.type === "VariableDeclarator" && parent.init === member;
|
|
6524
6568
|
}
|
|
6525
|
-
function recordMemberUsage(context, scope, ownershipResolver, member, isEnumValue) {
|
|
6569
|
+
function recordMemberUsage(context, scope, ownershipResolver, member, isEnumValue, detachableCall) {
|
|
6526
6570
|
if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
|
|
6527
6571
|
if (!memberCanBeDestructured(context, ownershipResolver, member, isEnumValue)) return;
|
|
6528
|
-
if (!isGroupedUsageSource(member.object) || !memberIsRead(context, member)) return;
|
|
6572
|
+
if (!isGroupedUsageSource(member.object) || !memberIsRead(context, member, detachableCall)) return;
|
|
6529
6573
|
const sourceText = context.sourceCode.getText(member.object);
|
|
6530
6574
|
const usage = objectUsage(scope, sourceText);
|
|
6531
6575
|
const propertyName5 = member.property.name;
|
|
@@ -6698,6 +6742,7 @@ var preferObjectDestructuringRule = {
|
|
|
6698
6742
|
create(context) {
|
|
6699
6743
|
const ownershipResolver = contractOwnershipResolver(context);
|
|
6700
6744
|
const isEnumValue = enumValueResolver(context);
|
|
6745
|
+
const detachableCall = detachableCallResolver(context);
|
|
6701
6746
|
const grouped = /* @__PURE__ */ new Set();
|
|
6702
6747
|
const usageScopes = [];
|
|
6703
6748
|
const currentUsageScope = () => usageScopes.at(-1);
|
|
@@ -6726,6 +6771,12 @@ var preferObjectDestructuringRule = {
|
|
|
6726
6771
|
node: firstDirectMember,
|
|
6727
6772
|
message: scopeUsageMessage(sourceText, usage.propertyNames),
|
|
6728
6773
|
fix(fixer) {
|
|
6774
|
+
if (usage.directMembers.some(({ member }) => {
|
|
6775
|
+
const parent = context.sourceCode.getAncestors(member).at(-1);
|
|
6776
|
+
return parent?.type === "CallExpression" && parent.callee === member;
|
|
6777
|
+
})) {
|
|
6778
|
+
return null;
|
|
6779
|
+
}
|
|
6729
6780
|
const memberFixes = usage.directMembers.map(
|
|
6730
6781
|
({ member, propertyName: propertyName5 }) => fixer.replaceText(member, propertyName5)
|
|
6731
6782
|
);
|
|
@@ -6787,7 +6838,7 @@ ${indentation}`;
|
|
|
6787
6838
|
ArrowFunctionExpression: enterUsageBarrier,
|
|
6788
6839
|
"ArrowFunctionExpression:exit": exitUsageScope,
|
|
6789
6840
|
MemberExpression(node) {
|
|
6790
|
-
recordMemberUsage(context, currentUsageScope(), ownershipResolver, node, isEnumValue);
|
|
6841
|
+
recordMemberUsage(context, currentUsageScope(), ownershipResolver, node, isEnumValue, detachableCall);
|
|
6791
6842
|
},
|
|
6792
6843
|
VariableDeclaration(node) {
|
|
6793
6844
|
for (const declarator of node.declarations) {
|