@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
|
@@ -229,7 +229,11 @@ function isCssColorFunction(value) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
// src/utils/color-lib-utils.ts
|
|
232
|
-
var
|
|
232
|
+
var LAB_THRESHOLD = 25;
|
|
233
|
+
var isHexCode = (color) => {
|
|
234
|
+
const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
|
|
235
|
+
return hexPattern.test(color);
|
|
236
|
+
};
|
|
233
237
|
var convertToHex = (color) => {
|
|
234
238
|
try {
|
|
235
239
|
return (0, import_chroma_js.default)(color).hex();
|
|
@@ -237,40 +241,52 @@ var convertToHex = (color) => {
|
|
|
237
241
|
return null;
|
|
238
242
|
}
|
|
239
243
|
};
|
|
240
|
-
var isHookPropertyMatch = (hook, cssProperty) => {
|
|
241
|
-
return hook.properties.includes(cssProperty) || hook.properties.includes("*");
|
|
242
|
-
};
|
|
243
|
-
function getOrderByCssProp(cssProperty) {
|
|
244
|
-
if (cssProperty === "color" || cssProperty === "fill") {
|
|
245
|
-
return ["surface", "theme", "feedback", "reference"];
|
|
246
|
-
} else if (cssProperty.match(/background/)) {
|
|
247
|
-
return ["surface", "surface-inverse", "theme", "feedback", "reference"];
|
|
248
|
-
} else if (cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {
|
|
249
|
-
return ["borders", "borders-inverse", "feedback", "theme", "reference"];
|
|
250
|
-
}
|
|
251
|
-
return ["surface", "surface-inverse", "borders", "borders-inverse", "theme", "feedback", "reference"];
|
|
252
|
-
}
|
|
253
244
|
var findClosestColorHook = (color, supportedColors, cssProperty) => {
|
|
254
|
-
const
|
|
245
|
+
const returnStylingHooks = [];
|
|
246
|
+
const closestHooksWithSameProperty = [];
|
|
247
|
+
const closestHooksWithoutSameProperty = [];
|
|
248
|
+
const closestHooksWithAllProperty = [];
|
|
249
|
+
const labColor = (0, import_chroma_js.default)(color).lab();
|
|
255
250
|
Object.entries(supportedColors).forEach(([sldsValue, data]) => {
|
|
256
|
-
if (sldsValue &&
|
|
251
|
+
if (sldsValue && isHexCode(sldsValue)) {
|
|
257
252
|
const hooks = data;
|
|
258
253
|
hooks.forEach((hook) => {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
254
|
+
const labSupportedColor = (0, import_chroma_js.default)(sldsValue).lab();
|
|
255
|
+
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");
|
|
256
|
+
if (hook.properties.includes(cssProperty)) {
|
|
257
|
+
if (distance <= LAB_THRESHOLD) {
|
|
258
|
+
closestHooksWithSameProperty.push({ name: hook.name, distance });
|
|
259
|
+
}
|
|
260
|
+
} else if (hook.properties.includes("*")) {
|
|
261
|
+
if (distance <= LAB_THRESHOLD) {
|
|
262
|
+
closestHooksWithAllProperty.push({ name: hook.name, distance });
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
if (distance <= LAB_THRESHOLD) {
|
|
266
|
+
closestHooksWithoutSameProperty.push({ name: hook.name, distance });
|
|
267
|
+
}
|
|
262
268
|
}
|
|
263
269
|
});
|
|
264
270
|
}
|
|
265
271
|
});
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
272
|
+
const closesthookGroups = [
|
|
273
|
+
{ hooks: closestHooksWithSameProperty, distance: 0 },
|
|
274
|
+
{ hooks: closestHooksWithAllProperty, distance: 0 },
|
|
275
|
+
{ hooks: closestHooksWithSameProperty, distance: Infinity },
|
|
276
|
+
// For hooks with distance > 0
|
|
277
|
+
{ hooks: closestHooksWithAllProperty, distance: Infinity },
|
|
278
|
+
{ hooks: closestHooksWithoutSameProperty, distance: Infinity }
|
|
279
|
+
];
|
|
280
|
+
for (const group of closesthookGroups) {
|
|
281
|
+
const filteredHooks = group.hooks.filter(
|
|
282
|
+
(h) => group.distance === 0 ? h.distance === 0 : h.distance > 0
|
|
283
|
+
);
|
|
284
|
+
if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {
|
|
285
|
+
filteredHooks.sort((a, b) => a.distance - b.distance);
|
|
286
|
+
returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));
|
|
269
287
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}, {});
|
|
273
|
-
return getOrderByCssProp(cssProperty).map((group) => hooksByGroupMap[group] || []).flat().slice(0, 5);
|
|
288
|
+
}
|
|
289
|
+
return Array.from(new Set(returnStylingHooks));
|
|
274
290
|
};
|
|
275
291
|
var isValidColor = (val) => import_chroma_js.default.valid(val);
|
|
276
292
|
var extractColorValue = (node) => {
|
|
@@ -369,9 +385,9 @@ function toSelector(properties) {
|
|
|
369
385
|
});
|
|
370
386
|
return selectorParts.join(", ");
|
|
371
387
|
}
|
|
372
|
-
function
|
|
388
|
+
function resolvePropertyToMatch(cssProperty) {
|
|
373
389
|
const propertyToMatch = cssProperty.toLowerCase();
|
|
374
|
-
if (
|
|
390
|
+
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
|
|
375
391
|
return "border-width";
|
|
376
392
|
} else if (isMarginProperty(propertyToMatch)) {
|
|
377
393
|
return "margin";
|
|
@@ -383,23 +399,13 @@ function resolveDensityPropertyToMatch(cssProperty) {
|
|
|
383
399
|
return "width";
|
|
384
400
|
} else if (isInsetProperty(propertyToMatch)) {
|
|
385
401
|
return "top";
|
|
386
|
-
}
|
|
387
|
-
return propertyToMatch;
|
|
388
|
-
}
|
|
389
|
-
function resolveColorPropertyToMatch(cssProperty) {
|
|
390
|
-
const propertyToMatch = cssProperty.toLowerCase();
|
|
391
|
-
if (propertyToMatch === "outline" || propertyToMatch === "outline-color") {
|
|
392
|
-
return "border-color";
|
|
393
|
-
} else if (propertyToMatch === "background" || propertyToMatch === "background-color") {
|
|
402
|
+
} else if (cssProperty === "background" || cssProperty === "background-color") {
|
|
394
403
|
return "background-color";
|
|
395
|
-
} else if (isBorderColorProperty(
|
|
404
|
+
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
|
|
396
405
|
return "border-color";
|
|
397
406
|
}
|
|
398
407
|
return propertyToMatch;
|
|
399
408
|
}
|
|
400
|
-
function isOutlineWidthProperty(propertyToMatch) {
|
|
401
|
-
return propertyToMatch === "outline" || propertyToMatch === "outline-width";
|
|
402
|
-
}
|
|
403
409
|
|
|
404
410
|
// src/utils/hardcoded-shared-utils.ts
|
|
405
411
|
var import_css_tree2 = require("@eslint/css-tree");
|
|
@@ -459,33 +465,13 @@ function isKnownFontWeight(value) {
|
|
|
459
465
|
return FONT_WEIGHTS.includes(stringValue.toLowerCase());
|
|
460
466
|
}
|
|
461
467
|
function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const reportNumericValue = context.options?.reportNumericValue || "always";
|
|
467
|
-
const fixCallback = (start, originalValue, replacement) => {
|
|
468
|
-
let newValue = valueText;
|
|
469
|
-
newValue = newValue.substring(0, start) + replacement + newValue.substring(start + originalValue.length);
|
|
470
|
-
if (newValue !== valueText) {
|
|
471
|
-
return (fixer) => {
|
|
472
|
-
return fixer.replaceText(declarationNode.value, newValue);
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook, isNumeric }) => {
|
|
468
|
+
const sortedReplacements = replacements.sort((a, b) => a.start - b.start);
|
|
469
|
+
const hasAnyHooks = sortedReplacements.some((r) => r.hasHook);
|
|
470
|
+
const canAutoFix = hasAnyHooks;
|
|
471
|
+
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook }) => {
|
|
477
472
|
const originalValue = valueText.substring(start, end);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
if (reportNumericValue === "hasReplacement" && !hasHook) {
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
const valueColumnStart = declarationNode.value.loc.start.column + start;
|
|
487
|
-
const valueColumnEnd = valueColumnStart + originalValue.length;
|
|
488
|
-
const canAutoFix = originalValue !== replacement;
|
|
473
|
+
const valueStartColumn = declarationNode.value.loc.start.column;
|
|
474
|
+
const valueColumn = valueStartColumn + start;
|
|
489
475
|
const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
|
|
490
476
|
const reportNode = {
|
|
491
477
|
...declarationNode.value,
|
|
@@ -493,16 +479,23 @@ function handleShorthandAutoFix(declarationNode, context, valueText, replacement
|
|
|
493
479
|
...declarationNode.value.loc,
|
|
494
480
|
start: {
|
|
495
481
|
...locStart,
|
|
496
|
-
column:
|
|
482
|
+
column: valueColumn
|
|
497
483
|
},
|
|
498
484
|
end: {
|
|
499
485
|
...locEnd,
|
|
500
|
-
column:
|
|
486
|
+
column: valueColumn + originalValue.length
|
|
501
487
|
}
|
|
502
488
|
}
|
|
503
489
|
};
|
|
504
490
|
if (hasHook) {
|
|
505
|
-
const fix = canAutoFix ?
|
|
491
|
+
const fix = canAutoFix ? (fixer) => {
|
|
492
|
+
let newValue = valueText;
|
|
493
|
+
for (let i = sortedReplacements.length - 1; i >= 0; i--) {
|
|
494
|
+
const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];
|
|
495
|
+
newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);
|
|
496
|
+
}
|
|
497
|
+
return fixer.replaceText(declarationNode.value, newValue);
|
|
498
|
+
} : void 0;
|
|
506
499
|
context.context.report({
|
|
507
500
|
node: reportNode,
|
|
508
501
|
messageId: "hardcodedValue",
|
|
@@ -656,41 +649,6 @@ function formatSuggestionHooks(hooks) {
|
|
|
656
649
|
return "\n" + hooks.map((hook, index) => `${index + 1}. ${hook}`).join("\n");
|
|
657
650
|
}
|
|
658
651
|
|
|
659
|
-
// src/utils/custom-mapping-utils.ts
|
|
660
|
-
function matchesPropertyPattern(cssProperty, pattern) {
|
|
661
|
-
const normalizedProperty = cssProperty.toLowerCase();
|
|
662
|
-
const normalizedPattern = pattern.toLowerCase();
|
|
663
|
-
if (normalizedProperty === normalizedPattern) {
|
|
664
|
-
return true;
|
|
665
|
-
}
|
|
666
|
-
if (normalizedPattern.endsWith("*")) {
|
|
667
|
-
const prefix = normalizedPattern.slice(0, -1);
|
|
668
|
-
return normalizedProperty.startsWith(prefix);
|
|
669
|
-
}
|
|
670
|
-
return false;
|
|
671
|
-
}
|
|
672
|
-
function getCustomMapping(cssProperty, value, customMapping) {
|
|
673
|
-
if (!customMapping) {
|
|
674
|
-
return null;
|
|
675
|
-
}
|
|
676
|
-
const normalizedValue = value.toLowerCase().trim();
|
|
677
|
-
for (const [hookName, config] of Object.entries(customMapping)) {
|
|
678
|
-
const propertyMatches = config.properties.some(
|
|
679
|
-
(pattern) => matchesPropertyPattern(cssProperty, pattern)
|
|
680
|
-
);
|
|
681
|
-
if (!propertyMatches) {
|
|
682
|
-
continue;
|
|
683
|
-
}
|
|
684
|
-
const valueMatches = config.values.some(
|
|
685
|
-
(configValue) => configValue.toLowerCase().trim() === normalizedValue
|
|
686
|
-
);
|
|
687
|
-
if (valueMatches) {
|
|
688
|
-
return hookName;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return null;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
652
|
// src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
|
|
695
653
|
var handleColorDeclaration = (node, context) => {
|
|
696
654
|
const cssProperty = node.property.toLowerCase();
|
|
@@ -714,32 +672,24 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
714
672
|
if (!hexValue) {
|
|
715
673
|
return null;
|
|
716
674
|
}
|
|
675
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
676
|
+
const closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
|
|
717
677
|
const start = positionInfo.start.offset;
|
|
718
678
|
const end = positionInfo.end.offset;
|
|
719
679
|
const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
let paletteHook = null;
|
|
730
|
-
if (context.options?.preferPaletteHook && closestHooks.length > 1) {
|
|
731
|
-
paletteHook = closestHooks.filter((hook) => hook.includes("-palette-"))[0];
|
|
732
|
-
}
|
|
733
|
-
if (paletteHook) {
|
|
734
|
-
replacement = `var(${paletteHook}, ${colorValue})`;
|
|
735
|
-
} else if (closestHooks.length === 1) {
|
|
736
|
-
replacement = `var(${closestHooks[0]}, ${colorValue})`;
|
|
737
|
-
}
|
|
738
|
-
if (closestHooks.length > 0) {
|
|
680
|
+
if (closestHooks.length === 1) {
|
|
681
|
+
return {
|
|
682
|
+
start,
|
|
683
|
+
end,
|
|
684
|
+
replacement: `var(${closestHooks[0]}, ${colorValue})`,
|
|
685
|
+
displayValue: closestHooks[0],
|
|
686
|
+
hasHook: true
|
|
687
|
+
};
|
|
688
|
+
} else if (closestHooks.length > 1) {
|
|
739
689
|
return {
|
|
740
690
|
start,
|
|
741
691
|
end,
|
|
742
|
-
replacement,
|
|
692
|
+
replacement: originalValue,
|
|
743
693
|
// Use original value to preserve spacing
|
|
744
694
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
745
695
|
hasHook: true
|
|
@@ -748,7 +698,7 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
748
698
|
return {
|
|
749
699
|
start,
|
|
750
700
|
end,
|
|
751
|
-
replacement,
|
|
701
|
+
replacement: originalValue,
|
|
752
702
|
// Use original value to preserve spacing
|
|
753
703
|
displayValue: originalValue,
|
|
754
704
|
hasHook: false
|
|
@@ -796,14 +746,8 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
796
746
|
return null;
|
|
797
747
|
}
|
|
798
748
|
const rawValue = parsedDimension.unit ? `${parsedDimension.number}${parsedDimension.unit}` : parsedDimension.number.toString();
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
if (customHook) {
|
|
802
|
-
closestHooks = [customHook];
|
|
803
|
-
} else {
|
|
804
|
-
const propToMatch = resolveDensityPropertyToMatch(cssProperty);
|
|
805
|
-
closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
806
|
-
}
|
|
749
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
750
|
+
const closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
807
751
|
const start = positionInfo.start.offset;
|
|
808
752
|
const end = positionInfo.end.offset;
|
|
809
753
|
if (closestHooks.length === 1) {
|
|
@@ -812,8 +756,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
812
756
|
end,
|
|
813
757
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
814
758
|
displayValue: closestHooks[0],
|
|
815
|
-
hasHook: true
|
|
816
|
-
isNumeric: true
|
|
759
|
+
hasHook: true
|
|
817
760
|
};
|
|
818
761
|
} else if (closestHooks.length > 1) {
|
|
819
762
|
return {
|
|
@@ -821,8 +764,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
821
764
|
end,
|
|
822
765
|
replacement: rawValue,
|
|
823
766
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
824
|
-
hasHook: true
|
|
825
|
-
isNumeric: true
|
|
767
|
+
hasHook: true
|
|
826
768
|
};
|
|
827
769
|
} else {
|
|
828
770
|
return {
|
|
@@ -830,8 +772,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
830
772
|
end,
|
|
831
773
|
replacement: rawValue,
|
|
832
774
|
displayValue: rawValue,
|
|
833
|
-
hasHook: false
|
|
834
|
-
isNumeric: true
|
|
775
|
+
hasHook: false
|
|
835
776
|
};
|
|
836
777
|
}
|
|
837
778
|
}
|
|
@@ -872,14 +813,8 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
872
813
|
return null;
|
|
873
814
|
}
|
|
874
815
|
const rawValue = fontValue.unit ? `${fontValue.number}${fontValue.unit}` : fontValue.number.toString();
|
|
875
|
-
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? "font-weight" : "font-size";
|
|
876
|
-
const
|
|
877
|
-
let closestHooks = [];
|
|
878
|
-
if (customHook) {
|
|
879
|
-
closestHooks = [customHook];
|
|
880
|
-
} else {
|
|
881
|
-
closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
882
|
-
}
|
|
816
|
+
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? resolvePropertyToMatch("font-weight") : resolvePropertyToMatch("font-size");
|
|
817
|
+
const closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
883
818
|
const start = positionInfo.start.offset;
|
|
884
819
|
const end = positionInfo.end.offset;
|
|
885
820
|
if (closestHooks.length === 1) {
|
|
@@ -888,8 +823,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
888
823
|
end,
|
|
889
824
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
890
825
|
displayValue: closestHooks[0],
|
|
891
|
-
hasHook: true
|
|
892
|
-
isNumeric: true
|
|
826
|
+
hasHook: true
|
|
893
827
|
};
|
|
894
828
|
} else if (closestHooks.length > 1) {
|
|
895
829
|
return {
|
|
@@ -897,8 +831,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
897
831
|
end,
|
|
898
832
|
replacement: rawValue,
|
|
899
833
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
900
|
-
hasHook: true
|
|
901
|
-
isNumeric: true
|
|
834
|
+
hasHook: true
|
|
902
835
|
};
|
|
903
836
|
} else {
|
|
904
837
|
return {
|
|
@@ -906,8 +839,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
906
839
|
end,
|
|
907
840
|
replacement: rawValue,
|
|
908
841
|
displayValue: rawValue,
|
|
909
|
-
hasHook: false
|
|
910
|
-
isNumeric: true
|
|
842
|
+
hasHook: false
|
|
911
843
|
};
|
|
912
844
|
}
|
|
913
845
|
}
|
|
@@ -1039,30 +971,9 @@ function shadowValueToHookEntries(supportedStylinghooks) {
|
|
|
1039
971
|
return [key, value.map((hook) => hook.name)];
|
|
1040
972
|
});
|
|
1041
973
|
}
|
|
1042
|
-
function reportBoxShadowViolation(node, context, valueText, hooks) {
|
|
1043
|
-
const positionInfo = {
|
|
1044
|
-
start: { offset: 0, line: 1, column: 1 },
|
|
1045
|
-
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
1046
|
-
};
|
|
1047
|
-
const replacement = createBoxShadowReplacement(
|
|
1048
|
-
valueText,
|
|
1049
|
-
hooks,
|
|
1050
|
-
context,
|
|
1051
|
-
positionInfo
|
|
1052
|
-
);
|
|
1053
|
-
if (replacement) {
|
|
1054
|
-
const replacements = [replacement];
|
|
1055
|
-
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
974
|
var handleBoxShadowDeclaration = (node, context) => {
|
|
1059
975
|
const cssProperty = node.property.toLowerCase();
|
|
1060
976
|
const valueText = context.sourceCode.getText(node.value);
|
|
1061
|
-
const customHook = getCustomMapping(cssProperty, valueText, context.options?.customMapping);
|
|
1062
|
-
if (customHook) {
|
|
1063
|
-
reportBoxShadowViolation(node, context, valueText, [customHook]);
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
977
|
const shadowHooks = shadowValueToHookEntries(context.valueToStylinghook);
|
|
1067
978
|
const parsedCssValue = toBoxShadowValue(valueText);
|
|
1068
979
|
if (!parsedCssValue) {
|
|
@@ -1072,7 +983,20 @@ var handleBoxShadowDeclaration = (node, context) => {
|
|
|
1072
983
|
const parsedValueHook = toBoxShadowValue(shadow);
|
|
1073
984
|
if (parsedValueHook && isBoxShadowMatch(parsedCssValue, parsedValueHook)) {
|
|
1074
985
|
if (closestHooks.length > 0) {
|
|
1075
|
-
|
|
986
|
+
const positionInfo = {
|
|
987
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
988
|
+
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
989
|
+
};
|
|
990
|
+
const replacement = createBoxShadowReplacement(
|
|
991
|
+
valueText,
|
|
992
|
+
closestHooks,
|
|
993
|
+
context,
|
|
994
|
+
positionInfo
|
|
995
|
+
);
|
|
996
|
+
if (replacement) {
|
|
997
|
+
const replacements = [replacement];
|
|
998
|
+
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
999
|
+
}
|
|
1076
1000
|
}
|
|
1077
1001
|
return;
|
|
1078
1002
|
}
|
|
@@ -1122,42 +1046,6 @@ function isRuleEnabled(context, ruleName2) {
|
|
|
1122
1046
|
}
|
|
1123
1047
|
}
|
|
1124
1048
|
|
|
1125
|
-
// src/rules/v9/no-hardcoded-values/ruleOptionsSchema.ts
|
|
1126
|
-
var ruleOptionsSchema = [
|
|
1127
|
-
{
|
|
1128
|
-
type: "object",
|
|
1129
|
-
properties: {
|
|
1130
|
-
reportNumericValue: {
|
|
1131
|
-
type: "string",
|
|
1132
|
-
enum: ["never", "always", "hasReplacement"],
|
|
1133
|
-
default: "always"
|
|
1134
|
-
},
|
|
1135
|
-
customMapping: {
|
|
1136
|
-
type: "object",
|
|
1137
|
-
additionalProperties: {
|
|
1138
|
-
type: "object",
|
|
1139
|
-
properties: {
|
|
1140
|
-
properties: {
|
|
1141
|
-
type: "array",
|
|
1142
|
-
items: { type: "string" }
|
|
1143
|
-
},
|
|
1144
|
-
values: {
|
|
1145
|
-
type: "array",
|
|
1146
|
-
items: { type: "string" }
|
|
1147
|
-
}
|
|
1148
|
-
},
|
|
1149
|
-
required: ["properties", "values"]
|
|
1150
|
-
}
|
|
1151
|
-
},
|
|
1152
|
-
preferPaletteHook: {
|
|
1153
|
-
type: "boolean",
|
|
1154
|
-
default: false
|
|
1155
|
-
}
|
|
1156
|
-
},
|
|
1157
|
-
additionalProperties: false
|
|
1158
|
-
}
|
|
1159
|
-
];
|
|
1160
|
-
|
|
1161
1049
|
// src/rules/v9/no-hardcoded-values/noHardcodedValueRule.ts
|
|
1162
1050
|
function defineNoHardcodedValueRule(config) {
|
|
1163
1051
|
const { ruleConfig: ruleConfig2, ruleName: ruleName2 } = config;
|
|
@@ -1171,24 +1059,16 @@ function defineNoHardcodedValueRule(config) {
|
|
|
1171
1059
|
url: url2
|
|
1172
1060
|
},
|
|
1173
1061
|
fixable: "code",
|
|
1174
|
-
messages: messages2
|
|
1175
|
-
schema: ruleOptionsSchema
|
|
1062
|
+
messages: messages2
|
|
1176
1063
|
},
|
|
1177
1064
|
create(context) {
|
|
1178
1065
|
if (ruleName2 === "no-hardcoded-values-slds1" && isRuleEnabled(context, "@salesforce-ux/slds/no-hardcoded-values-slds2")) {
|
|
1179
1066
|
return {};
|
|
1180
1067
|
}
|
|
1181
|
-
const options = context.options[0] || {};
|
|
1182
|
-
const ruleOptions = {
|
|
1183
|
-
reportNumericValue: options.reportNumericValue || "always",
|
|
1184
|
-
customMapping: options.customMapping || {},
|
|
1185
|
-
preferPaletteHook: options.preferPaletteHook || false
|
|
1186
|
-
};
|
|
1187
1068
|
const handlerContext = {
|
|
1188
1069
|
valueToStylinghook: config.valueToStylinghook,
|
|
1189
1070
|
context,
|
|
1190
|
-
sourceCode: context.sourceCode
|
|
1191
|
-
options: ruleOptions
|
|
1071
|
+
sourceCode: context.sourceCode
|
|
1192
1072
|
};
|
|
1193
1073
|
const colorOnlySelector = toSelector(colorProperties);
|
|
1194
1074
|
const densityOnlySelector = toSelector(densificationProperties);
|