pasika 0.10.93 → 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 +27 -5
- 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
|
}
|