pasika 0.10.112 → 0.10.113
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 +81 -83
- package/package.json +1 -1
|
@@ -10376,12 +10376,21 @@ function applyOperationCount(utility) {
|
|
|
10376
10376
|
return count;
|
|
10377
10377
|
}
|
|
10378
10378
|
function themeCandidate(name, utilityText) {
|
|
10379
|
-
const
|
|
10380
|
-
|
|
10379
|
+
const source = utilityText.trim();
|
|
10380
|
+
const arbitrary = /^@utility\s+[\w-]+\s*\{\s*@apply\s+\[(?<property>font-size|letter-spacing):(?<value>[^\]\r\n;{}]+)\];?\s*\}$/u.exec(
|
|
10381
|
+
source
|
|
10381
10382
|
);
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10383
|
+
const typed = /^@utility\s+[\w-]+\s*\{\s*@apply\s+(?<kind>text|tracking)-\((?<hint>length:)?(?<variable>--[a-z][a-z0-9-]*)\);?\s*\}$/u.exec(
|
|
10384
|
+
source
|
|
10385
|
+
);
|
|
10386
|
+
const kind = typed?.groups?.kind;
|
|
10387
|
+
const hint = typed?.groups?.hint;
|
|
10388
|
+
if (kind === "text" && hint !== "length:") return void 0;
|
|
10389
|
+
if (kind === "tracking" && hint !== void 0) return void 0;
|
|
10390
|
+
let property = arbitrary?.groups?.property;
|
|
10391
|
+
if (!property && kind === "text") property = "font-size";
|
|
10392
|
+
if (!property && kind === "tracking") property = "letter-spacing";
|
|
10393
|
+
const value = arbitrary?.groups?.value?.trim() ?? (typed?.groups?.variable ? `var(${typed.groups.variable})` : void 0);
|
|
10385
10394
|
if (!property || !value) return void 0;
|
|
10386
10395
|
const prefix = property === "font-size" ? "text-" : "tracking-";
|
|
10387
10396
|
if (!name.startsWith(prefix) || name.length === prefix.length) return void 0;
|
|
@@ -10428,98 +10437,87 @@ function isTypographySize(name) {
|
|
|
10428
10437
|
}
|
|
10429
10438
|
var utilityMappingRule = {
|
|
10430
10439
|
meta: {
|
|
10431
|
-
schema: [
|
|
10432
|
-
{
|
|
10433
|
-
type: "object",
|
|
10434
|
-
properties: { preferThemeTokens: { type: "boolean" } },
|
|
10435
|
-
additionalProperties: false
|
|
10436
|
-
}
|
|
10437
|
-
],
|
|
10440
|
+
schema: [],
|
|
10438
10441
|
type: "problem",
|
|
10439
10442
|
docs: {
|
|
10440
|
-
description: "Require one styling operation per custom utility
|
|
10443
|
+
description: "Require one styling operation per custom utility and enforce theme tokens instead of redundant mappings."
|
|
10441
10444
|
}
|
|
10442
10445
|
},
|
|
10443
10446
|
create(context) {
|
|
10444
|
-
const option = context.options[0];
|
|
10445
|
-
const preferThemeTokens = typeof option === "object" && option !== null && "preferThemeTokens" in option && option.preferThemeTokens === true;
|
|
10446
10447
|
return {
|
|
10447
10448
|
"StyleSheet:exit"(node) {
|
|
10448
10449
|
const utilities = atrulesNamed(node, "utility");
|
|
10449
10450
|
const themeTokens = /* @__PURE__ */ new Set();
|
|
10450
10451
|
const nameCounts = /* @__PURE__ */ new Map();
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
if (!variable) return lengthIdentity(value);
|
|
10455
|
-
const name = variable.groups?.name;
|
|
10456
|
-
if (!name || overriddenVariables.has(name)) return void 0;
|
|
10457
|
-
const definitions = rootValues.get(name);
|
|
10458
|
-
const definition = definitions?.length === 1 ? definitions[0] : void 0;
|
|
10459
|
-
return definition ? lengthIdentity(definition) : void 0;
|
|
10460
|
-
};
|
|
10461
|
-
var identity = identity2;
|
|
10462
|
-
for (const theme of atrulesNamed(node, "theme")) {
|
|
10463
|
-
for (const child of blockChildren2(theme)) {
|
|
10464
|
-
if (child.type === "Declaration") themeTokens.add(child.property);
|
|
10465
|
-
}
|
|
10466
|
-
}
|
|
10467
|
-
for (const utility of utilities) {
|
|
10468
|
-
const name = preludeIdentifiers(utility)[0] ?? "";
|
|
10469
|
-
nameCounts.set(name, (nameCounts.get(name) ?? 0) + 1);
|
|
10452
|
+
for (const theme of atrulesNamed(node, "theme")) {
|
|
10453
|
+
for (const child of blockChildren2(theme)) {
|
|
10454
|
+
if (child.type === "Declaration") themeTokens.add(child.property);
|
|
10470
10455
|
}
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10456
|
+
}
|
|
10457
|
+
for (const utility of utilities) {
|
|
10458
|
+
const name = preludeIdentifiers(utility)[0] ?? "";
|
|
10459
|
+
nameCounts.set(name, (nameCounts.get(name) ?? 0) + 1);
|
|
10460
|
+
}
|
|
10461
|
+
const themeDefinitions = /* @__PURE__ */ new Map();
|
|
10462
|
+
for (const theme of atrulesNamed(node, "theme")) {
|
|
10463
|
+
for (const child of blockChildren2(theme)) {
|
|
10464
|
+
if (child.type !== "Declaration") continue;
|
|
10465
|
+
const value = declarationValue(context.sourceCode.getText(child));
|
|
10466
|
+
if (!value) continue;
|
|
10467
|
+
const definitions = themeDefinitions.get(child.property) ?? [];
|
|
10468
|
+
definitions.push({ node: child, value });
|
|
10469
|
+
themeDefinitions.set(child.property, definitions);
|
|
10481
10470
|
}
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
const value = declarationValue(context.sourceCode.getText(child));
|
|
10494
|
-
if (!value) continue;
|
|
10495
|
-
const definitions = rootValues.get(child.property) ?? [];
|
|
10496
|
-
definitions.push(value);
|
|
10497
|
-
rootValues.set(child.property, definitions);
|
|
10471
|
+
}
|
|
10472
|
+
const rootValues = /* @__PURE__ */ new Map();
|
|
10473
|
+
const overriddenVariables = /* @__PURE__ */ new Set();
|
|
10474
|
+
for (const cssRule of rules(node)) {
|
|
10475
|
+
if (!("prelude" in cssRule) || !cssRule.prelude) continue;
|
|
10476
|
+
const isRoot = context.sourceCode.getText(cssRule.prelude).trim() === ":root";
|
|
10477
|
+
for (const child of blockChildren2(cssRule)) {
|
|
10478
|
+
if (child.type !== "Declaration" || !child.property.startsWith("--")) continue;
|
|
10479
|
+
if (!isRoot) {
|
|
10480
|
+
overriddenVariables.add(child.property);
|
|
10481
|
+
continue;
|
|
10498
10482
|
}
|
|
10499
|
-
|
|
10500
|
-
for (const [name, definitions] of themeDefinitions) {
|
|
10501
|
-
const definition = definitions.length === 1 ? definitions[0] : void 0;
|
|
10502
|
-
if (!definition || canonicalToken(name)) continue;
|
|
10503
|
-
if (!isTypographySize(name) && !name.startsWith("--tracking-")) continue;
|
|
10504
|
-
if (name.includes("--", 2)) continue;
|
|
10505
|
-
const value = identity2(definition.value);
|
|
10483
|
+
const value = declarationValue(context.sourceCode.getText(child));
|
|
10506
10484
|
if (!value) continue;
|
|
10507
|
-
const
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10485
|
+
const definitions = rootValues.get(child.property) ?? [];
|
|
10486
|
+
definitions.push(value);
|
|
10487
|
+
rootValues.set(child.property, definitions);
|
|
10488
|
+
}
|
|
10489
|
+
}
|
|
10490
|
+
function identity(value) {
|
|
10491
|
+
const variable = /^var\((?<name>--[a-z][a-z0-9-]*)\)$/u.exec(value);
|
|
10492
|
+
if (!variable) return lengthIdentity(value);
|
|
10493
|
+
const name = variable.groups?.name;
|
|
10494
|
+
if (!name || overriddenVariables.has(name)) return void 0;
|
|
10495
|
+
const definitions = rootValues.get(name);
|
|
10496
|
+
const definition = definitions?.length === 1 ? definitions[0] : void 0;
|
|
10497
|
+
return definition ? lengthIdentity(definition) : void 0;
|
|
10498
|
+
}
|
|
10499
|
+
for (const [name, definitions] of themeDefinitions) {
|
|
10500
|
+
const definition = definitions.length === 1 ? definitions[0] : void 0;
|
|
10501
|
+
if (!definition || canonicalToken(name)) continue;
|
|
10502
|
+
if (!isTypographySize(name) && !name.startsWith("--tracking-")) continue;
|
|
10503
|
+
if (name.includes("--", 2)) continue;
|
|
10504
|
+
const value = identity(definition.value);
|
|
10505
|
+
if (!value) continue;
|
|
10506
|
+
const prefix = name.startsWith("--text-") ? "--text-" : "--tracking-";
|
|
10507
|
+
for (const [other, otherDefinitions] of themeDefinitions) {
|
|
10508
|
+
const otherDefinition = otherDefinitions.length === 1 ? otherDefinitions[0] : void 0;
|
|
10509
|
+
if (!canonicalToken(other) || !other.startsWith(prefix) || !otherDefinition) continue;
|
|
10510
|
+
if (identity(otherDefinition.value) !== value) continue;
|
|
10511
|
+
if (prefix === "--text-" && ["--line-height", "--letter-spacing", "--font-weight"].some(
|
|
10512
|
+
(suffix) => themeDefinitions.has(`${name}${suffix}`) || themeDefinitions.has(`${other}${suffix}`)
|
|
10513
|
+
)) {
|
|
10514
|
+
continue;
|
|
10522
10515
|
}
|
|
10516
|
+
context.report({
|
|
10517
|
+
node: definition.node,
|
|
10518
|
+
message: `Theme token "${name}" duplicates the configured built-in "${other}" (${value}); reuse the "${other.slice(2)}" utility instead of defining an equivalent theme token.`
|
|
10519
|
+
});
|
|
10520
|
+
break;
|
|
10523
10521
|
}
|
|
10524
10522
|
}
|
|
10525
10523
|
for (const utility of utilities) {
|
|
@@ -10532,7 +10530,7 @@ var utilityMappingRule = {
|
|
|
10532
10530
|
});
|
|
10533
10531
|
continue;
|
|
10534
10532
|
}
|
|
10535
|
-
if (
|
|
10533
|
+
if (nameCounts.get(name) !== 1) continue;
|
|
10536
10534
|
const candidate = themeCandidate(name, context.sourceCode.getText(utility));
|
|
10537
10535
|
if (!candidate || themeTokens.has(candidate.token)) continue;
|
|
10538
10536
|
if (candidate.property === "font-size" && themeTokens.has(`--color-${name.slice(5)}`)) continue;
|