@noctcore/eslint-plugin-contracts 0.3.0 → 0.5.0
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/README.md +3 -2
- package/dist/index.cjs +714 -21
- package/dist/index.d.cts +175 -1
- package/dist/index.d.ts +175 -1
- package/dist/index.js +707 -20
- package/docs/rules/translation-key-exists.md +155 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,13 +9,14 @@ var recommended = {
|
|
|
9
9
|
"noctcore-contracts/restrict-throw-to-taxonomy": "error",
|
|
10
10
|
"noctcore-contracts/schema-enum-field-consistency": "error",
|
|
11
11
|
"noctcore-contracts/fetch-must-check-ok": "error",
|
|
12
|
-
// Config-required / heuristic rules ship inert. `require-registered-keys
|
|
13
|
-
// `env-var-schema-parity` do nothing until their
|
|
14
|
-
// set; `require-schema-parse-at-boundary` is a conservative syntactic slice of a
|
|
12
|
+
// Config-required / heuristic rules ship inert. `require-registered-keys`,
|
|
13
|
+
// `env-var-schema-parity` and `translation-key-exists` do nothing until their
|
|
14
|
+
// `sinks` / `schema` / `catalogs` options are set; `require-schema-parse-at-boundary` is a conservative syntactic slice of a
|
|
15
15
|
// type-aware concern. Enable them explicitly once configured for your project.
|
|
16
16
|
"noctcore-contracts/require-registered-keys": "off",
|
|
17
17
|
"noctcore-contracts/env-var-schema-parity": "off",
|
|
18
|
-
"noctcore-contracts/require-schema-parse-at-boundary": "off"
|
|
18
|
+
"noctcore-contracts/require-schema-parse-at-boundary": "off",
|
|
19
|
+
"noctcore-contracts/translation-key-exists": "off"
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
// src/rules/env-var-schema-parity.ts
|
|
@@ -556,8 +557,8 @@ var fetchMustCheckOkRule = createRule({
|
|
|
556
557
|
}
|
|
557
558
|
return {
|
|
558
559
|
CallExpression(node) {
|
|
559
|
-
const
|
|
560
|
-
if (
|
|
560
|
+
const path3 = calleePath(node.callee);
|
|
561
|
+
if (path3 === null || !fetchFunctions.has(path3)) {
|
|
561
562
|
return;
|
|
562
563
|
}
|
|
563
564
|
const parent = skipAwait(node.parent);
|
|
@@ -1056,11 +1057,11 @@ var requireRegisteredKeysRule = createRule({
|
|
|
1056
1057
|
const registryHint = registry ? ` (import it from '${registry}')` : "";
|
|
1057
1058
|
return {
|
|
1058
1059
|
CallExpression(node) {
|
|
1059
|
-
const
|
|
1060
|
-
if (
|
|
1060
|
+
const path3 = calleePath2(node.callee);
|
|
1061
|
+
if (path3 === null) {
|
|
1061
1062
|
return;
|
|
1062
1063
|
}
|
|
1063
|
-
const indexes = sinkMap.get(
|
|
1064
|
+
const indexes = sinkMap.get(path3);
|
|
1064
1065
|
if (indexes === void 0) {
|
|
1065
1066
|
return;
|
|
1066
1067
|
}
|
|
@@ -1070,7 +1071,7 @@ var requireRegisteredKeysRule = createRule({
|
|
|
1070
1071
|
context.report({
|
|
1071
1072
|
node: arg,
|
|
1072
1073
|
messageId: "unregisteredKey",
|
|
1073
|
-
data: { callee:
|
|
1074
|
+
data: { callee: path3, value: `'${arg.value}'`, registryHint }
|
|
1074
1075
|
});
|
|
1075
1076
|
}
|
|
1076
1077
|
}
|
|
@@ -1371,10 +1372,689 @@ var schemaEnumFieldConsistencyRule = createRule({
|
|
|
1371
1372
|
}
|
|
1372
1373
|
});
|
|
1373
1374
|
|
|
1375
|
+
// src/i18n/catalogs.ts
|
|
1376
|
+
import { readFileSync as readFileSync2, statSync } from "fs";
|
|
1377
|
+
import path2 from "path";
|
|
1378
|
+
var NS_PLACEHOLDER = "{ns}";
|
|
1379
|
+
var SAFE_NAMESPACE = /^(?!\.{1,2}$)[^/\\\0]+$/u;
|
|
1380
|
+
var fileCache = /* @__PURE__ */ new Map();
|
|
1381
|
+
function readCatalogFile(absolute) {
|
|
1382
|
+
let mtimeMs;
|
|
1383
|
+
try {
|
|
1384
|
+
const stats = statSync(absolute);
|
|
1385
|
+
if (!stats.isFile()) return { kind: "missing" };
|
|
1386
|
+
mtimeMs = stats.mtimeMs;
|
|
1387
|
+
} catch {
|
|
1388
|
+
return { kind: "missing" };
|
|
1389
|
+
}
|
|
1390
|
+
const cached = fileCache.get(absolute);
|
|
1391
|
+
if (cached !== void 0 && cached.mtimeMs === mtimeMs) {
|
|
1392
|
+
return cached.value.ok ? { kind: "ok", entry: cached } : { kind: "invalid", reason: cached.value.reason };
|
|
1393
|
+
}
|
|
1394
|
+
let value;
|
|
1395
|
+
try {
|
|
1396
|
+
value = { ok: true, json: JSON.parse(readFileSync2(absolute, "utf8")) };
|
|
1397
|
+
} catch (error) {
|
|
1398
|
+
value = { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
1399
|
+
}
|
|
1400
|
+
const entry = { mtimeMs, value, flattened: /* @__PURE__ */ new Map() };
|
|
1401
|
+
fileCache.set(absolute, entry);
|
|
1402
|
+
return value.ok ? { kind: "ok", entry } : { kind: "invalid", reason: value.reason };
|
|
1403
|
+
}
|
|
1404
|
+
function isRecord(value) {
|
|
1405
|
+
return value !== null && typeof value === "object";
|
|
1406
|
+
}
|
|
1407
|
+
function descend(json, keyPath) {
|
|
1408
|
+
if (keyPath === void 0 || keyPath === "") return json;
|
|
1409
|
+
let current = json;
|
|
1410
|
+
for (const segment of keyPath.split(".")) {
|
|
1411
|
+
if (!isRecord(current) || !Object.hasOwn(current, segment)) return void 0;
|
|
1412
|
+
current = current[segment];
|
|
1413
|
+
}
|
|
1414
|
+
return current;
|
|
1415
|
+
}
|
|
1416
|
+
function flatten(root, keySeparator, label) {
|
|
1417
|
+
const leaves = /* @__PURE__ */ new Set();
|
|
1418
|
+
const branches = /* @__PURE__ */ new Set();
|
|
1419
|
+
const visit = (value, prefix) => {
|
|
1420
|
+
if (!isRecord(value)) {
|
|
1421
|
+
leaves.add(prefix);
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
branches.add(prefix);
|
|
1425
|
+
if (keySeparator === false) return;
|
|
1426
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1427
|
+
visit(child, `${prefix}${keySeparator}${key}`);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
for (const [key, child] of Object.entries(root)) {
|
|
1431
|
+
if (keySeparator === false) {
|
|
1432
|
+
(isRecord(child) ? branches : leaves).add(key);
|
|
1433
|
+
} else {
|
|
1434
|
+
visit(child, key);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return { label, leaves, branches };
|
|
1438
|
+
}
|
|
1439
|
+
function loadSource(cwd, file, keyPath, keySeparator) {
|
|
1440
|
+
const absolute = path2.isAbsolute(file) ? file : path2.resolve(cwd, file);
|
|
1441
|
+
const read = readCatalogFile(absolute);
|
|
1442
|
+
if (read.kind === "missing") return { kind: "absent" };
|
|
1443
|
+
if (read.kind === "invalid") return { kind: "error", reason: `${file}: ${read.reason}` };
|
|
1444
|
+
const cacheKey = `${keyPath ?? ""}\0${keySeparator === false ? "" : keySeparator}`;
|
|
1445
|
+
const cached = read.entry.flattened.get(cacheKey);
|
|
1446
|
+
if (cached !== void 0) {
|
|
1447
|
+
return cached === null ? { kind: "absent" } : { kind: "ok", catalog: cached };
|
|
1448
|
+
}
|
|
1449
|
+
const subtree = read.entry.value.ok ? descend(read.entry.value.json, keyPath) : void 0;
|
|
1450
|
+
const label = keyPath ? `${file}#${keyPath}` : file;
|
|
1451
|
+
const catalog = isRecord(subtree) ? flatten(subtree, keySeparator, label) : null;
|
|
1452
|
+
read.entry.flattened.set(cacheKey, catalog);
|
|
1453
|
+
return catalog === null ? { kind: "absent" } : { kind: "ok", catalog };
|
|
1454
|
+
}
|
|
1455
|
+
function catalogsForNamespace(namespace, sources, settings) {
|
|
1456
|
+
const catalogs = [];
|
|
1457
|
+
const errors = [];
|
|
1458
|
+
for (const source of sources) {
|
|
1459
|
+
const templated = source.file.includes(NS_PLACEHOLDER) || (source.keyPath?.includes(NS_PLACEHOLDER) ?? false);
|
|
1460
|
+
if (templated) {
|
|
1461
|
+
if (!SAFE_NAMESPACE.test(namespace)) continue;
|
|
1462
|
+
const file = source.file.replaceAll(NS_PLACEHOLDER, namespace);
|
|
1463
|
+
const keyPath = source.keyPath?.replaceAll(NS_PLACEHOLDER, namespace);
|
|
1464
|
+
const load2 = loadSource(settings.cwd, file, keyPath, settings.keySeparator);
|
|
1465
|
+
if (load2.kind === "ok") catalogs.push(load2.catalog);
|
|
1466
|
+
else if (load2.kind === "error") errors.push(load2.reason);
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
if ((source.namespace ?? settings.defaultNamespace) !== namespace) continue;
|
|
1470
|
+
const load = loadSource(settings.cwd, source.file, source.keyPath, settings.keySeparator);
|
|
1471
|
+
if (load.kind === "ok") catalogs.push(load.catalog);
|
|
1472
|
+
else if (load.kind === "error") errors.push(load.reason);
|
|
1473
|
+
else {
|
|
1474
|
+
const where = source.keyPath ? `${source.file}#${source.keyPath}` : source.file;
|
|
1475
|
+
errors.push(`${where}: not found or not a JSON object`);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return { catalogs, errors };
|
|
1479
|
+
}
|
|
1480
|
+
var PLURAL_CATEGORIES = ["zero", "one", "two", "few", "many", "other"];
|
|
1481
|
+
function catalogHasKey(catalog, key, lookup) {
|
|
1482
|
+
if (catalog.leaves.has(key)) return true;
|
|
1483
|
+
if (lookup.returnObjects && catalog.branches.has(key)) return true;
|
|
1484
|
+
if (lookup.plural) {
|
|
1485
|
+
const sep = lookup.pluralSeparator;
|
|
1486
|
+
for (const category of PLURAL_CATEGORIES) {
|
|
1487
|
+
if (catalog.leaves.has(`${key}${sep}${category}`)) return true;
|
|
1488
|
+
if (catalog.leaves.has(`${key}${sep}ordinal${sep}${category}`)) return true;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (lookup.context) {
|
|
1492
|
+
const variant = `${key}${lookup.contextSeparator}`;
|
|
1493
|
+
for (const leaf of catalog.leaves) {
|
|
1494
|
+
if (leaf.startsWith(variant)) return true;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return false;
|
|
1498
|
+
}
|
|
1499
|
+
function catalogHasPrefix(catalog, prefix) {
|
|
1500
|
+
for (const leaf of catalog.leaves) {
|
|
1501
|
+
if (leaf.startsWith(prefix)) return true;
|
|
1502
|
+
}
|
|
1503
|
+
for (const branch of catalog.branches) {
|
|
1504
|
+
if (branch.startsWith(prefix)) return true;
|
|
1505
|
+
}
|
|
1506
|
+
return false;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// src/i18n/translationUsage.ts
|
|
1510
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11 } from "@typescript-eslint/utils";
|
|
1511
|
+
var UNRESOLVED = "unresolved";
|
|
1512
|
+
var MAX_DEPTH = 8;
|
|
1513
|
+
function unwrap(node) {
|
|
1514
|
+
let current = node;
|
|
1515
|
+
while (current.type === AST_NODE_TYPES11.TSAsExpression || current.type === AST_NODE_TYPES11.TSSatisfiesExpression || current.type === AST_NODE_TYPES11.TSNonNullExpression) {
|
|
1516
|
+
current = current.expression;
|
|
1517
|
+
}
|
|
1518
|
+
return current;
|
|
1519
|
+
}
|
|
1520
|
+
function staticString(node) {
|
|
1521
|
+
const inner = unwrap(node);
|
|
1522
|
+
if (inner.type === AST_NODE_TYPES11.Literal && typeof inner.value === "string") return inner.value;
|
|
1523
|
+
if (inner.type === AST_NODE_TYPES11.TemplateLiteral && inner.expressions.length === 0) {
|
|
1524
|
+
return inner.quasis[0]?.value.cooked ?? null;
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
function propertyName2(property) {
|
|
1529
|
+
if (property.computed) return staticString(property.key);
|
|
1530
|
+
if (property.key.type === AST_NODE_TYPES11.Identifier) return property.key.name;
|
|
1531
|
+
return staticString(property.key);
|
|
1532
|
+
}
|
|
1533
|
+
function targetIdentifier(node) {
|
|
1534
|
+
if (node.type === AST_NODE_TYPES11.Identifier) return node;
|
|
1535
|
+
if (node.type === AST_NODE_TYPES11.AssignmentPattern && node.left.type === AST_NODE_TYPES11.Identifier) {
|
|
1536
|
+
return node.left;
|
|
1537
|
+
}
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
function createTranslationVisitor(context, settings, onUsage) {
|
|
1541
|
+
const sourceCode = context.sourceCode;
|
|
1542
|
+
const defaultBinding = { namespaces: [settings.defaultNamespace], keyPrefix: null };
|
|
1543
|
+
function resolveVariable(identifier) {
|
|
1544
|
+
let scope = sourceCode.getScope(identifier);
|
|
1545
|
+
while (scope !== null) {
|
|
1546
|
+
const variable = scope.set.get(identifier.name);
|
|
1547
|
+
if (variable !== void 0) return variable;
|
|
1548
|
+
scope = scope.upper;
|
|
1549
|
+
}
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
function typedStringLiteral(node) {
|
|
1553
|
+
const services = sourceCode.parserServices;
|
|
1554
|
+
const program = services?.program;
|
|
1555
|
+
const map = services?.esTreeNodeToTSNodeMap;
|
|
1556
|
+
if (!program || !map) return null;
|
|
1557
|
+
const type = program.getTypeChecker().getTypeAtLocation(map.get(node));
|
|
1558
|
+
return type.isStringLiteral() ? type.value : null;
|
|
1559
|
+
}
|
|
1560
|
+
function resolveNamespaces(node, depth = 0) {
|
|
1561
|
+
if (node === void 0) return defaultBinding.namespaces;
|
|
1562
|
+
const inner = unwrap(node);
|
|
1563
|
+
const literal = staticString(inner);
|
|
1564
|
+
if (literal !== null) return [literal];
|
|
1565
|
+
if (inner.type === AST_NODE_TYPES11.Literal && inner.value === null) return defaultBinding.namespaces;
|
|
1566
|
+
if (inner.type === AST_NODE_TYPES11.ArrayExpression) {
|
|
1567
|
+
const namespaces = [];
|
|
1568
|
+
for (const element of inner.elements) {
|
|
1569
|
+
if (element === null || element.type === AST_NODE_TYPES11.SpreadElement) return UNRESOLVED;
|
|
1570
|
+
const value2 = staticString(element) ?? resolveIdentifierString(element, depth);
|
|
1571
|
+
if (value2 === null) return UNRESOLVED;
|
|
1572
|
+
namespaces.push(value2);
|
|
1573
|
+
}
|
|
1574
|
+
return namespaces.length > 0 ? namespaces : defaultBinding.namespaces;
|
|
1575
|
+
}
|
|
1576
|
+
if (inner.type === AST_NODE_TYPES11.Identifier && inner.name === "undefined") return defaultBinding.namespaces;
|
|
1577
|
+
const value = resolveIdentifierString(inner, depth);
|
|
1578
|
+
return value === null ? UNRESOLVED : [value];
|
|
1579
|
+
}
|
|
1580
|
+
function resolveIdentifierString(node, depth) {
|
|
1581
|
+
if (node.type !== AST_NODE_TYPES11.Identifier || depth > MAX_DEPTH) return null;
|
|
1582
|
+
if (Object.hasOwn(settings.namespaceIdentifiers, node.name)) {
|
|
1583
|
+
return settings.namespaceIdentifiers[node.name] ?? null;
|
|
1584
|
+
}
|
|
1585
|
+
const definition = resolveVariable(node)?.defs[0];
|
|
1586
|
+
if (definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.id.type === AST_NODE_TYPES11.Identifier && definition.node.init !== null) {
|
|
1587
|
+
const init = unwrap(definition.node.init);
|
|
1588
|
+
const literal = staticString(init);
|
|
1589
|
+
if (literal !== null) return literal;
|
|
1590
|
+
const chained = resolveIdentifierString(init, depth + 1);
|
|
1591
|
+
if (chained !== null) return chained;
|
|
1592
|
+
}
|
|
1593
|
+
return typedStringLiteral(node);
|
|
1594
|
+
}
|
|
1595
|
+
function isHookCall(node) {
|
|
1596
|
+
return node.type === AST_NODE_TYPES11.CallExpression && node.callee.type === AST_NODE_TYPES11.Identifier && settings.hooks.has(node.callee.name);
|
|
1597
|
+
}
|
|
1598
|
+
function isInstance(node) {
|
|
1599
|
+
return node.type === AST_NODE_TYPES11.Identifier && settings.instances.has(node.name);
|
|
1600
|
+
}
|
|
1601
|
+
function staticPrefix(node) {
|
|
1602
|
+
if (node === void 0) return null;
|
|
1603
|
+
const inner = unwrap(node);
|
|
1604
|
+
if (inner.type === AST_NODE_TYPES11.Identifier && inner.name === "undefined") return null;
|
|
1605
|
+
if (inner.type === AST_NODE_TYPES11.Literal && inner.value === null) return null;
|
|
1606
|
+
return staticString(inner) ?? UNRESOLVED;
|
|
1607
|
+
}
|
|
1608
|
+
function bindingFromHook(call) {
|
|
1609
|
+
const [nsArg, optionsArg] = call.arguments;
|
|
1610
|
+
const namespaces = resolveNamespaces(nsArg);
|
|
1611
|
+
if (namespaces === UNRESOLVED) return UNRESOLVED;
|
|
1612
|
+
let keyPrefix = null;
|
|
1613
|
+
if (optionsArg !== void 0) {
|
|
1614
|
+
const options = unwrap(optionsArg);
|
|
1615
|
+
if (options.type !== AST_NODE_TYPES11.ObjectExpression) return UNRESOLVED;
|
|
1616
|
+
for (const property of options.properties) {
|
|
1617
|
+
if (property.type !== AST_NODE_TYPES11.Property) return UNRESOLVED;
|
|
1618
|
+
if (propertyName2(property) !== "keyPrefix") continue;
|
|
1619
|
+
const prefix = staticPrefix(property.value);
|
|
1620
|
+
if (prefix === UNRESOLVED) return UNRESOLVED;
|
|
1621
|
+
keyPrefix = prefix;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
return { namespaces, keyPrefix };
|
|
1625
|
+
}
|
|
1626
|
+
function bindingFromGetFixedT(call) {
|
|
1627
|
+
const [, nsArg, prefixArg] = call.arguments;
|
|
1628
|
+
const namespaces = resolveNamespaces(nsArg);
|
|
1629
|
+
if (namespaces === UNRESOLVED) return UNRESOLVED;
|
|
1630
|
+
const keyPrefix = staticPrefix(prefixArg);
|
|
1631
|
+
if (keyPrefix === UNRESOLVED) return UNRESOLVED;
|
|
1632
|
+
return { namespaces, keyPrefix };
|
|
1633
|
+
}
|
|
1634
|
+
function isGetFixedT(node) {
|
|
1635
|
+
return node.type === AST_NODE_TYPES11.CallExpression && node.callee.type === AST_NODE_TYPES11.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES11.Identifier && node.callee.property.name === "getFixedT" && isInstance(node.callee.object);
|
|
1636
|
+
}
|
|
1637
|
+
function hookCallOf(identifier) {
|
|
1638
|
+
const definition = resolveVariable(identifier)?.defs[0];
|
|
1639
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== AST_NODE_TYPES11.Identifier) return null;
|
|
1640
|
+
const init = definition.node.init === null ? null : unwrap(definition.node.init);
|
|
1641
|
+
return init !== null && isHookCall(init) ? init : null;
|
|
1642
|
+
}
|
|
1643
|
+
function bindingOfTSource(object) {
|
|
1644
|
+
const inner = unwrap(object);
|
|
1645
|
+
if (isHookCall(inner)) return bindingFromHook(inner);
|
|
1646
|
+
if (inner.type === AST_NODE_TYPES11.Identifier) {
|
|
1647
|
+
const hook = hookCallOf(inner);
|
|
1648
|
+
if (hook !== null) return bindingFromHook(hook);
|
|
1649
|
+
if (isInstance(inner)) return defaultBinding;
|
|
1650
|
+
}
|
|
1651
|
+
return null;
|
|
1652
|
+
}
|
|
1653
|
+
function bindingFromType(annotation) {
|
|
1654
|
+
const type = annotation?.typeAnnotation;
|
|
1655
|
+
if (type?.type !== AST_NODE_TYPES11.TSTypeReference) return null;
|
|
1656
|
+
const name = type.typeName.type === AST_NODE_TYPES11.Identifier ? type.typeName.name : type.typeName.type === AST_NODE_TYPES11.TSQualifiedName ? type.typeName.right.name : null;
|
|
1657
|
+
if (name === null || !settings.typeNames.has(name)) return null;
|
|
1658
|
+
const [nsType, prefixType] = type.typeArguments?.params ?? [];
|
|
1659
|
+
const literalOf = (node) => node.type === AST_NODE_TYPES11.TSLiteralType ? staticString(node.literal) : null;
|
|
1660
|
+
let namespaces = defaultBinding.namespaces;
|
|
1661
|
+
if (nsType !== void 0) {
|
|
1662
|
+
if (nsType.type === AST_NODE_TYPES11.TSTupleType) {
|
|
1663
|
+
const values = nsType.elementTypes.map(literalOf);
|
|
1664
|
+
if (values.length === 0 || values.some((value) => value === null)) return UNRESOLVED;
|
|
1665
|
+
namespaces = values;
|
|
1666
|
+
} else {
|
|
1667
|
+
const value = literalOf(nsType);
|
|
1668
|
+
if (value === null) return UNRESOLVED;
|
|
1669
|
+
namespaces = [value];
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
let keyPrefix = null;
|
|
1673
|
+
if (prefixType !== void 0) {
|
|
1674
|
+
keyPrefix = literalOf(prefixType);
|
|
1675
|
+
if (keyPrefix === null) return UNRESOLVED;
|
|
1676
|
+
}
|
|
1677
|
+
return { namespaces, keyPrefix };
|
|
1678
|
+
}
|
|
1679
|
+
function bindingFromDeclarator(declarator, name, depth) {
|
|
1680
|
+
if (declarator.init === null) return null;
|
|
1681
|
+
const init = unwrap(declarator.init);
|
|
1682
|
+
const id = declarator.id;
|
|
1683
|
+
if (id.type === AST_NODE_TYPES11.Identifier) {
|
|
1684
|
+
if (isGetFixedT(init)) return bindingFromGetFixedT(init);
|
|
1685
|
+
if (init.type === AST_NODE_TYPES11.MemberExpression && !init.computed && init.property.type === AST_NODE_TYPES11.Identifier && init.property.name === "t") {
|
|
1686
|
+
return bindingOfTSource(init.object);
|
|
1687
|
+
}
|
|
1688
|
+
if (init.type === AST_NODE_TYPES11.Identifier) return bindingOfIdentifier(init, depth + 1);
|
|
1689
|
+
return null;
|
|
1690
|
+
}
|
|
1691
|
+
if (id.type === AST_NODE_TYPES11.ObjectPattern) {
|
|
1692
|
+
for (const property of id.properties) {
|
|
1693
|
+
if (property.type !== AST_NODE_TYPES11.Property || targetIdentifier(property.value) !== name) continue;
|
|
1694
|
+
return propertyName2(property) === "t" ? bindingOfTSource(init) : null;
|
|
1695
|
+
}
|
|
1696
|
+
return null;
|
|
1697
|
+
}
|
|
1698
|
+
if (id.type === AST_NODE_TYPES11.ArrayPattern) {
|
|
1699
|
+
const first = id.elements[0];
|
|
1700
|
+
if (first && targetIdentifier(first) === name && isHookCall(init)) return bindingFromHook(init);
|
|
1701
|
+
}
|
|
1702
|
+
return null;
|
|
1703
|
+
}
|
|
1704
|
+
function bindingOfIdentifier(identifier, depth = 0) {
|
|
1705
|
+
if (depth > MAX_DEPTH) return null;
|
|
1706
|
+
const variable = resolveVariable(identifier);
|
|
1707
|
+
if (variable === null) {
|
|
1708
|
+
return settings.functions.has(identifier.name) ? defaultBinding : null;
|
|
1709
|
+
}
|
|
1710
|
+
const definition = variable.defs[0];
|
|
1711
|
+
if (definition === void 0) return null;
|
|
1712
|
+
switch (definition.type) {
|
|
1713
|
+
case "ImportBinding": {
|
|
1714
|
+
const specifier = definition.node;
|
|
1715
|
+
if (specifier.type !== AST_NODE_TYPES11.ImportSpecifier) return null;
|
|
1716
|
+
const imported = specifier.imported.type === AST_NODE_TYPES11.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
1717
|
+
return settings.functions.has(imported) ? defaultBinding : null;
|
|
1718
|
+
}
|
|
1719
|
+
case "Parameter": {
|
|
1720
|
+
const name = definition.name;
|
|
1721
|
+
if (name.type !== AST_NODE_TYPES11.Identifier) return null;
|
|
1722
|
+
const typed = bindingFromType(name.typeAnnotation);
|
|
1723
|
+
if (typed !== null) return typed;
|
|
1724
|
+
return settings.functions.has(name.name) ? UNRESOLVED : null;
|
|
1725
|
+
}
|
|
1726
|
+
case "Variable":
|
|
1727
|
+
return definition.name.type === AST_NODE_TYPES11.Identifier ? bindingFromDeclarator(definition.node, definition.name, depth) : null;
|
|
1728
|
+
default:
|
|
1729
|
+
return null;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
function bindingOfCallee(callee) {
|
|
1733
|
+
if (callee.type === AST_NODE_TYPES11.Identifier) return bindingOfIdentifier(callee);
|
|
1734
|
+
if (callee.type === AST_NODE_TYPES11.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES11.Identifier && callee.property.name === "t") {
|
|
1735
|
+
return bindingOfTSource(callee.object);
|
|
1736
|
+
}
|
|
1737
|
+
return null;
|
|
1738
|
+
}
|
|
1739
|
+
function readCallOptions(node) {
|
|
1740
|
+
const none = { namespaces: null, plural: false, context: false, returnObjects: false };
|
|
1741
|
+
if (node === void 0) return none;
|
|
1742
|
+
const inner = unwrap(node);
|
|
1743
|
+
if (inner.type !== AST_NODE_TYPES11.ObjectExpression) return UNRESOLVED;
|
|
1744
|
+
let namespaces = null;
|
|
1745
|
+
let plural = false;
|
|
1746
|
+
let context2 = false;
|
|
1747
|
+
let returnObjects = false;
|
|
1748
|
+
for (const property of inner.properties) {
|
|
1749
|
+
if (property.type !== AST_NODE_TYPES11.Property) return UNRESOLVED;
|
|
1750
|
+
const name = propertyName2(property);
|
|
1751
|
+
if (name === null || name === "keyPrefix") return UNRESOLVED;
|
|
1752
|
+
if (name === "ns") {
|
|
1753
|
+
const resolved = resolveNamespaces(property.value);
|
|
1754
|
+
if (resolved === UNRESOLVED) return UNRESOLVED;
|
|
1755
|
+
namespaces = resolved;
|
|
1756
|
+
} else if (name === "count") {
|
|
1757
|
+
plural = true;
|
|
1758
|
+
} else if (name === "context") {
|
|
1759
|
+
context2 = true;
|
|
1760
|
+
} else if (name === "returnObjects") {
|
|
1761
|
+
const value = unwrap(property.value);
|
|
1762
|
+
returnObjects = !(value.type === AST_NODE_TYPES11.Literal && value.value === false);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
return { namespaces, plural, context: context2, returnObjects };
|
|
1766
|
+
}
|
|
1767
|
+
function qualify(raw, binding, optionNamespaces) {
|
|
1768
|
+
const { nsSeparator, keySeparator } = settings;
|
|
1769
|
+
if (nsSeparator !== false && raw.includes(nsSeparator)) {
|
|
1770
|
+
if (binding.keyPrefix !== null) return null;
|
|
1771
|
+
const [head = "", ...rest] = raw.split(nsSeparator);
|
|
1772
|
+
if (head !== "" && rest.length > 0) {
|
|
1773
|
+
return { namespaces: [head], key: rest.join(keySeparator === false ? nsSeparator : keySeparator) };
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
const namespaces = optionNamespaces ?? binding.namespaces;
|
|
1777
|
+
if (binding.keyPrefix === null || binding.keyPrefix === "") return { namespaces, key: raw };
|
|
1778
|
+
return { namespaces, key: `${binding.keyPrefix}${keySeparator === false ? "" : keySeparator}${raw}` };
|
|
1779
|
+
}
|
|
1780
|
+
function emit(node, keyNode, binding, options) {
|
|
1781
|
+
const inner = unwrap(keyNode);
|
|
1782
|
+
const raws = [];
|
|
1783
|
+
const single = staticString(inner);
|
|
1784
|
+
if (single !== null) {
|
|
1785
|
+
raws.push(single);
|
|
1786
|
+
} else if (inner.type === AST_NODE_TYPES11.ArrayExpression && inner.elements.length > 0) {
|
|
1787
|
+
for (const element of inner.elements) {
|
|
1788
|
+
const value = element === null || element.type === AST_NODE_TYPES11.SpreadElement ? null : staticString(element);
|
|
1789
|
+
if (value === null) {
|
|
1790
|
+
onUsage({ kind: "dynamic", node });
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
raws.push(value);
|
|
1794
|
+
}
|
|
1795
|
+
} else if (inner.type === AST_NODE_TYPES11.TemplateLiteral) {
|
|
1796
|
+
const head = inner.quasis[0]?.value.cooked ?? "";
|
|
1797
|
+
const qualified = head === "" ? null : qualify(head, binding, options.namespaces);
|
|
1798
|
+
if (qualified === null) {
|
|
1799
|
+
onUsage({ kind: "dynamic", node });
|
|
1800
|
+
} else {
|
|
1801
|
+
onUsage({ kind: "prefix", node, namespaces: qualified.namespaces, prefix: qualified.key });
|
|
1802
|
+
}
|
|
1803
|
+
return;
|
|
1804
|
+
} else {
|
|
1805
|
+
onUsage({ kind: "dynamic", node });
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
let namespaces = null;
|
|
1809
|
+
const keys = [];
|
|
1810
|
+
for (const raw of raws) {
|
|
1811
|
+
const qualified = qualify(raw, binding, options.namespaces);
|
|
1812
|
+
if (qualified === null || raw === "") {
|
|
1813
|
+
onUsage({ kind: "unresolved", node });
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
if (namespaces !== null && namespaces.join("\0") !== qualified.namespaces.join("\0")) {
|
|
1817
|
+
onUsage({ kind: "unresolved", node });
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
namespaces = qualified.namespaces;
|
|
1821
|
+
keys.push(qualified.key);
|
|
1822
|
+
}
|
|
1823
|
+
onUsage({
|
|
1824
|
+
kind: "key",
|
|
1825
|
+
node,
|
|
1826
|
+
namespaces: namespaces ?? binding.namespaces,
|
|
1827
|
+
keys,
|
|
1828
|
+
plural: options.plural,
|
|
1829
|
+
context: options.context,
|
|
1830
|
+
returnObjects: options.returnObjects
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
function jsxAttributeValue(attribute) {
|
|
1834
|
+
const value = attribute.value;
|
|
1835
|
+
if (value === null) return null;
|
|
1836
|
+
if (value.type === AST_NODE_TYPES11.JSXExpressionContainer) {
|
|
1837
|
+
return value.expression.type === AST_NODE_TYPES11.JSXEmptyExpression ? null : value.expression;
|
|
1838
|
+
}
|
|
1839
|
+
return value;
|
|
1840
|
+
}
|
|
1841
|
+
return {
|
|
1842
|
+
CallExpression(node) {
|
|
1843
|
+
const binding = bindingOfCallee(node.callee);
|
|
1844
|
+
if (binding === null) return;
|
|
1845
|
+
const [keyArg, secondArg, thirdArg] = node.arguments;
|
|
1846
|
+
if (keyArg === void 0) return;
|
|
1847
|
+
if (binding === UNRESOLVED) {
|
|
1848
|
+
onUsage({ kind: "unresolved", node: keyArg });
|
|
1849
|
+
return;
|
|
1850
|
+
}
|
|
1851
|
+
const optionsArg = secondArg !== void 0 && staticString(secondArg) !== null ? thirdArg : secondArg;
|
|
1852
|
+
const options = readCallOptions(optionsArg);
|
|
1853
|
+
if (options === UNRESOLVED) {
|
|
1854
|
+
onUsage({ kind: "unresolved", node: keyArg });
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
emit(keyArg, keyArg, binding, options);
|
|
1858
|
+
},
|
|
1859
|
+
JSXOpeningElement(node) {
|
|
1860
|
+
if (node.name.type !== AST_NODE_TYPES11.JSXIdentifier || !settings.transComponents.has(node.name.name)) return;
|
|
1861
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
1862
|
+
for (const attribute of node.attributes) {
|
|
1863
|
+
if (attribute.type === AST_NODE_TYPES11.JSXSpreadAttribute) {
|
|
1864
|
+
onUsage({ kind: "unresolved", node });
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
if (attribute.name.type === AST_NODE_TYPES11.JSXIdentifier) attributes.set(attribute.name.name, attribute);
|
|
1868
|
+
}
|
|
1869
|
+
const keyAttribute = attributes.get("i18nKey");
|
|
1870
|
+
const keyNode = keyAttribute === void 0 ? null : jsxAttributeValue(keyAttribute);
|
|
1871
|
+
if (keyNode === null) return;
|
|
1872
|
+
let binding = defaultBinding;
|
|
1873
|
+
const tAttribute = attributes.get("t");
|
|
1874
|
+
const tNode = tAttribute === void 0 ? null : jsxAttributeValue(tAttribute);
|
|
1875
|
+
if (tNode !== null) {
|
|
1876
|
+
binding = tNode.type === AST_NODE_TYPES11.Identifier ? bindingOfIdentifier(tNode) : UNRESOLVED;
|
|
1877
|
+
}
|
|
1878
|
+
let namespaces = null;
|
|
1879
|
+
const nsAttribute = attributes.get("ns");
|
|
1880
|
+
const nsNode = nsAttribute === void 0 ? null : jsxAttributeValue(nsAttribute);
|
|
1881
|
+
if (nsNode !== null) {
|
|
1882
|
+
const resolved = resolveNamespaces(nsNode);
|
|
1883
|
+
if (resolved === UNRESOLVED) binding = UNRESOLVED;
|
|
1884
|
+
else namespaces = resolved;
|
|
1885
|
+
}
|
|
1886
|
+
if (binding === null || binding === UNRESOLVED) {
|
|
1887
|
+
onUsage({ kind: "unresolved", node: keyNode });
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
emit(keyNode, keyNode, binding, {
|
|
1891
|
+
namespaces,
|
|
1892
|
+
plural: attributes.has("count"),
|
|
1893
|
+
context: attributes.has("context"),
|
|
1894
|
+
returnObjects: false
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// src/rules/translation-key-exists.ts
|
|
1901
|
+
var RULE_NAME11 = "translation-key-exists";
|
|
1902
|
+
var stringList = { type: "array", items: { type: "string", minLength: 1 }, uniqueItems: true };
|
|
1903
|
+
var separator = { oneOf: [{ type: "string", minLength: 1 }, { type: "boolean", enum: [false] }] };
|
|
1904
|
+
var optionSchema9 = {
|
|
1905
|
+
type: "object",
|
|
1906
|
+
additionalProperties: false,
|
|
1907
|
+
properties: {
|
|
1908
|
+
catalogs: {
|
|
1909
|
+
type: "array",
|
|
1910
|
+
items: {
|
|
1911
|
+
type: "object",
|
|
1912
|
+
additionalProperties: false,
|
|
1913
|
+
required: ["file"],
|
|
1914
|
+
properties: {
|
|
1915
|
+
file: { type: "string", minLength: 1 },
|
|
1916
|
+
namespace: { type: "string", minLength: 1 },
|
|
1917
|
+
keyPath: { type: "string", minLength: 1 }
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
},
|
|
1921
|
+
defaultNamespace: { type: "string", minLength: 1 },
|
|
1922
|
+
fallbackNamespaces: stringList,
|
|
1923
|
+
hooks: stringList,
|
|
1924
|
+
instances: stringList,
|
|
1925
|
+
functions: stringList,
|
|
1926
|
+
typeNames: stringList,
|
|
1927
|
+
transComponents: stringList,
|
|
1928
|
+
namespaceIdentifiers: { type: "object", additionalProperties: { type: "string", minLength: 1 } },
|
|
1929
|
+
nsSeparator: separator,
|
|
1930
|
+
keySeparator: separator,
|
|
1931
|
+
pluralSeparator: { type: "string", minLength: 1 },
|
|
1932
|
+
contextSeparator: { type: "string", minLength: 1 },
|
|
1933
|
+
dynamicKeys: { type: "string", enum: ["ignore", "check-prefix"] }
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
var TRANSLATION_DEFAULTS = {
|
|
1937
|
+
defaultNamespace: "translation",
|
|
1938
|
+
hooks: ["useTranslation"],
|
|
1939
|
+
instances: ["i18n", "i18next"],
|
|
1940
|
+
functions: ["t"],
|
|
1941
|
+
typeNames: ["TFunction"],
|
|
1942
|
+
transComponents: ["Trans"],
|
|
1943
|
+
nsSeparator: ":",
|
|
1944
|
+
keySeparator: ".",
|
|
1945
|
+
pluralSeparator: "_",
|
|
1946
|
+
contextSeparator: "_"
|
|
1947
|
+
};
|
|
1948
|
+
function translationSettingsOf(options) {
|
|
1949
|
+
return {
|
|
1950
|
+
hooks: new Set(options.hooks ?? TRANSLATION_DEFAULTS.hooks),
|
|
1951
|
+
instances: new Set(options.instances ?? TRANSLATION_DEFAULTS.instances),
|
|
1952
|
+
functions: new Set(options.functions ?? TRANSLATION_DEFAULTS.functions),
|
|
1953
|
+
typeNames: new Set(options.typeNames ?? TRANSLATION_DEFAULTS.typeNames),
|
|
1954
|
+
transComponents: new Set(options.transComponents ?? TRANSLATION_DEFAULTS.transComponents),
|
|
1955
|
+
namespaceIdentifiers: options.namespaceIdentifiers ?? {},
|
|
1956
|
+
defaultNamespace: options.defaultNamespace ?? TRANSLATION_DEFAULTS.defaultNamespace,
|
|
1957
|
+
nsSeparator: options.nsSeparator ?? TRANSLATION_DEFAULTS.nsSeparator,
|
|
1958
|
+
keySeparator: options.keySeparator ?? TRANSLATION_DEFAULTS.keySeparator
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
var translationKeyExistsRule = createRule({
|
|
1962
|
+
name: RULE_NAME11,
|
|
1963
|
+
meta: {
|
|
1964
|
+
type: "problem",
|
|
1965
|
+
docs: {
|
|
1966
|
+
description: "Require every static i18next / react-i18next translation key (`t(...)`, `i18n.t(...)`, `<Trans i18nKey>`) to exist in the catalog of the namespace in scope."
|
|
1967
|
+
},
|
|
1968
|
+
schema: [optionSchema9],
|
|
1969
|
+
messages: {
|
|
1970
|
+
missingKey: "Translation key `{{key}}` does not exist in namespace `{{namespace}}` ({{catalogs}}). It renders as the raw key at runtime: fix the key or add it to the catalog.",
|
|
1971
|
+
missingKeyPrefix: "No key in namespace `{{namespace}}` ({{catalogs}}) starts with `{{prefix}}`, so this template key can never resolve.",
|
|
1972
|
+
unknownNamespace: "Namespace `{{namespace}}` has no catalog in the rule configuration. Fix the namespace name or add a `catalogs` entry for it.",
|
|
1973
|
+
catalogUnreadable: "Translation catalog could not be loaded: {{reason}}."
|
|
1974
|
+
}
|
|
1975
|
+
},
|
|
1976
|
+
defaultOptions: [{}],
|
|
1977
|
+
create(context, [options]) {
|
|
1978
|
+
const sources = options.catalogs ?? [];
|
|
1979
|
+
if (sources.length === 0) {
|
|
1980
|
+
return {};
|
|
1981
|
+
}
|
|
1982
|
+
const settings = translationSettingsOf(options);
|
|
1983
|
+
const fallbackNamespaces = options.fallbackNamespaces ?? [];
|
|
1984
|
+
const catalogSettings = {
|
|
1985
|
+
cwd: context.cwd,
|
|
1986
|
+
defaultNamespace: settings.defaultNamespace,
|
|
1987
|
+
keySeparator: settings.keySeparator
|
|
1988
|
+
};
|
|
1989
|
+
const lookupBase = {
|
|
1990
|
+
pluralSeparator: options.pluralSeparator ?? TRANSLATION_DEFAULTS.pluralSeparator,
|
|
1991
|
+
contextSeparator: options.contextSeparator ?? TRANSLATION_DEFAULTS.contextSeparator
|
|
1992
|
+
};
|
|
1993
|
+
const checkPrefix = options.dynamicKeys === "check-prefix";
|
|
1994
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1995
|
+
const reportedErrors = /* @__PURE__ */ new Set();
|
|
1996
|
+
function catalogsOf(namespace) {
|
|
1997
|
+
let entry = resolved.get(namespace);
|
|
1998
|
+
if (entry === void 0) {
|
|
1999
|
+
entry = catalogsForNamespace(namespace, sources, catalogSettings);
|
|
2000
|
+
resolved.set(namespace, entry);
|
|
2001
|
+
}
|
|
2002
|
+
return entry;
|
|
2003
|
+
}
|
|
2004
|
+
function searched(node, namespaces) {
|
|
2005
|
+
const catalogs = [];
|
|
2006
|
+
for (const namespace of [...namespaces, ...fallbackNamespaces]) {
|
|
2007
|
+
const entry = catalogsOf(namespace);
|
|
2008
|
+
for (const reason of entry.errors) {
|
|
2009
|
+
if (!reportedErrors.has(reason)) {
|
|
2010
|
+
reportedErrors.add(reason);
|
|
2011
|
+
context.report({ node, messageId: "catalogUnreadable", data: { reason } });
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
if (entry.errors.length > 0) return null;
|
|
2015
|
+
catalogs.push(...entry.catalogs);
|
|
2016
|
+
}
|
|
2017
|
+
if (catalogs.length === 0) {
|
|
2018
|
+
context.report({ node, messageId: "unknownNamespace", data: { namespace: namespaces.join("`, `") } });
|
|
2019
|
+
return null;
|
|
2020
|
+
}
|
|
2021
|
+
return catalogs;
|
|
2022
|
+
}
|
|
2023
|
+
const labels = (catalogs) => catalogs.map((catalog) => catalog.label).join(", ");
|
|
2024
|
+
return createTranslationVisitor(context, settings, (usage) => {
|
|
2025
|
+
if (usage.kind === "key") {
|
|
2026
|
+
const catalogs = searched(usage.node, usage.namespaces);
|
|
2027
|
+
if (catalogs === null) return;
|
|
2028
|
+
const lookup = { ...lookupBase, plural: usage.plural, context: usage.context, returnObjects: usage.returnObjects };
|
|
2029
|
+
const found = usage.keys.some((key) => catalogs.some((catalog) => catalogHasKey(catalog, key, lookup)));
|
|
2030
|
+
if (!found) {
|
|
2031
|
+
context.report({
|
|
2032
|
+
node: usage.node,
|
|
2033
|
+
messageId: "missingKey",
|
|
2034
|
+
data: { key: usage.keys.join("` | `"), namespace: usage.namespaces.join("`, `"), catalogs: labels(catalogs) }
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
if (usage.kind === "prefix" && checkPrefix) {
|
|
2040
|
+
const catalogs = searched(usage.node, usage.namespaces);
|
|
2041
|
+
if (catalogs === null) return;
|
|
2042
|
+
if (!catalogs.some((catalog) => catalogHasPrefix(catalog, usage.prefix))) {
|
|
2043
|
+
context.report({
|
|
2044
|
+
node: usage.node,
|
|
2045
|
+
messageId: "missingKeyPrefix",
|
|
2046
|
+
data: { prefix: usage.prefix, namespace: usage.namespaces.join("`, `"), catalogs: labels(catalogs) }
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
});
|
|
2053
|
+
|
|
1374
2054
|
// src/rules/wire-message-naming.ts
|
|
1375
|
-
var
|
|
2055
|
+
var RULE_NAME12 = "wire-message-naming";
|
|
1376
2056
|
var DEFAULT_ROLE_SUFFIXES = ["Event", "Command", "Query"];
|
|
1377
|
-
var
|
|
2057
|
+
var optionSchema10 = {
|
|
1378
2058
|
type: "object",
|
|
1379
2059
|
additionalProperties: false,
|
|
1380
2060
|
properties: {
|
|
@@ -1415,14 +2095,14 @@ function typeLiteralNode(obj) {
|
|
|
1415
2095
|
return null;
|
|
1416
2096
|
}
|
|
1417
2097
|
var wireMessageNamingRule = createRule({
|
|
1418
|
-
name:
|
|
2098
|
+
name: RULE_NAME12,
|
|
1419
2099
|
meta: {
|
|
1420
2100
|
type: "problem",
|
|
1421
2101
|
docs: {
|
|
1422
2102
|
description: "A message-schema const ending in a role suffix (default Event/Command/Query) whose zod object declares `type: z.literal(...)` must set that literal to kebab-case(const name minus its role suffix)."
|
|
1423
2103
|
},
|
|
1424
2104
|
fixable: "code",
|
|
1425
|
-
schema: [
|
|
2105
|
+
schema: [optionSchema10],
|
|
1426
2106
|
messages: {
|
|
1427
2107
|
typeMismatch: "Wire `type` literal '{{actual}}' for `{{name}}` must be '{{expected}}' \u2014 kebab-case of the const name minus its role suffix."
|
|
1428
2108
|
}
|
|
@@ -1458,11 +2138,11 @@ var wireMessageNamingRule = createRule({
|
|
|
1458
2138
|
});
|
|
1459
2139
|
|
|
1460
2140
|
// src/rules/zod-schema-naming.ts
|
|
1461
|
-
var
|
|
2141
|
+
var RULE_NAME13 = "zod-schema-naming";
|
|
1462
2142
|
var SCHEMA_NAME = /^[A-Z][A-Za-z0-9]*Schema$/;
|
|
1463
2143
|
var SUFFIX = "Schema";
|
|
1464
2144
|
var DEFAULT_ROLE_SUFFIXES2 = [];
|
|
1465
|
-
var
|
|
2145
|
+
var optionSchema11 = {
|
|
1466
2146
|
type: "object",
|
|
1467
2147
|
additionalProperties: false,
|
|
1468
2148
|
properties: {
|
|
@@ -1495,13 +2175,13 @@ function rootIdentifierName(node) {
|
|
|
1495
2175
|
return null;
|
|
1496
2176
|
}
|
|
1497
2177
|
var zodSchemaNamingRule = createRule({
|
|
1498
|
-
name:
|
|
2178
|
+
name: RULE_NAME13,
|
|
1499
2179
|
meta: {
|
|
1500
2180
|
type: "problem",
|
|
1501
2181
|
docs: {
|
|
1502
2182
|
description: "Every exported zod schema is a PascalCase const suffixed `Schema`, paired with a same-named inferred type (`export type Foo = z.infer<typeof FooSchema>`)."
|
|
1503
2183
|
},
|
|
1504
|
-
schema: [
|
|
2184
|
+
schema: [optionSchema11],
|
|
1505
2185
|
messages: {
|
|
1506
2186
|
schemaNaming: "Exported zod schema `{{name}}` must be a PascalCase const ending in `Schema` (e.g. `FooSchema`).",
|
|
1507
2187
|
missingType: "Schema `{{name}}` has no sibling `export type {{base}} = z.infer<typeof {{name}}>`. Export the inferred type instead of hand-authoring a duplicate."
|
|
@@ -1564,7 +2244,8 @@ var rules = {
|
|
|
1564
2244
|
"env-var-schema-parity": envVarSchemaParityRule,
|
|
1565
2245
|
"require-schema-parse-at-boundary": requireSchemaParseAtBoundaryRule,
|
|
1566
2246
|
"schema-enum-field-consistency": schemaEnumFieldConsistencyRule,
|
|
1567
|
-
"fetch-must-check-ok": fetchMustCheckOkRule
|
|
2247
|
+
"fetch-must-check-ok": fetchMustCheckOkRule,
|
|
2248
|
+
"translation-key-exists": translationKeyExistsRule
|
|
1568
2249
|
};
|
|
1569
2250
|
|
|
1570
2251
|
// src/index.ts
|
|
@@ -1582,7 +2263,13 @@ plugin.configs.recommended = {
|
|
|
1582
2263
|
var configs = plugin.configs;
|
|
1583
2264
|
var index_default = plugin;
|
|
1584
2265
|
export {
|
|
2266
|
+
TRANSLATION_DEFAULTS,
|
|
2267
|
+
catalogHasKey,
|
|
2268
|
+
catalogHasPrefix,
|
|
2269
|
+
catalogsForNamespace,
|
|
1585
2270
|
configs,
|
|
2271
|
+
createTranslationVisitor,
|
|
1586
2272
|
index_default as default,
|
|
1587
|
-
rules
|
|
2273
|
+
rules,
|
|
2274
|
+
translationSettingsOf
|
|
1588
2275
|
};
|