@salesforce-ux/eslint-plugin-slds 1.0.6-internal → 1.0.7-internal
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/README.md +27 -62
- package/build/index.js +128 -258
- package/build/index.js.map +4 -4
- package/build/rules/v9/lwc-token-to-slds-hook.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +30 -86
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +104 -116
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +30 -83
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +74 -78
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/index.js +99 -175
- package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +101 -221
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +101 -221
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +101 -221
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +3 -3
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js.map +2 -2
- package/build/src/types/index.d.ts +0 -31
- package/build/src/utils/color-lib-utils.d.ts +9 -16
- package/build/src/utils/hardcoded-shared-utils.d.ts +0 -1
- package/build/src/utils/property-matcher.d.ts +1 -3
- package/build/types/index.js.map +1 -1
- package/build/utils/boxShadowValueParser.js.map +2 -2
- package/build/utils/color-lib-utils.js +50 -26
- package/build/utils/color-lib-utils.js.map +2 -2
- package/build/utils/css-utils.js.map +2 -2
- package/build/utils/hardcoded-shared-utils.js +16 -29
- package/build/utils/hardcoded-shared-utils.js.map +2 -2
- package/build/utils/property-matcher.js +6 -20
- package/build/utils/property-matcher.js.map +2 -2
- package/eslint.config.mjs +2 -5
- package/package.json +2 -2
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js +0 -63
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js.map +0 -7
- package/build/src/rules/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +0 -40
- package/build/src/utils/custom-mapping-utils.d.ts +0 -9
- package/build/utils/custom-mapping-utils.js +0 -62
- package/build/utils/custom-mapping-utils.js.map +0 -7
|
@@ -67,7 +67,11 @@ function isCssColorFunction(value) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/utils/color-lib-utils.ts
|
|
70
|
-
var
|
|
70
|
+
var LAB_THRESHOLD = 25;
|
|
71
|
+
var isHexCode = (color) => {
|
|
72
|
+
const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
|
|
73
|
+
return hexPattern.test(color);
|
|
74
|
+
};
|
|
71
75
|
var convertToHex = (color) => {
|
|
72
76
|
try {
|
|
73
77
|
return (0, import_chroma_js.default)(color).hex();
|
|
@@ -75,40 +79,52 @@ var convertToHex = (color) => {
|
|
|
75
79
|
return null;
|
|
76
80
|
}
|
|
77
81
|
};
|
|
78
|
-
var isHookPropertyMatch = (hook, cssProperty) => {
|
|
79
|
-
return hook.properties.includes(cssProperty) || hook.properties.includes("*");
|
|
80
|
-
};
|
|
81
|
-
function getOrderByCssProp(cssProperty) {
|
|
82
|
-
if (cssProperty === "color" || cssProperty === "fill") {
|
|
83
|
-
return ["surface", "theme", "feedback", "reference"];
|
|
84
|
-
} else if (cssProperty.match(/background/)) {
|
|
85
|
-
return ["surface", "surface-inverse", "theme", "feedback", "reference"];
|
|
86
|
-
} else if (cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {
|
|
87
|
-
return ["borders", "borders-inverse", "feedback", "theme", "reference"];
|
|
88
|
-
}
|
|
89
|
-
return ["surface", "surface-inverse", "borders", "borders-inverse", "theme", "feedback", "reference"];
|
|
90
|
-
}
|
|
91
82
|
var findClosestColorHook = (color, supportedColors, cssProperty) => {
|
|
92
|
-
const
|
|
83
|
+
const returnStylingHooks = [];
|
|
84
|
+
const closestHooksWithSameProperty = [];
|
|
85
|
+
const closestHooksWithoutSameProperty = [];
|
|
86
|
+
const closestHooksWithAllProperty = [];
|
|
87
|
+
const labColor = (0, import_chroma_js.default)(color).lab();
|
|
93
88
|
Object.entries(supportedColors).forEach(([sldsValue, data]) => {
|
|
94
|
-
if (sldsValue &&
|
|
89
|
+
if (sldsValue && isHexCode(sldsValue)) {
|
|
95
90
|
const hooks = data;
|
|
96
91
|
hooks.forEach((hook) => {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
const labSupportedColor = (0, import_chroma_js.default)(sldsValue).lab();
|
|
93
|
+
const distance = JSON.stringify(labColor) === JSON.stringify(labSupportedColor) ? 0 : import_chroma_js.default.distance(import_chroma_js.default.lab(...labColor), import_chroma_js.default.lab(...labSupportedColor), "lab");
|
|
94
|
+
if (hook.properties.includes(cssProperty)) {
|
|
95
|
+
if (distance <= LAB_THRESHOLD) {
|
|
96
|
+
closestHooksWithSameProperty.push({ name: hook.name, distance });
|
|
97
|
+
}
|
|
98
|
+
} else if (hook.properties.includes("*")) {
|
|
99
|
+
if (distance <= LAB_THRESHOLD) {
|
|
100
|
+
closestHooksWithAllProperty.push({ name: hook.name, distance });
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
if (distance <= LAB_THRESHOLD) {
|
|
104
|
+
closestHooksWithoutSameProperty.push({ name: hook.name, distance });
|
|
105
|
+
}
|
|
100
106
|
}
|
|
101
107
|
});
|
|
102
108
|
}
|
|
103
109
|
});
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
const closesthookGroups = [
|
|
111
|
+
{ hooks: closestHooksWithSameProperty, distance: 0 },
|
|
112
|
+
{ hooks: closestHooksWithAllProperty, distance: 0 },
|
|
113
|
+
{ hooks: closestHooksWithSameProperty, distance: Infinity },
|
|
114
|
+
// For hooks with distance > 0
|
|
115
|
+
{ hooks: closestHooksWithAllProperty, distance: Infinity },
|
|
116
|
+
{ hooks: closestHooksWithoutSameProperty, distance: Infinity }
|
|
117
|
+
];
|
|
118
|
+
for (const group of closesthookGroups) {
|
|
119
|
+
const filteredHooks = group.hooks.filter(
|
|
120
|
+
(h) => group.distance === 0 ? h.distance === 0 : h.distance > 0
|
|
121
|
+
);
|
|
122
|
+
if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {
|
|
123
|
+
filteredHooks.sort((a, b) => a.distance - b.distance);
|
|
124
|
+
returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));
|
|
107
125
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}, {});
|
|
111
|
-
return getOrderByCssProp(cssProperty).map((group) => hooksByGroupMap[group] || []).flat().slice(0, 5);
|
|
126
|
+
}
|
|
127
|
+
return Array.from(new Set(returnStylingHooks));
|
|
112
128
|
};
|
|
113
129
|
var isValidColor = (val) => import_chroma_js.default.valid(val);
|
|
114
130
|
var extractColorValue = (node) => {
|
|
@@ -207,9 +223,9 @@ function toSelector(properties) {
|
|
|
207
223
|
});
|
|
208
224
|
return selectorParts.join(", ");
|
|
209
225
|
}
|
|
210
|
-
function
|
|
226
|
+
function resolvePropertyToMatch(cssProperty) {
|
|
211
227
|
const propertyToMatch = cssProperty.toLowerCase();
|
|
212
|
-
if (
|
|
228
|
+
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
|
|
213
229
|
return "border-width";
|
|
214
230
|
} else if (isMarginProperty(propertyToMatch)) {
|
|
215
231
|
return "margin";
|
|
@@ -221,23 +237,13 @@ function resolveDensityPropertyToMatch(cssProperty) {
|
|
|
221
237
|
return "width";
|
|
222
238
|
} else if (isInsetProperty(propertyToMatch)) {
|
|
223
239
|
return "top";
|
|
224
|
-
}
|
|
225
|
-
return propertyToMatch;
|
|
226
|
-
}
|
|
227
|
-
function resolveColorPropertyToMatch(cssProperty) {
|
|
228
|
-
const propertyToMatch = cssProperty.toLowerCase();
|
|
229
|
-
if (propertyToMatch === "outline" || propertyToMatch === "outline-color") {
|
|
230
|
-
return "border-color";
|
|
231
|
-
} else if (propertyToMatch === "background" || propertyToMatch === "background-color") {
|
|
240
|
+
} else if (cssProperty === "background" || cssProperty === "background-color") {
|
|
232
241
|
return "background-color";
|
|
233
|
-
} else if (isBorderColorProperty(
|
|
242
|
+
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
|
|
234
243
|
return "border-color";
|
|
235
244
|
}
|
|
236
245
|
return propertyToMatch;
|
|
237
246
|
}
|
|
238
|
-
function isOutlineWidthProperty(propertyToMatch) {
|
|
239
|
-
return propertyToMatch === "outline" || propertyToMatch === "outline-width";
|
|
240
|
-
}
|
|
241
247
|
|
|
242
248
|
// src/utils/hardcoded-shared-utils.ts
|
|
243
249
|
var import_css_tree2 = require("@eslint/css-tree");
|
|
@@ -297,33 +303,13 @@ function isKnownFontWeight(value) {
|
|
|
297
303
|
return FONT_WEIGHTS.includes(stringValue.toLowerCase());
|
|
298
304
|
}
|
|
299
305
|
function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const reportNumericValue = context.options?.reportNumericValue || "always";
|
|
305
|
-
const fixCallback = (start, originalValue, replacement) => {
|
|
306
|
-
let newValue = valueText;
|
|
307
|
-
newValue = newValue.substring(0, start) + replacement + newValue.substring(start + originalValue.length);
|
|
308
|
-
if (newValue !== valueText) {
|
|
309
|
-
return (fixer) => {
|
|
310
|
-
return fixer.replaceText(declarationNode.value, newValue);
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook, isNumeric }) => {
|
|
306
|
+
const sortedReplacements = replacements.sort((a, b) => a.start - b.start);
|
|
307
|
+
const hasAnyHooks = sortedReplacements.some((r) => r.hasHook);
|
|
308
|
+
const canAutoFix = hasAnyHooks;
|
|
309
|
+
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook }) => {
|
|
315
310
|
const originalValue = valueText.substring(start, end);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (reportNumericValue === "hasReplacement" && !hasHook) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
const valueColumnStart = declarationNode.value.loc.start.column + start;
|
|
325
|
-
const valueColumnEnd = valueColumnStart + originalValue.length;
|
|
326
|
-
const canAutoFix = originalValue !== replacement;
|
|
311
|
+
const valueStartColumn = declarationNode.value.loc.start.column;
|
|
312
|
+
const valueColumn = valueStartColumn + start;
|
|
327
313
|
const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
|
|
328
314
|
const reportNode = {
|
|
329
315
|
...declarationNode.value,
|
|
@@ -331,16 +317,23 @@ function handleShorthandAutoFix(declarationNode, context, valueText, replacement
|
|
|
331
317
|
...declarationNode.value.loc,
|
|
332
318
|
start: {
|
|
333
319
|
...locStart,
|
|
334
|
-
column:
|
|
320
|
+
column: valueColumn
|
|
335
321
|
},
|
|
336
322
|
end: {
|
|
337
323
|
...locEnd,
|
|
338
|
-
column:
|
|
324
|
+
column: valueColumn + originalValue.length
|
|
339
325
|
}
|
|
340
326
|
}
|
|
341
327
|
};
|
|
342
328
|
if (hasHook) {
|
|
343
|
-
const fix = canAutoFix ?
|
|
329
|
+
const fix = canAutoFix ? (fixer) => {
|
|
330
|
+
let newValue = valueText;
|
|
331
|
+
for (let i = sortedReplacements.length - 1; i >= 0; i--) {
|
|
332
|
+
const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];
|
|
333
|
+
newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);
|
|
334
|
+
}
|
|
335
|
+
return fixer.replaceText(declarationNode.value, newValue);
|
|
336
|
+
} : void 0;
|
|
344
337
|
context.context.report({
|
|
345
338
|
node: reportNode,
|
|
346
339
|
messageId: "hardcodedValue",
|
|
@@ -494,41 +487,6 @@ function formatSuggestionHooks(hooks) {
|
|
|
494
487
|
return "\n" + hooks.map((hook, index) => `${index + 1}. ${hook}`).join("\n");
|
|
495
488
|
}
|
|
496
489
|
|
|
497
|
-
// src/utils/custom-mapping-utils.ts
|
|
498
|
-
function matchesPropertyPattern(cssProperty, pattern) {
|
|
499
|
-
const normalizedProperty = cssProperty.toLowerCase();
|
|
500
|
-
const normalizedPattern = pattern.toLowerCase();
|
|
501
|
-
if (normalizedProperty === normalizedPattern) {
|
|
502
|
-
return true;
|
|
503
|
-
}
|
|
504
|
-
if (normalizedPattern.endsWith("*")) {
|
|
505
|
-
const prefix = normalizedPattern.slice(0, -1);
|
|
506
|
-
return normalizedProperty.startsWith(prefix);
|
|
507
|
-
}
|
|
508
|
-
return false;
|
|
509
|
-
}
|
|
510
|
-
function getCustomMapping(cssProperty, value, customMapping) {
|
|
511
|
-
if (!customMapping) {
|
|
512
|
-
return null;
|
|
513
|
-
}
|
|
514
|
-
const normalizedValue = value.toLowerCase().trim();
|
|
515
|
-
for (const [hookName, config] of Object.entries(customMapping)) {
|
|
516
|
-
const propertyMatches = config.properties.some(
|
|
517
|
-
(pattern) => matchesPropertyPattern(cssProperty, pattern)
|
|
518
|
-
);
|
|
519
|
-
if (!propertyMatches) {
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
const valueMatches = config.values.some(
|
|
523
|
-
(configValue) => configValue.toLowerCase().trim() === normalizedValue
|
|
524
|
-
);
|
|
525
|
-
if (valueMatches) {
|
|
526
|
-
return hookName;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
return null;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
490
|
// src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
|
|
533
491
|
var handleColorDeclaration = (node, context) => {
|
|
534
492
|
const cssProperty = node.property.toLowerCase();
|
|
@@ -552,32 +510,24 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
552
510
|
if (!hexValue) {
|
|
553
511
|
return null;
|
|
554
512
|
}
|
|
513
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
514
|
+
const closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
|
|
555
515
|
const start = positionInfo.start.offset;
|
|
556
516
|
const end = positionInfo.end.offset;
|
|
557
517
|
const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
let paletteHook = null;
|
|
568
|
-
if (context.options?.preferPaletteHook && closestHooks.length > 1) {
|
|
569
|
-
paletteHook = closestHooks.filter((hook) => hook.includes("-palette-"))[0];
|
|
570
|
-
}
|
|
571
|
-
if (paletteHook) {
|
|
572
|
-
replacement = `var(${paletteHook}, ${colorValue})`;
|
|
573
|
-
} else if (closestHooks.length === 1) {
|
|
574
|
-
replacement = `var(${closestHooks[0]}, ${colorValue})`;
|
|
575
|
-
}
|
|
576
|
-
if (closestHooks.length > 0) {
|
|
518
|
+
if (closestHooks.length === 1) {
|
|
519
|
+
return {
|
|
520
|
+
start,
|
|
521
|
+
end,
|
|
522
|
+
replacement: `var(${closestHooks[0]}, ${colorValue})`,
|
|
523
|
+
displayValue: closestHooks[0],
|
|
524
|
+
hasHook: true
|
|
525
|
+
};
|
|
526
|
+
} else if (closestHooks.length > 1) {
|
|
577
527
|
return {
|
|
578
528
|
start,
|
|
579
529
|
end,
|
|
580
|
-
replacement,
|
|
530
|
+
replacement: originalValue,
|
|
581
531
|
// Use original value to preserve spacing
|
|
582
532
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
583
533
|
hasHook: true
|
|
@@ -586,7 +536,7 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
586
536
|
return {
|
|
587
537
|
start,
|
|
588
538
|
end,
|
|
589
|
-
replacement,
|
|
539
|
+
replacement: originalValue,
|
|
590
540
|
// Use original value to preserve spacing
|
|
591
541
|
displayValue: originalValue,
|
|
592
542
|
hasHook: false
|
|
@@ -634,14 +584,8 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
634
584
|
return null;
|
|
635
585
|
}
|
|
636
586
|
const rawValue = parsedDimension.unit ? `${parsedDimension.number}${parsedDimension.unit}` : parsedDimension.number.toString();
|
|
637
|
-
const
|
|
638
|
-
|
|
639
|
-
if (customHook) {
|
|
640
|
-
closestHooks = [customHook];
|
|
641
|
-
} else {
|
|
642
|
-
const propToMatch = resolveDensityPropertyToMatch(cssProperty);
|
|
643
|
-
closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
644
|
-
}
|
|
587
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
588
|
+
const closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
645
589
|
const start = positionInfo.start.offset;
|
|
646
590
|
const end = positionInfo.end.offset;
|
|
647
591
|
if (closestHooks.length === 1) {
|
|
@@ -650,8 +594,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
650
594
|
end,
|
|
651
595
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
652
596
|
displayValue: closestHooks[0],
|
|
653
|
-
hasHook: true
|
|
654
|
-
isNumeric: true
|
|
597
|
+
hasHook: true
|
|
655
598
|
};
|
|
656
599
|
} else if (closestHooks.length > 1) {
|
|
657
600
|
return {
|
|
@@ -659,8 +602,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
659
602
|
end,
|
|
660
603
|
replacement: rawValue,
|
|
661
604
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
662
|
-
hasHook: true
|
|
663
|
-
isNumeric: true
|
|
605
|
+
hasHook: true
|
|
664
606
|
};
|
|
665
607
|
} else {
|
|
666
608
|
return {
|
|
@@ -668,8 +610,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
668
610
|
end,
|
|
669
611
|
replacement: rawValue,
|
|
670
612
|
displayValue: rawValue,
|
|
671
|
-
hasHook: false
|
|
672
|
-
isNumeric: true
|
|
613
|
+
hasHook: false
|
|
673
614
|
};
|
|
674
615
|
}
|
|
675
616
|
}
|
|
@@ -710,14 +651,8 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
710
651
|
return null;
|
|
711
652
|
}
|
|
712
653
|
const rawValue = fontValue.unit ? `${fontValue.number}${fontValue.unit}` : fontValue.number.toString();
|
|
713
|
-
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? "font-weight" : "font-size";
|
|
714
|
-
const
|
|
715
|
-
let closestHooks = [];
|
|
716
|
-
if (customHook) {
|
|
717
|
-
closestHooks = [customHook];
|
|
718
|
-
} else {
|
|
719
|
-
closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
720
|
-
}
|
|
654
|
+
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? resolvePropertyToMatch("font-weight") : resolvePropertyToMatch("font-size");
|
|
655
|
+
const closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
721
656
|
const start = positionInfo.start.offset;
|
|
722
657
|
const end = positionInfo.end.offset;
|
|
723
658
|
if (closestHooks.length === 1) {
|
|
@@ -726,8 +661,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
726
661
|
end,
|
|
727
662
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
728
663
|
displayValue: closestHooks[0],
|
|
729
|
-
hasHook: true
|
|
730
|
-
isNumeric: true
|
|
664
|
+
hasHook: true
|
|
731
665
|
};
|
|
732
666
|
} else if (closestHooks.length > 1) {
|
|
733
667
|
return {
|
|
@@ -735,8 +669,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
735
669
|
end,
|
|
736
670
|
replacement: rawValue,
|
|
737
671
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
738
|
-
hasHook: true
|
|
739
|
-
isNumeric: true
|
|
672
|
+
hasHook: true
|
|
740
673
|
};
|
|
741
674
|
} else {
|
|
742
675
|
return {
|
|
@@ -744,8 +677,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
744
677
|
end,
|
|
745
678
|
replacement: rawValue,
|
|
746
679
|
displayValue: rawValue,
|
|
747
|
-
hasHook: false
|
|
748
|
-
isNumeric: true
|
|
680
|
+
hasHook: false
|
|
749
681
|
};
|
|
750
682
|
}
|
|
751
683
|
}
|
|
@@ -877,30 +809,9 @@ function shadowValueToHookEntries(supportedStylinghooks) {
|
|
|
877
809
|
return [key, value.map((hook) => hook.name)];
|
|
878
810
|
});
|
|
879
811
|
}
|
|
880
|
-
function reportBoxShadowViolation(node, context, valueText, hooks) {
|
|
881
|
-
const positionInfo = {
|
|
882
|
-
start: { offset: 0, line: 1, column: 1 },
|
|
883
|
-
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
884
|
-
};
|
|
885
|
-
const replacement = createBoxShadowReplacement(
|
|
886
|
-
valueText,
|
|
887
|
-
hooks,
|
|
888
|
-
context,
|
|
889
|
-
positionInfo
|
|
890
|
-
);
|
|
891
|
-
if (replacement) {
|
|
892
|
-
const replacements = [replacement];
|
|
893
|
-
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
812
|
var handleBoxShadowDeclaration = (node, context) => {
|
|
897
813
|
const cssProperty = node.property.toLowerCase();
|
|
898
814
|
const valueText = context.sourceCode.getText(node.value);
|
|
899
|
-
const customHook = getCustomMapping(cssProperty, valueText, context.options?.customMapping);
|
|
900
|
-
if (customHook) {
|
|
901
|
-
reportBoxShadowViolation(node, context, valueText, [customHook]);
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
815
|
const shadowHooks = shadowValueToHookEntries(context.valueToStylinghook);
|
|
905
816
|
const parsedCssValue = toBoxShadowValue(valueText);
|
|
906
817
|
if (!parsedCssValue) {
|
|
@@ -910,7 +821,20 @@ var handleBoxShadowDeclaration = (node, context) => {
|
|
|
910
821
|
const parsedValueHook = toBoxShadowValue(shadow);
|
|
911
822
|
if (parsedValueHook && isBoxShadowMatch(parsedCssValue, parsedValueHook)) {
|
|
912
823
|
if (closestHooks.length > 0) {
|
|
913
|
-
|
|
824
|
+
const positionInfo = {
|
|
825
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
826
|
+
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
827
|
+
};
|
|
828
|
+
const replacement = createBoxShadowReplacement(
|
|
829
|
+
valueText,
|
|
830
|
+
closestHooks,
|
|
831
|
+
context,
|
|
832
|
+
positionInfo
|
|
833
|
+
);
|
|
834
|
+
if (replacement) {
|
|
835
|
+
const replacements = [replacement];
|
|
836
|
+
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
837
|
+
}
|
|
914
838
|
}
|
|
915
839
|
return;
|
|
916
840
|
}
|
|
@@ -960,42 +884,6 @@ function isRuleEnabled(context, ruleName) {
|
|
|
960
884
|
}
|
|
961
885
|
}
|
|
962
886
|
|
|
963
|
-
// src/rules/v9/no-hardcoded-values/ruleOptionsSchema.ts
|
|
964
|
-
var ruleOptionsSchema = [
|
|
965
|
-
{
|
|
966
|
-
type: "object",
|
|
967
|
-
properties: {
|
|
968
|
-
reportNumericValue: {
|
|
969
|
-
type: "string",
|
|
970
|
-
enum: ["never", "always", "hasReplacement"],
|
|
971
|
-
default: "always"
|
|
972
|
-
},
|
|
973
|
-
customMapping: {
|
|
974
|
-
type: "object",
|
|
975
|
-
additionalProperties: {
|
|
976
|
-
type: "object",
|
|
977
|
-
properties: {
|
|
978
|
-
properties: {
|
|
979
|
-
type: "array",
|
|
980
|
-
items: { type: "string" }
|
|
981
|
-
},
|
|
982
|
-
values: {
|
|
983
|
-
type: "array",
|
|
984
|
-
items: { type: "string" }
|
|
985
|
-
}
|
|
986
|
-
},
|
|
987
|
-
required: ["properties", "values"]
|
|
988
|
-
}
|
|
989
|
-
},
|
|
990
|
-
preferPaletteHook: {
|
|
991
|
-
type: "boolean",
|
|
992
|
-
default: false
|
|
993
|
-
}
|
|
994
|
-
},
|
|
995
|
-
additionalProperties: false
|
|
996
|
-
}
|
|
997
|
-
];
|
|
998
|
-
|
|
999
887
|
// src/rules/v9/no-hardcoded-values/noHardcodedValueRule.ts
|
|
1000
888
|
function defineNoHardcodedValueRule(config) {
|
|
1001
889
|
const { ruleConfig, ruleName } = config;
|
|
@@ -1009,24 +897,16 @@ function defineNoHardcodedValueRule(config) {
|
|
|
1009
897
|
url
|
|
1010
898
|
},
|
|
1011
899
|
fixable: "code",
|
|
1012
|
-
messages
|
|
1013
|
-
schema: ruleOptionsSchema
|
|
900
|
+
messages
|
|
1014
901
|
},
|
|
1015
902
|
create(context) {
|
|
1016
903
|
if (ruleName === "no-hardcoded-values-slds1" && isRuleEnabled(context, "@salesforce-ux/slds/no-hardcoded-values-slds2")) {
|
|
1017
904
|
return {};
|
|
1018
905
|
}
|
|
1019
|
-
const options = context.options[0] || {};
|
|
1020
|
-
const ruleOptions = {
|
|
1021
|
-
reportNumericValue: options.reportNumericValue || "always",
|
|
1022
|
-
customMapping: options.customMapping || {},
|
|
1023
|
-
preferPaletteHook: options.preferPaletteHook || false
|
|
1024
|
-
};
|
|
1025
906
|
const handlerContext = {
|
|
1026
907
|
valueToStylinghook: config.valueToStylinghook,
|
|
1027
908
|
context,
|
|
1028
|
-
sourceCode: context.sourceCode
|
|
1029
|
-
options: ruleOptions
|
|
909
|
+
sourceCode: context.sourceCode
|
|
1030
910
|
};
|
|
1031
911
|
const colorOnlySelector = toSelector(colorProperties);
|
|
1032
912
|
const densityOnlySelector = toSelector(densificationProperties);
|