@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.
@@ -1437,6 +1437,75 @@ var no_product_imports_in_shared_default = {
1437
1437
  }
1438
1438
  };
1439
1439
 
1440
+ // src/rules/no-raw-color-literal.js
1441
+ var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1442
+ var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
1443
+ function containsRawColor(text) {
1444
+ if (typeof text !== "string" || text.length === 0) return false;
1445
+ if (FULL_HEX_COLOR.test(text.trim())) return true;
1446
+ return FUNCTIONAL_COLOR.test(text);
1447
+ }
1448
+ function isAllowedFile(filename, allow) {
1449
+ if (typeof filename !== "string") return false;
1450
+ const normalised = filename.split("\\").join("/");
1451
+ return allow.some((fragment) => normalised.includes(fragment));
1452
+ }
1453
+ var noRawColorLiteralRule = {
1454
+ meta: {
1455
+ type: "problem",
1456
+ docs: {
1457
+ description: "Disallow raw colour literals (hex / rgb() / hsl()) in app code. Colours belong in @dloizides/design-tokens and reach components through the theme.",
1458
+ category: "Best Practices",
1459
+ recommended: true
1460
+ },
1461
+ schema: [
1462
+ {
1463
+ type: "object",
1464
+ properties: {
1465
+ allow: {
1466
+ type: "array",
1467
+ items: { type: "string" }
1468
+ }
1469
+ },
1470
+ additionalProperties: false
1471
+ }
1472
+ ],
1473
+ messages: {
1474
+ 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.'
1475
+ }
1476
+ },
1477
+ create(context) {
1478
+ const options = context.options[0] ?? {};
1479
+ const allow = Array.isArray(options.allow) ? options.allow : [];
1480
+ const filename = typeof context.getFilename === "function" ? context.getFilename() : context.filename;
1481
+ if (isAllowedFile(filename, allow)) return {};
1482
+ const report = (node, rawValue) => {
1483
+ const value = rawValue.trim();
1484
+ const display = value.length > 40 ? `${value.slice(0, 40)}\u2026` : value;
1485
+ context.report({ node, messageId: "rawColor", data: { value: display } });
1486
+ };
1487
+ return {
1488
+ Literal(node) {
1489
+ if (typeof node.value !== "string") return;
1490
+ if (!containsRawColor(node.value)) return;
1491
+ report(node, node.value);
1492
+ },
1493
+ // Template literals: check each static chunk, so an interpolated value
1494
+ // (`${primary}`) is fine but a baked-in rgba(...) chunk is not.
1495
+ TemplateElement(node) {
1496
+ const raw = node.value?.raw;
1497
+ if (!containsRawColor(raw)) return;
1498
+ report(node, raw);
1499
+ }
1500
+ };
1501
+ }
1502
+ };
1503
+ var no_raw_color_literal_default = {
1504
+ rules: {
1505
+ "no-raw-color-literal": noRawColorLiteralRule
1506
+ }
1507
+ };
1508
+
1440
1509
  // src/rules/prefer-const-enum.js
1441
1510
  function toPascalCase(value) {
1442
1511
  const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[-_\s]+/).filter((w) => w.length > 0);
@@ -2017,6 +2086,7 @@ var ruleModules = [
2017
2086
  no_null_check_default,
2018
2087
  no_optional_undefined_default,
2019
2088
  no_product_imports_in_shared_default,
2089
+ no_raw_color_literal_default,
2020
2090
  prefer_const_enum_default,
2021
2091
  require_stable_hook_args_default,
2022
2092
  smart_max_lines_default