@dloizides/frontend-devtools 1.1.1 → 1.2.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/dist/eslint/index.js +70 -0
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +70 -0
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1430,6 +1430,75 @@ var no_product_imports_in_shared_default = {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
};
|
|
1432
1432
|
|
|
1433
|
+
// src/rules/no-raw-color-literal.js
|
|
1434
|
+
var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
1435
|
+
var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
|
|
1436
|
+
function containsRawColor(text) {
|
|
1437
|
+
if (typeof text !== "string" || text.length === 0) return false;
|
|
1438
|
+
if (FULL_HEX_COLOR.test(text.trim())) return true;
|
|
1439
|
+
return FUNCTIONAL_COLOR.test(text);
|
|
1440
|
+
}
|
|
1441
|
+
function isAllowedFile(filename, allow) {
|
|
1442
|
+
if (typeof filename !== "string") return false;
|
|
1443
|
+
const normalised = filename.split("\\").join("/");
|
|
1444
|
+
return allow.some((fragment) => normalised.includes(fragment));
|
|
1445
|
+
}
|
|
1446
|
+
var noRawColorLiteralRule = {
|
|
1447
|
+
meta: {
|
|
1448
|
+
type: "problem",
|
|
1449
|
+
docs: {
|
|
1450
|
+
description: "Disallow raw colour literals (hex / rgb() / hsl()) in app code. Colours belong in @dloizides/design-tokens and reach components through the theme.",
|
|
1451
|
+
category: "Best Practices",
|
|
1452
|
+
recommended: true
|
|
1453
|
+
},
|
|
1454
|
+
schema: [
|
|
1455
|
+
{
|
|
1456
|
+
type: "object",
|
|
1457
|
+
properties: {
|
|
1458
|
+
allow: {
|
|
1459
|
+
type: "array",
|
|
1460
|
+
items: { type: "string" }
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
additionalProperties: false
|
|
1464
|
+
}
|
|
1465
|
+
],
|
|
1466
|
+
messages: {
|
|
1467
|
+
rawColor: 'Raw colour literal "{{value}}" \u2014 use a design token instead (@dloizides/design-tokens via the theme). Hardcoded colours make a rebrand a find-and-replace across every file.'
|
|
1468
|
+
}
|
|
1469
|
+
},
|
|
1470
|
+
create(context) {
|
|
1471
|
+
const options = context.options[0] ?? {};
|
|
1472
|
+
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
1473
|
+
const filename = typeof context.getFilename === "function" ? context.getFilename() : context.filename;
|
|
1474
|
+
if (isAllowedFile(filename, allow)) return {};
|
|
1475
|
+
const report = (node, rawValue) => {
|
|
1476
|
+
const value = rawValue.trim();
|
|
1477
|
+
const display = value.length > 40 ? `${value.slice(0, 40)}\u2026` : value;
|
|
1478
|
+
context.report({ node, messageId: "rawColor", data: { value: display } });
|
|
1479
|
+
};
|
|
1480
|
+
return {
|
|
1481
|
+
Literal(node) {
|
|
1482
|
+
if (typeof node.value !== "string") return;
|
|
1483
|
+
if (!containsRawColor(node.value)) return;
|
|
1484
|
+
report(node, node.value);
|
|
1485
|
+
},
|
|
1486
|
+
// Template literals: check each static chunk, so an interpolated value
|
|
1487
|
+
// (`${primary}`) is fine but a baked-in rgba(...) chunk is not.
|
|
1488
|
+
TemplateElement(node) {
|
|
1489
|
+
const raw = node.value?.raw;
|
|
1490
|
+
if (!containsRawColor(raw)) return;
|
|
1491
|
+
report(node, raw);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
var no_raw_color_literal_default = {
|
|
1497
|
+
rules: {
|
|
1498
|
+
"no-raw-color-literal": noRawColorLiteralRule
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1433
1502
|
// src/rules/prefer-const-enum.js
|
|
1434
1503
|
function toPascalCase(value) {
|
|
1435
1504
|
const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[-_\s]+/).filter((w) => w.length > 0);
|
|
@@ -2010,6 +2079,7 @@ var ruleModules = [
|
|
|
2010
2079
|
no_null_check_default,
|
|
2011
2080
|
no_optional_undefined_default,
|
|
2012
2081
|
no_product_imports_in_shared_default,
|
|
2082
|
+
no_raw_color_literal_default,
|
|
2013
2083
|
prefer_const_enum_default,
|
|
2014
2084
|
require_stable_hook_args_default,
|
|
2015
2085
|
smart_max_lines_default
|