pasika 0.10.98 → 0.10.100
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 +32 -5
- package/package.json +1 -1
|
@@ -5315,7 +5315,7 @@ function getSemanticLiteralIndex(index) {
|
|
|
5315
5315
|
|
|
5316
5316
|
// eslint/rules/no-inline-runtime-literal.ts
|
|
5317
5317
|
var DOC4 = "See docs/next-codebase-guide/rules/constants-rule.md";
|
|
5318
|
-
var MESSAGE2 = `Every runtime string or numeric value must use a named constant or enum member, including single-use values.
|
|
5318
|
+
var MESSAGE2 = `Every runtime string or numeric value must use a named constant or enum member, including single-use values. Inline JSX className and canonical locale strings are exempt. ${DOC4}`;
|
|
5319
5319
|
function isClassNameProp(node) {
|
|
5320
5320
|
let current = node;
|
|
5321
5321
|
while (current.parent) {
|
|
@@ -5369,28 +5369,55 @@ function isSyntacticString(node) {
|
|
|
5369
5369
|
}
|
|
5370
5370
|
return false;
|
|
5371
5371
|
}
|
|
5372
|
+
function isRuntimeMockSource(file, root) {
|
|
5373
|
+
const parts = path40.relative(root, file).split(path40.sep);
|
|
5374
|
+
return parts.includes("mocks") && !parts.some((part) => part === "__tests__" || part === "__mocks__") && !/\.(?:test|spec|mock)\.[^.]+$/.test(path40.basename(file));
|
|
5375
|
+
}
|
|
5376
|
+
function isCanonicalLocaleString(node, root, file) {
|
|
5377
|
+
if (path40.relative(root, file) !== path40.join("locales", "index.ts")) return false;
|
|
5378
|
+
let current = node;
|
|
5379
|
+
let depth = 0;
|
|
5380
|
+
while (current.parent?.type === "Property" && current.parent.value === current) {
|
|
5381
|
+
const object = current.parent.parent;
|
|
5382
|
+
if (object?.type !== "ObjectExpression") return false;
|
|
5383
|
+
current = object;
|
|
5384
|
+
depth += 1;
|
|
5385
|
+
}
|
|
5386
|
+
if (depth < 1 || depth > 2) return false;
|
|
5387
|
+
while ((current.parent?.type === "TSAsExpression" || current.parent?.type === "TSSatisfiesExpression") && current.parent.expression === current) {
|
|
5388
|
+
current = current.parent;
|
|
5389
|
+
}
|
|
5390
|
+
const declaration = current.parent;
|
|
5391
|
+
if (declaration?.type !== "VariableDeclarator" || declaration.init !== current) return false;
|
|
5392
|
+
const id = declaration.id;
|
|
5393
|
+
return typeof id === "object" && id !== null && "type" in id && id.type === "Identifier" && "name" in id && id.name === "locales" && declaration.parent?.type === "VariableDeclaration" && declaration.parent.kind === "const" && declaration.parent.parent?.type === "ExportNamedDeclaration";
|
|
5394
|
+
}
|
|
5372
5395
|
var noInlineRuntimeLiteralRule = {
|
|
5373
5396
|
meta: {
|
|
5374
5397
|
schema: [],
|
|
5375
5398
|
type: "problem",
|
|
5376
|
-
docs: { description: "Require named runtime
|
|
5399
|
+
docs: { description: "Require named runtime values except JSX className and canonical locale strings." }
|
|
5377
5400
|
},
|
|
5378
5401
|
create(context) {
|
|
5379
5402
|
const root = sourceRootOf(context);
|
|
5380
5403
|
const file = path40.resolve(context.filename);
|
|
5381
|
-
if (!file.startsWith(root + path40.sep) || !isProductionSource(file, root))
|
|
5404
|
+
if (!file.startsWith(root + path40.sep) || !isProductionSource(file, root) && !isRuntimeMockSource(file, root)) {
|
|
5405
|
+
return {};
|
|
5406
|
+
}
|
|
5382
5407
|
return {
|
|
5383
5408
|
Literal(node) {
|
|
5384
5409
|
if (typeof node.value !== "string" && typeof node.value !== "number" && typeof node.value !== "bigint" && !("bigint" in node && typeof node.bigint === "string")) {
|
|
5385
5410
|
return;
|
|
5386
5411
|
}
|
|
5387
|
-
if (typeof node.value === "string" && isClassNameProp(node) || isNamedValue(node) || isSyntacticString(node)) {
|
|
5412
|
+
if (typeof node.value === "string" && (isClassNameProp(node) || isCanonicalLocaleString(node, root, file)) || isNamedValue(node) || isSyntacticString(node)) {
|
|
5388
5413
|
return;
|
|
5389
5414
|
}
|
|
5390
5415
|
context.report({ node, message: MESSAGE2 });
|
|
5391
5416
|
},
|
|
5392
5417
|
TemplateLiteral(node) {
|
|
5393
|
-
if (isClassNameProp(node) || isNamedValue(node))
|
|
5418
|
+
if (isClassNameProp(node) || isNamedValue(node) || node.expressions.length === 0 && isCanonicalLocaleString(node, root, file)) {
|
|
5419
|
+
return;
|
|
5420
|
+
}
|
|
5394
5421
|
if (node.quasis.every((quasi) => quasi.value.raw === "")) return;
|
|
5395
5422
|
context.report({ node, message: MESSAGE2 });
|
|
5396
5423
|
},
|