@dloizides/frontend-devtools 1.1.0 → 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 +76 -1
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +76 -1
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1170,10 +1170,15 @@ function findGuardBinding(ast) {
|
|
|
1170
1170
|
}
|
|
1171
1171
|
function buildGuardImportFix(fixer, sourceCode, utilImportPath) {
|
|
1172
1172
|
const importStatement = `import { ${GUARD_NAME} } from '${utilImportPath}';`;
|
|
1173
|
-
const
|
|
1173
|
+
const body = sourceCode.ast.body;
|
|
1174
|
+
const imports = body.filter((node) => node.type === "ImportDeclaration");
|
|
1174
1175
|
if (imports.length > 0) {
|
|
1175
1176
|
return fixer.insertTextAfter(imports[imports.length - 1], `
|
|
1176
1177
|
${importStatement}`);
|
|
1178
|
+
}
|
|
1179
|
+
if (body.length > 0) {
|
|
1180
|
+
return fixer.insertTextBefore(body[0], `${importStatement}
|
|
1181
|
+
`);
|
|
1177
1182
|
}
|
|
1178
1183
|
return fixer.insertTextBeforeRange([0, 0], `${importStatement}
|
|
1179
1184
|
`);
|
|
@@ -1425,6 +1430,75 @@ var no_product_imports_in_shared_default = {
|
|
|
1425
1430
|
}
|
|
1426
1431
|
};
|
|
1427
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
|
+
|
|
1428
1502
|
// src/rules/prefer-const-enum.js
|
|
1429
1503
|
function toPascalCase(value) {
|
|
1430
1504
|
const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[-_\s]+/).filter((w) => w.length > 0);
|
|
@@ -2005,6 +2079,7 @@ var ruleModules = [
|
|
|
2005
2079
|
no_null_check_default,
|
|
2006
2080
|
no_optional_undefined_default,
|
|
2007
2081
|
no_product_imports_in_shared_default,
|
|
2082
|
+
no_raw_color_literal_default,
|
|
2008
2083
|
prefer_const_enum_default,
|
|
2009
2084
|
require_stable_hook_args_default,
|
|
2010
2085
|
smart_max_lines_default
|