pasika 0.10.151 → 0.10.153
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 +65 -4
- package/package.json +1 -1
|
@@ -10196,16 +10196,64 @@ var colorLiteralUsageRule = {
|
|
|
10196
10196
|
schema: [],
|
|
10197
10197
|
type: "problem",
|
|
10198
10198
|
docs: {
|
|
10199
|
-
description: "Require
|
|
10199
|
+
description: "Require reusable colors in tokens and one-off fixed colors inline."
|
|
10200
10200
|
}
|
|
10201
10201
|
},
|
|
10202
10202
|
create(context) {
|
|
10203
10203
|
return {
|
|
10204
10204
|
"StyleSheet:exit"(node) {
|
|
10205
10205
|
const masked = maskNonColors(context.sourceCode.text);
|
|
10206
|
+
const declarations = [...masked.matchAll(DECLARATION)];
|
|
10207
|
+
const applyExpressions = [...masked.matchAll(APPLY)];
|
|
10208
|
+
const literalKey = (text) => {
|
|
10209
|
+
const normalized = text.toLowerCase().replace(/\s+/gu, " ").trim();
|
|
10210
|
+
if (/^#[\da-f]{3,4}$/u.test(normalized)) {
|
|
10211
|
+
return `#${normalized.slice(1).replace(/[\da-f]/gu, (digit) => digit.repeat(2))}`;
|
|
10212
|
+
}
|
|
10213
|
+
return normalized;
|
|
10214
|
+
};
|
|
10215
|
+
const literalUses = /* @__PURE__ */ new Map();
|
|
10216
|
+
const literalColorTokens = /* @__PURE__ */ new Map();
|
|
10217
|
+
const colorTokenReferences = /* @__PURE__ */ new Map();
|
|
10218
|
+
const trackReferences = (value, start) => {
|
|
10219
|
+
for (const match of value.matchAll(/\bvar\s*\(\s*(?<token>--color-[\w-]+)\s*\)/giu)) {
|
|
10220
|
+
const token = match.groups?.token;
|
|
10221
|
+
if (!token) continue;
|
|
10222
|
+
const references = colorTokenReferences.get(token) ?? [];
|
|
10223
|
+
references.push({ offset: start + match.index, text: match[0] });
|
|
10224
|
+
colorTokenReferences.set(token, references);
|
|
10225
|
+
}
|
|
10226
|
+
};
|
|
10227
|
+
for (const match of declarations) {
|
|
10228
|
+
const property = match.groups?.property;
|
|
10229
|
+
const value = match.groups?.value;
|
|
10230
|
+
if (!property || value === void 0) continue;
|
|
10231
|
+
if (property.startsWith("--color-")) {
|
|
10232
|
+
const colors = colorLiterals(value);
|
|
10233
|
+
if (colors.length === 1 && colors[0]?.text === value.trim()) {
|
|
10234
|
+
literalColorTokens.set(property, { color: colors[0].text, key: literalKey(colors[0].text) });
|
|
10235
|
+
}
|
|
10236
|
+
}
|
|
10237
|
+
trackReferences(value, match.index + match[0].lastIndexOf(value));
|
|
10238
|
+
}
|
|
10239
|
+
for (const match of applyExpressions) {
|
|
10240
|
+
const value = match.groups?.value;
|
|
10241
|
+
if (value === void 0) continue;
|
|
10242
|
+
trackReferences(value, match.index + match[0].indexOf(value));
|
|
10243
|
+
}
|
|
10244
|
+
for (const match of [...declarations, ...applyExpressions]) {
|
|
10245
|
+
const value = match.groups?.value;
|
|
10246
|
+
if (value === void 0) continue;
|
|
10247
|
+
for (const color of colorLiterals(value)) {
|
|
10248
|
+
const key = literalKey(color.text);
|
|
10249
|
+
literalUses.set(key, (literalUses.get(key) ?? 0) + 1);
|
|
10250
|
+
}
|
|
10251
|
+
}
|
|
10206
10252
|
const reported = /* @__PURE__ */ new Set();
|
|
10207
10253
|
const reportValue = (value, start) => {
|
|
10208
|
-
|
|
10254
|
+
const colors = colorLiterals(value);
|
|
10255
|
+
for (const color of colors) {
|
|
10256
|
+
if (literalUses.get(literalKey(color.text)) === 1) continue;
|
|
10209
10257
|
const offset = start + color.offset;
|
|
10210
10258
|
if (reported.has(offset)) continue;
|
|
10211
10259
|
reported.add(offset);
|
|
@@ -10217,17 +10265,30 @@ var colorLiteralUsageRule = {
|
|
|
10217
10265
|
});
|
|
10218
10266
|
}
|
|
10219
10267
|
};
|
|
10220
|
-
for (const match of
|
|
10268
|
+
for (const match of declarations) {
|
|
10221
10269
|
const property = match.groups?.property;
|
|
10222
10270
|
const value = match.groups?.value;
|
|
10223
10271
|
if (!property || value === void 0 || property.startsWith("--color-")) continue;
|
|
10224
10272
|
reportValue(value, match.index + match[0].lastIndexOf(value));
|
|
10225
10273
|
}
|
|
10226
|
-
for (const match of
|
|
10274
|
+
for (const match of applyExpressions) {
|
|
10227
10275
|
const value = match.groups?.value;
|
|
10228
10276
|
if (value === void 0) continue;
|
|
10229
10277
|
reportValue(value, match.index + match[0].indexOf(value));
|
|
10230
10278
|
}
|
|
10279
|
+
for (const [token, definition] of literalColorTokens) {
|
|
10280
|
+
const references = colorTokenReferences.get(token);
|
|
10281
|
+
if (references?.length !== 1 || literalUses.get(definition.key) !== 1) continue;
|
|
10282
|
+
const reference = references[0];
|
|
10283
|
+
if (!reference) continue;
|
|
10284
|
+
const start = context.sourceCode.getLocFromIndex(reference.offset);
|
|
10285
|
+
const end = context.sourceCode.getLocFromIndex(reference.offset + reference.text.length);
|
|
10286
|
+
context.report({
|
|
10287
|
+
node,
|
|
10288
|
+
loc: { start, end },
|
|
10289
|
+
message: `Inline one-off fixed color "${definition.color}" instead of referencing "${token}" through var().`
|
|
10290
|
+
});
|
|
10291
|
+
}
|
|
10231
10292
|
}
|
|
10232
10293
|
};
|
|
10233
10294
|
}
|