@salesforce-ux/eslint-plugin-slds 1.0.8-internal → 1.0.10-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.
Files changed (107) hide show
  1. package/build/config/rule-messages.d.ts +2 -0
  2. package/build/config/rule-messages.js +197 -0
  3. package/build/config/rule-messages.js.map +7 -0
  4. package/build/index.js +77 -2459
  5. package/build/index.js.map +4 -4
  6. package/build/rules/enforce-bem-usage.js +16 -232
  7. package/build/rules/enforce-bem-usage.js.map +4 -4
  8. package/build/rules/modal-close-button-issue.js +11 -183
  9. package/build/rules/modal-close-button-issue.js.map +4 -4
  10. package/build/rules/no-deprecated-classes-slds2.js +4 -176
  11. package/build/rules/no-deprecated-classes-slds2.js.map +4 -4
  12. package/build/rules/v9/enforce-bem-usage.js +1 -161
  13. package/build/rules/v9/enforce-bem-usage.js.map +4 -4
  14. package/build/rules/v9/enforce-component-hook-naming-convention.js +1 -161
  15. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +4 -4
  16. package/build/rules/v9/enforce-sds-to-slds-hooks.js +1 -161
  17. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +4 -4
  18. package/build/rules/v9/lwc-token-to-slds-hook.js +4 -262
  19. package/build/rules/v9/lwc-token-to-slds-hook.js.map +4 -4
  20. package/build/rules/v9/no-deprecated-slds-classes.js +1 -161
  21. package/build/rules/v9/no-deprecated-slds-classes.js.map +4 -4
  22. package/build/rules/v9/no-deprecated-tokens-slds1.js +29 -168
  23. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +4 -4
  24. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +9 -289
  25. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +4 -4
  26. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +13 -283
  27. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +4 -4
  28. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +12 -328
  29. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +4 -4
  30. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +13 -309
  31. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +4 -4
  32. package/build/rules/v9/no-hardcoded-values/handlers/index.js +8 -875
  33. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +4 -4
  34. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +3 -1208
  35. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +4 -4
  36. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +3 -1208
  37. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +4 -4
  38. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +22 -993
  39. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +4 -4
  40. package/build/rules/v9/no-slds-class-overrides.js +1 -161
  41. package/build/rules/v9/no-slds-class-overrides.js.map +4 -4
  42. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +3 -252
  43. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +4 -4
  44. package/build/rules/v9/no-slds-private-var.js +1 -161
  45. package/build/rules/v9/no-slds-private-var.js.map +4 -4
  46. package/build/rules/v9/no-slds-var-without-fallback.js +3 -255
  47. package/build/rules/v9/no-slds-var-without-fallback.js.map +4 -4
  48. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +1 -161
  49. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +4 -4
  50. package/build/rules/v9/no-unsupported-hooks-slds2.js +1 -161
  51. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +4 -4
  52. package/build/rules/v9/reduce-annotations.js +1 -161
  53. package/build/rules/v9/reduce-annotations.js.map +4 -4
  54. package/build/{src/utils → utils}/boxShadowValueParser.d.ts +1 -1
  55. package/build/utils/boxShadowValueParser.js +63 -93
  56. package/build/utils/boxShadowValueParser.js.map +4 -4
  57. package/build/utils/color-lib-utils.js +2 -29
  58. package/build/utils/color-lib-utils.js.map +3 -3
  59. package/build/{src/utils → utils}/css-utils.d.ts +7 -0
  60. package/build/utils/css-utils.js +10 -71
  61. package/build/utils/css-utils.js.map +4 -4
  62. package/build/utils/hardcoded-shared-utils.js +17 -82
  63. package/build/utils/hardcoded-shared-utils.js.map +4 -4
  64. package/build/utils/property-matcher.js +2 -2
  65. package/build/utils/property-matcher.js.map +2 -2
  66. package/build/utils/styling-hook-utils.js +16 -39
  67. package/build/utils/styling-hook-utils.js.map +3 -3
  68. package/build/{src/utils → utils}/value-utils.d.ts +2 -2
  69. package/build/utils/value-utils.js +8 -8
  70. package/build/utils/value-utils.js.map +2 -2
  71. package/package.json +5 -10
  72. package/src/config/rule-messages.yml +0 -143
  73. /package/build/{src/index.d.ts → index.d.ts} +0 -0
  74. /package/build/{src/rules → rules}/enforce-bem-usage.d.ts +0 -0
  75. /package/build/{src/rules → rules}/modal-close-button-issue.d.ts +0 -0
  76. /package/build/{src/rules → rules}/no-deprecated-classes-slds2.d.ts +0 -0
  77. /package/build/{src/rules → rules}/v9/enforce-bem-usage.d.ts +0 -0
  78. /package/build/{src/rules → rules}/v9/enforce-component-hook-naming-convention.d.ts +0 -0
  79. /package/build/{src/rules → rules}/v9/enforce-sds-to-slds-hooks.d.ts +0 -0
  80. /package/build/{src/rules → rules}/v9/lwc-token-to-slds-hook.d.ts +0 -0
  81. /package/build/{src/rules → rules}/v9/no-deprecated-slds-classes.d.ts +0 -0
  82. /package/build/{src/rules → rules}/v9/no-deprecated-tokens-slds1.d.ts +0 -0
  83. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/boxShadowHandler.d.ts +0 -0
  84. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/colorHandler.d.ts +0 -0
  85. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/densityHandler.d.ts +0 -0
  86. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/fontHandler.d.ts +0 -0
  87. /package/build/{src/rules → rules}/v9/no-hardcoded-values/handlers/index.d.ts +0 -0
  88. /package/build/{src/rules → rules}/v9/no-hardcoded-values/no-hardcoded-values-slds1.d.ts +0 -0
  89. /package/build/{src/rules → rules}/v9/no-hardcoded-values/no-hardcoded-values-slds2.d.ts +0 -0
  90. /package/build/{src/rules → rules}/v9/no-hardcoded-values/noHardcodedValueRule.d.ts +0 -0
  91. /package/build/{src/rules → rules}/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +0 -0
  92. /package/build/{src/rules → rules}/v9/no-slds-class-overrides.d.ts +0 -0
  93. /package/build/{src/rules → rules}/v9/no-slds-namespace-for-custom-hooks.d.ts +0 -0
  94. /package/build/{src/rules → rules}/v9/no-slds-private-var.d.ts +0 -0
  95. /package/build/{src/rules → rules}/v9/no-slds-var-without-fallback.d.ts +0 -0
  96. /package/build/{src/rules → rules}/v9/no-sldshook-fallback-for-lwctoken.d.ts +0 -0
  97. /package/build/{src/rules → rules}/v9/no-unsupported-hooks-slds2.d.ts +0 -0
  98. /package/build/{src/rules → rules}/v9/reduce-annotations.d.ts +0 -0
  99. /package/build/{src/types → types}/index.d.ts +0 -0
  100. /package/build/{src/utils → utils}/color-lib-utils.d.ts +0 -0
  101. /package/build/{src/utils → utils}/css-functions.d.ts +0 -0
  102. /package/build/{src/utils → utils}/custom-mapping-utils.d.ts +0 -0
  103. /package/build/{src/utils → utils}/hardcoded-shared-utils.d.ts +0 -0
  104. /package/build/{src/utils → utils}/node.d.ts +0 -0
  105. /package/build/{src/utils → utils}/property-matcher.d.ts +0 -0
  106. /package/build/{src/utils → utils}/rule-utils.d.ts +0 -0
  107. /package/build/{src/utils → utils}/styling-hook-utils.d.ts +0 -0
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
@@ -32,303 +22,43 @@ __export(colorHandler_exports, {
32
22
  handleColorDeclaration: () => handleColorDeclaration
33
23
  });
34
24
  module.exports = __toCommonJS(colorHandler_exports);
35
-
36
- // src/utils/color-lib-utils.ts
37
- var import_chroma_js = __toESM(require("chroma-js"));
38
- var import_css_tree = require("@eslint/css-tree");
39
-
40
- // src/utils/css-functions.ts
41
- var CSS_FUNCTIONS = [
42
- "attr",
43
- "calc",
44
- "color-mix",
45
- "conic-gradient",
46
- "counter",
47
- "cubic-bezier",
48
- "linear-gradient",
49
- "max",
50
- "min",
51
- "radial-gradient",
52
- "repeating-conic-gradient",
53
- "repeating-linear-gradient",
54
- "repeating-radial-gradient",
55
- "var"
56
- ];
57
- var CSS_MATH_FUNCTIONS = ["calc", "min", "max"];
58
- var RGB_COLOR_FUNCTIONS = ["rgb", "rgba", "hsl", "hsla"];
59
- var cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join("|")})`);
60
- var cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join("|")})$`);
61
- var cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join("|")})$`);
62
- function isCssFunction(value) {
63
- return cssFunctionsExactRegex.test(value);
64
- }
65
- function isCssColorFunction(value) {
66
- return RGB_COLOR_FUNCTIONS.includes(value);
67
- }
68
-
69
- // src/utils/color-lib-utils.ts
70
- var DELTAE_THRESHOLD = 10;
71
- var convertToHex = (color) => {
72
- try {
73
- return (0, import_chroma_js.default)(color).hex();
74
- } catch (e) {
75
- return null;
76
- }
77
- };
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
- var findClosestColorHook = (color, supportedColors, cssProperty) => {
92
- const closestHooks = [];
93
- Object.entries(supportedColors).forEach(([sldsValue, data]) => {
94
- if (sldsValue && isValidColor(sldsValue)) {
95
- const hooks = data;
96
- hooks.forEach((hook) => {
97
- const distance = sldsValue.toLowerCase() === color.toLowerCase() ? 0 : import_chroma_js.default.deltaE(sldsValue, color);
98
- if (isHookPropertyMatch(hook, cssProperty) && distance <= DELTAE_THRESHOLD) {
99
- closestHooks.push({ distance, group: hook.group, name: hook.name });
100
- }
101
- });
102
- }
103
- });
104
- const hooksByGroupMap = closestHooks.sort((a, b) => a.distance - b.distance).reduce((acc, hook) => {
105
- if (!acc[hook.group]) {
106
- acc[hook.group] = [];
107
- }
108
- acc[hook.group].push(hook.name);
109
- return acc;
110
- }, {});
111
- return getOrderByCssProp(cssProperty).map((group) => hooksByGroupMap[group] || []).flat().slice(0, 5);
112
- };
113
- var isValidColor = (val) => import_chroma_js.default.valid(val);
114
- var extractColorValue = (node) => {
115
- let colorValue = null;
116
- switch (node.type) {
117
- case "Hash":
118
- colorValue = `#${node.value}`;
119
- break;
120
- case "Identifier":
121
- colorValue = node.name;
122
- break;
123
- case "Function":
124
- if (isCssColorFunction(node.name)) {
125
- colorValue = (0, import_css_tree.generate)(node);
126
- }
127
- break;
128
- }
129
- return colorValue && isValidColor(colorValue) ? colorValue : null;
130
- };
131
-
132
- // src/utils/property-matcher.ts
133
- var DIRECTION_VALUES = "(?:top|right|bottom|left|inline|block|inline-start|inline-end|start|end|block-start|block-end)";
134
- var CORNER_VALUES = "(?:top-left|top-right|bottom-right|bottom-left|start-start|start-end|end-start|end-end)";
135
- var INSET_VALUES = "(?:inline|block|inline-start|inline-end|block-start|block-end)";
136
- var BORDER_COLOR_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-color$`);
137
- var BORDER_WIDTH_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-width$`);
138
- var MARGIN_REGEX = new RegExp(`^margin(?:-${DIRECTION_VALUES})?$`);
139
- var PADDING_REGEX = new RegExp(`^padding(?:-${DIRECTION_VALUES})?$`);
140
- var BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);
141
- var INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);
142
- function isBorderColorProperty(cssProperty) {
143
- return BORDER_COLOR_REGEX.test(cssProperty);
144
- }
145
- function resolveColorPropertyToMatch(cssProperty) {
146
- const propertyToMatch = cssProperty.toLowerCase();
147
- if (propertyToMatch === "outline" || propertyToMatch === "outline-color") {
148
- return "border-color";
149
- } else if (propertyToMatch === "background" || propertyToMatch === "background-color") {
150
- return "background-color";
151
- } else if (isBorderColorProperty(propertyToMatch)) {
152
- return "border-color";
153
- }
154
- return propertyToMatch;
155
- }
156
-
157
- // src/utils/hardcoded-shared-utils.ts
158
- var import_css_tree2 = require("@eslint/css-tree");
159
- function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
160
- if (!replacements || replacements.length === 0) {
161
- return;
162
- }
163
- const sortedReplacements = replacements.sort((a, b) => b.start - a.start);
164
- const reportNumericValue = context.options?.reportNumericValue || "always";
165
- const fixCallback = (start, originalValue, replacement) => {
166
- let newValue = valueText;
167
- newValue = newValue.substring(0, start) + replacement + newValue.substring(start + originalValue.length);
168
- if (newValue !== valueText) {
169
- return (fixer) => {
170
- return fixer.replaceText(declarationNode.value, newValue);
171
- };
172
- }
173
- };
174
- sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook, isNumeric }) => {
175
- const originalValue = valueText.substring(start, end);
176
- if (isNumeric) {
177
- if (reportNumericValue === "never") {
178
- return;
179
- }
180
- if (reportNumericValue === "hasReplacement" && !hasHook) {
181
- return;
182
- }
183
- }
184
- const valueColumnStart = declarationNode.value.loc.start.column + start;
185
- const valueColumnEnd = valueColumnStart + originalValue.length;
186
- const canAutoFix = originalValue !== replacement;
187
- const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
188
- const reportNode = {
189
- ...declarationNode.value,
190
- loc: {
191
- ...declarationNode.value.loc,
192
- start: {
193
- ...locStart,
194
- column: valueColumnStart
195
- },
196
- end: {
197
- ...locEnd,
198
- column: valueColumnEnd
199
- }
200
- }
201
- };
202
- if (hasHook) {
203
- const fix = canAutoFix ? fixCallback(start, originalValue, replacement) : void 0;
204
- context.context.report({
205
- node: reportNode,
206
- messageId: "hardcodedValue",
207
- data: {
208
- oldValue: originalValue,
209
- newValue: displayValue
210
- },
211
- fix
212
- });
213
- } else {
214
- context.context.report({
215
- node: reportNode,
216
- messageId: "noReplacement",
217
- data: {
218
- oldValue: originalValue
219
- }
220
- });
221
- }
222
- });
223
- }
224
- function forEachValue(valueText, extractValue, shouldSkipNode, callback) {
225
- if (!valueText || typeof valueText !== "string") {
226
- return;
227
- }
228
- try {
229
- const ast = (0, import_css_tree2.parse)(valueText, { context: "value", positions: true });
230
- (0, import_css_tree2.walk)(ast, {
231
- enter(node) {
232
- if (shouldSkipNode(node)) {
233
- return this.skip;
234
- }
235
- const value = extractValue(node);
236
- if (value !== null) {
237
- const positionInfo = {
238
- start: node.loc?.start,
239
- end: node.loc?.end
240
- };
241
- callback(value, positionInfo);
242
- }
243
- }
244
- });
245
- } catch (error) {
246
- return;
247
- }
248
- }
249
- function shouldSkipColorNode(node) {
250
- return node.type === "Function" && isCssFunction(node.name);
251
- }
252
- function forEachColorValue(valueText, callback) {
253
- forEachValue(valueText, extractColorValue, shouldSkipColorNode, callback);
254
- }
255
-
256
- // src/utils/css-utils.ts
257
- function formatSuggestionHooks(hooks) {
258
- if (hooks.length === 1) {
259
- return `${hooks[0]}`;
260
- }
261
- return "\n" + hooks.map((hook, index) => `${index + 1}. ${hook}`).join("\n");
262
- }
263
-
264
- // src/utils/custom-mapping-utils.ts
265
- function matchesPropertyPattern(cssProperty, pattern) {
266
- const normalizedProperty = cssProperty.toLowerCase();
267
- const normalizedPattern = pattern.toLowerCase();
268
- if (normalizedProperty === normalizedPattern) {
269
- return true;
270
- }
271
- if (normalizedPattern.endsWith("*")) {
272
- const prefix = normalizedPattern.slice(0, -1);
273
- return normalizedProperty.startsWith(prefix);
274
- }
275
- return false;
276
- }
277
- function getCustomMapping(cssProperty, value, customMapping) {
278
- if (!customMapping) {
279
- return null;
280
- }
281
- const normalizedValue = value.toLowerCase().trim();
282
- for (const [hookName, config] of Object.entries(customMapping)) {
283
- const propertyMatches = config.properties.some(
284
- (pattern) => matchesPropertyPattern(cssProperty, pattern)
285
- );
286
- if (!propertyMatches) {
287
- continue;
288
- }
289
- const valueMatches = config.values.some(
290
- (configValue) => configValue.toLowerCase().trim() === normalizedValue
291
- );
292
- if (valueMatches) {
293
- return hookName;
294
- }
295
- }
296
- return null;
297
- }
298
-
299
- // src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
25
+ var import_color_lib_utils = require("../../../../utils/color-lib-utils");
26
+ var import_property_matcher = require("../../../../utils/property-matcher");
27
+ var import_css_utils = require("../../../../utils/css-utils");
28
+ var import_custom_mapping_utils = require("../../../../utils/custom-mapping-utils");
29
+ var import_hardcoded_shared_utils = require("../../../../utils/hardcoded-shared-utils");
300
30
  var handleColorDeclaration = (node, context) => {
301
31
  const cssProperty = node.property.toLowerCase();
302
32
  const valueText = context.sourceCode.getText(node.value);
303
33
  const replacements = [];
304
- forEachColorValue(valueText, (colorValue, positionInfo) => {
305
- if (colorValue !== "transparent" && isValidColor(colorValue)) {
34
+ (0, import_hardcoded_shared_utils.forEachColorValue)(valueText, (colorValue, positionInfo) => {
35
+ if (colorValue !== "transparent" && (0, import_color_lib_utils.isValidColor)(colorValue)) {
306
36
  const replacement = createColorReplacement(colorValue, cssProperty, context, positionInfo, valueText);
307
37
  if (replacement) {
308
38
  replacements.push(replacement);
309
39
  }
310
40
  }
311
41
  });
312
- handleShorthandAutoFix(node, context, valueText, replacements);
42
+ (0, import_hardcoded_shared_utils.handleShorthandAutoFix)(node, context, valueText, replacements);
313
43
  };
314
44
  function createColorReplacement(colorValue, cssProperty, context, positionInfo, originalValueText) {
315
45
  if (!positionInfo?.start) {
316
46
  return null;
317
47
  }
318
- const hexValue = convertToHex(colorValue);
48
+ const hexValue = (0, import_color_lib_utils.convertToHex)(colorValue);
319
49
  if (!hexValue) {
320
50
  return null;
321
51
  }
322
52
  const start = positionInfo.start.offset;
323
53
  const end = positionInfo.end.offset;
324
54
  const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;
325
- const customHook = getCustomMapping(cssProperty, colorValue, context.options?.customMapping);
55
+ const customHook = (0, import_custom_mapping_utils.getCustomMapping)(cssProperty, colorValue, context.options?.customMapping);
326
56
  let closestHooks = [];
327
57
  if (customHook) {
328
58
  closestHooks = [customHook];
329
59
  } else {
330
- const propToMatch = resolveColorPropertyToMatch(cssProperty);
331
- closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
60
+ const propToMatch = (0, import_property_matcher.resolveColorPropertyToMatch)(cssProperty);
61
+ closestHooks = (0, import_color_lib_utils.findClosestColorHook)(hexValue, context.valueToStylinghook, propToMatch);
332
62
  }
333
63
  let replacement = originalValue;
334
64
  let paletteHook = null;
@@ -346,7 +76,7 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
346
76
  end,
347
77
  replacement,
348
78
  // Use original value to preserve spacing
349
- displayValue: formatSuggestionHooks(closestHooks),
79
+ displayValue: (0, import_css_utils.formatSuggestionHooks)(closestHooks),
350
80
  hasHook: true
351
81
  };
352
82
  } else {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../../../src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts", "../../../../../src/utils/color-lib-utils.ts", "../../../../../src/utils/css-functions.ts", "../../../../../src/utils/property-matcher.ts", "../../../../../src/utils/hardcoded-shared-utils.ts", "../../../../../src/utils/css-utils.ts", "../../../../../src/utils/custom-mapping-utils.ts"],
4
- "sourcesContent": ["import { findClosestColorHook, convertToHex, isValidColor } from '../../../../utils/color-lib-utils';\nimport { resolveColorPropertyToMatch } from '../../../../utils/property-matcher';\nimport { formatSuggestionHooks } from '../../../../utils/css-utils';\nimport { getCustomMapping } from '../../../../utils/custom-mapping-utils';\nimport type { HandlerContext, DeclarationHandler } from '../../../../types';\n\n// Import shared utilities for common logic\nimport { \n handleShorthandAutoFix, \n forEachColorValue,\n type ReplacementInfo,\n type PositionInfo\n} from '../../../../utils/hardcoded-shared-utils';\n\n\n/**\n * Handle color declarations using CSS tree parsing\n * Supports shorthand properties like background, border, etc. \n * Uses css-tree for reliable AST-based parsing + chroma-js validation\n */\nexport const handleColorDeclaration: DeclarationHandler = (node: any, context: HandlerContext) => {\n const cssProperty = node.property.toLowerCase();\n const valueText = context.sourceCode.getText(node.value);\n const replacements: ReplacementInfo[] = [];\n \n forEachColorValue(valueText, (colorValue, positionInfo) => {\n if (colorValue !== 'transparent' && isValidColor(colorValue)) {\n const replacement = createColorReplacement(colorValue, cssProperty, context, positionInfo, valueText);\n if (replacement) {\n replacements.push(replacement);\n }\n }\n });\n \n // Apply shorthand auto-fix once all values are processed\n handleShorthandAutoFix(node, context, valueText, replacements);\n};\n\n\n/**\n * Create color replacement info for shorthand auto-fix\n * Returns replacement data or null if no valid replacement\n */\nfunction createColorReplacement(\n colorValue: string,\n cssProperty: string,\n context: HandlerContext,\n positionInfo: PositionInfo,\n originalValueText?: string\n): ReplacementInfo | null {\n if (!positionInfo?.start) {\n return null;\n }\n\n const hexValue = convertToHex(colorValue);\n if (!hexValue) {\n return null;\n }\n\n // Use position information directly from CSS tree (already 0-based offsets)\n const start = positionInfo.start.offset;\n const end = positionInfo.end.offset;\n \n // Extract the original value from the CSS text to preserve spacing\n const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;\n\n // Check custom mapping first\n const customHook = getCustomMapping(cssProperty, colorValue, context.options?.customMapping);\n let closestHooks: string[] = [];\n \n if (customHook) {\n // Use custom mapping if available\n closestHooks = [customHook];\n } else {\n // Otherwise, find closest hooks from metadata\n const propToMatch = resolveColorPropertyToMatch(cssProperty);\n closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);\n }\n\n let replacement = originalValue;\n let paletteHook = null;\n // Apply preferPaletteHook filter if enabled\n if (context.options?.preferPaletteHook && closestHooks.length > 1) {\n paletteHook = closestHooks.filter(hook => hook.includes('-palette-'))[0];\n }\n if(paletteHook){\n replacement = `var(${paletteHook}, ${colorValue})`;\n } else if(closestHooks.length === 1){\n replacement = `var(${closestHooks[0]}, ${colorValue})`;\n }\n\n if (closestHooks.length > 0) {\n // Multiple hooks - format them for better readability\n return {\n start,\n end,\n replacement, // Use original value to preserve spacing\n displayValue: formatSuggestionHooks(closestHooks),\n hasHook: true \n };\n } else {\n // No hooks - keep original value\n return {\n start,\n end,\n replacement, // Use original value to preserve spacing\n displayValue: originalValue,\n hasHook: false\n };\n }\n}\n\n\n\n\n\n", "import { ValueToStylingHooksMapping, ValueToStylingHookEntry } from '@salesforce-ux/sds-metadata/next';\nimport chroma from 'chroma-js';\nimport { generate } from '@eslint/css-tree';\nimport { isCssColorFunction } from './css-functions';\n\n/**\n * Perceptual color difference threshold (Delta E, CIEDE2000 via chroma.deltaE).\n * Lower values are stricter matches. Used to decide which hooks are \"close enough\".\n */\nconst DELTAE_THRESHOLD = 10;\n\n/**\n * Convert any valid CSS color (named, hex, rgb(a), hsl(a), etc.) to hex.\n * Returns null if the value is not a valid color.\n */\nconst convertToHex = (color: string): string | null => {\n try {\n // Try converting the color using chroma-js, which handles both named and hex colors\n return chroma(color).hex();\n } catch (e) {\n // If chroma can't process the color, it's likely invalid\n return null;\n }\n};\n\nconst isHookPropertyMatch = (hook: ValueToStylingHookEntry, cssProperty: string): boolean => {\n return hook.properties.includes(cssProperty) || hook.properties.includes(\"*\");\n}\n\nfunction getOrderByCssProp(cssProperty: string): string[] {\n if(cssProperty === 'color' || cssProperty === 'fill') {\n return [\"surface\", \"theme\", \"feedback\", \"reference\"];\n } else if(cssProperty.match(/background/)){\n return [\"surface\", \"surface-inverse\", \"theme\", \"feedback\", \"reference\"];\n } else if(cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {\n return [\"borders\", \"borders-inverse\", \"feedback\", \"theme\", \"reference\"];\n }\n return [\"surface\", \"surface-inverse\", \"borders\", \"borders-inverse\", \"theme\", \"feedback\", \"reference\"];\n}\n\n\n/**\n * Given an input color and the metadata mapping of supported colors to hooks,\n * suggest up to 5 styling hook names ordered by:\n * 1) Category priority: semantic -> system -> palette\n * 2) Perceptual distance (Delta E)\n * Also prioritizes exact color matches (distance 0).\n */\nconst findClosestColorHook = (\n color: string,\n supportedColors:ValueToStylingHooksMapping,\n cssProperty: string\n): string[] => {\n const closestHooks: Array<{distance: number, group: string, name: string}> = [];\n Object.entries(supportedColors).forEach(([sldsValue, data]) => {\n if (sldsValue && isValidColor(sldsValue)) {\n const hooks = data as ValueToStylingHookEntry[]; // Get the hooks for the sldsValue\n\n hooks.forEach((hook) => {\n // Exact match shortcut to avoid floating rounding noise\n const distance = (sldsValue.toLowerCase() === color.toLowerCase())\n ? 0\n : chroma.deltaE(sldsValue, color);\n \n // Check if the hook has the same property or universal selector\n if (isHookPropertyMatch(hook, cssProperty) && distance <= DELTAE_THRESHOLD) {\n // Add to same property hooks if within threshold\n closestHooks.push({ distance, group: hook.group, name: hook.name });\n }\n });\n }\n });\n\n const hooksByGroupMap:Record<string, string[]> = closestHooks.sort((a, b) => a.distance - b.distance).reduce((acc, hook) => {\n if (!acc[hook.group]) {\n acc[hook.group] = [];\n }\n acc[hook.group].push(hook.name);\n return acc;\n }, {});\n\n return getOrderByCssProp(cssProperty)\n .map(group => hooksByGroupMap[group]||[])\n .flat().slice(0, 5);\n};\n\n/**\n * Check if a value is any valid CSS color string (delegates to chroma-js).\n */\nconst isValidColor = (val:string):boolean => chroma.valid(val);\n\n/**\n * Extract a color string from a CSS AST node produced by @eslint/css-tree.\n * Supports Hash (#rrggbb), Identifier (named colors), and color Function nodes.\n * Returns null if the extracted value is not a valid color.\n */\nconst extractColorValue = (node: any): string | null => {\n let colorValue: string | null = null;\n \n switch (node.type) {\n case 'Hash':\n colorValue = `#${node.value}`;\n break;\n case 'Identifier':\n colorValue = node.name;\n break;\n case 'Function':\n // Only extract color functions\n if (isCssColorFunction(node.name)) {\n colorValue = generate(node);\n }\n break;\n }\n \n return colorValue && isValidColor(colorValue) ? colorValue : null;\n};\n\nexport { findClosestColorHook, convertToHex, isValidColor, extractColorValue };\n", "//stylelint-sds/packages/stylelint-plugin-slds/src/utils/css-functions.ts\n/**\n * Complete list of CSS functions that should be preserved/recognized\n */\nconst CSS_FUNCTIONS = [\n 'attr',\n 'calc',\n 'color-mix',\n 'conic-gradient',\n 'counter',\n 'cubic-bezier',\n 'linear-gradient',\n 'max',\n 'min',\n 'radial-gradient',\n 'repeating-conic-gradient',\n 'repeating-linear-gradient',\n 'repeating-radial-gradient',\n 'var'\n ];\n \n \n const CSS_MATH_FUNCTIONS = ['calc', 'min', 'max'];\n \n \n const RGB_COLOR_FUNCTIONS = ['rgb', 'rgba', 'hsl', 'hsla'];\n \n /**\n * Regex for matching any CSS function (for general detection)\n * Matches function names within other text\n */\n const cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join('|')})`);\n \n \n const cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join('|')})$`);\n \n \n const cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join('|')})$`);\n \n export function containsCssFunction(value: string): boolean {\n return cssFunctionsRegex.test(value);\n }\n \n /**\n * Check if a value is exactly a CSS function name\n */\n export function isCssFunction(value: string): boolean {\n return cssFunctionsExactRegex.test(value);\n }\n \n export function isCssMathFunction(value: string): boolean {\n return cssMathFunctionsRegex.test(value);\n }\n \n export function isCssColorFunction(value: string): boolean {\n return RGB_COLOR_FUNCTIONS.includes(value);\n }", "///stylelint-sds/packages/stylelint-plugin-slds/src/utils/property-matcher.ts\n/**\n * Check if any of the hook properties match the provided cssProperty using wildcard matching.\n * @param hookProperties - Array of property patterns (can contain wildcards like `*`)\n * @param cssProperty - The CSS property to be checked\n * @returns true if a match is found, otherwise false\n */\nexport function matchesCssProperty(\n hookProperties: string[],\n cssProperty: string\n): boolean {\n return hookProperties.some((propertyPattern: string) => {\n const regexPattern = new RegExp(\n '^' + propertyPattern.replace(/\\*/g, '.*') + '$'\n );\n return regexPattern.test(cssProperty);\n });\n}\n\n// Directions & Corners\nconst DIRECTION_VALUES = '(?:top|right|bottom|left|inline|block|inline-start|inline-end|start|end|block-start|block-end)';\nconst CORNER_VALUES = '(?:top-left|top-right|bottom-right|bottom-left|start-start|start-end|end-start|end-end)';\nconst INSET_VALUES = '(?:inline|block|inline-start|inline-end|block-start|block-end)';\n\n\n// Pre-compiled regex patterns for better performance\nconst BORDER_COLOR_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-color$`);\nconst BORDER_WIDTH_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-width$`);\nconst MARGIN_REGEX = new RegExp(`^margin(?:-${DIRECTION_VALUES})?$`);\nconst PADDING_REGEX = new RegExp(`^padding(?:-${DIRECTION_VALUES})?$`);\nconst BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);\nconst INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);\n\nexport function isBorderColorProperty(cssProperty: string): boolean {\n return BORDER_COLOR_REGEX.test(cssProperty);\n}\n\nexport function isBorderWidthProperty(cssProperty: string): boolean {\n return BORDER_WIDTH_REGEX.test(cssProperty);\n}\n\nexport function isMarginProperty(cssProperty: string): boolean {\n return MARGIN_REGEX.test(cssProperty);\n}\n\nexport function isPaddingProperty(cssProperty: string): boolean {\n return PADDING_REGEX.test(cssProperty);\n}\n\nexport function isBorderRadius(cssProperty: string): boolean {\n return BORDER_RADIUS_REGEX.test(cssProperty);\n}\n\nexport function isDimensionProperty(cssProperty: string): boolean {\n return ['width', 'height', 'min-width', 'max-width', 'min-height', 'max-height'].includes(cssProperty);\n}\n\nexport function isInsetProperty(cssProperty: string): boolean {\n return INSET_REGEX.test(cssProperty);\n}\n\nexport const fontProperties = [\n 'font',\n 'font-size', \n 'font-weight'\n];\n\nexport const colorProperties = [\n 'color',\n 'fill',\n 'background',\n 'background-color',\n 'stroke',\n 'border',\n 'border*',\n 'border*-color',\n 'outline',\n 'outline-color',\n];\n\nexport const densificationProperties = [\n 'border*',\n 'margin*',\n 'padding*',\n 'width',\n 'height',\n 'min-width',\n 'max-width',\n 'min-height',\n 'max-height',\n 'inset',\n 'top',\n 'right',\n 'left',\n 'bottom',\n 'outline',\n 'outline-width',\n 'line-height'\n]; \n\n/**\n * Convert property patterns to CSS AST selector patterns\n * Handles wildcards (*) and creates proper ESLint CSS selector syntax\n */\nexport function toSelector(properties: string[]): string {\n const selectorParts = properties.map(prop => {\n if (prop.includes('*')) {\n // Convert wildcards to regex patterns for CSS AST selectors\n // Anchor to start of string to prevent matching CSS custom properties\n const regexPattern = prop.replace(/\\*/g, '.*');\n return `Declaration[property=/^${regexPattern}$/]`;\n } else {\n // Exact property match\n return `Declaration[property='${prop}']`;\n }\n });\n \n return selectorParts.join(', ');\n}\n\nexport function resolveDensityPropertyToMatch(cssProperty:string){\n const propertyToMatch = cssProperty.toLowerCase();\n if(isOutlineWidthProperty(propertyToMatch) || isBorderWidthProperty(propertyToMatch)){\n return 'border-width';\n } else if(isMarginProperty(propertyToMatch)){\n return 'margin';\n } else if(isPaddingProperty(propertyToMatch)){\n return 'padding';\n } else if(isBorderRadius(propertyToMatch)){\n return 'border-radius';\n } else if(isDimensionProperty(propertyToMatch)){\n // Stylinghooks includes only width as property to match, for all other dimensions we need to match width\n return 'width';\n } else if(isInsetProperty(propertyToMatch)){\n // Stylinghooks includes only top/left/right/bottom as property to match, for all other insets we need to match top\n return 'top';\n }\n return propertyToMatch;\n}\n\nexport function resolveColorPropertyToMatch(cssProperty:string){\n const propertyToMatch = cssProperty.toLowerCase();\n if(propertyToMatch === 'outline' || propertyToMatch === 'outline-color'){\n return 'border-color';\n } else if(propertyToMatch === 'background' || propertyToMatch === 'background-color'){\n return 'background-color';\n } else if(isBorderColorProperty(propertyToMatch)){\n return 'border-color';\n }\n return propertyToMatch;\n}\n\nexport function isOutlineWidthProperty(propertyToMatch:string){\n return propertyToMatch === 'outline' || propertyToMatch === 'outline-width';\n}", "import { parse, walk } from '@eslint/css-tree';\nimport type { HandlerContext } from '../types';\nimport type { ParsedUnitValue } from './value-utils';\nimport { ALLOWED_UNITS } from './value-utils';\nimport { extractColorValue } from './color-lib-utils';\nimport { isCssFunction } from './css-functions';\n\n/**\n * Common replacement data structure used by both color and density handlers\n */\nexport interface ReplacementInfo {\n start: number;\n end: number;\n replacement: string; // Full CSS var: var(--hook, fallback)\n displayValue: string; // Just the hook: --hook\n hasHook: boolean;\n isNumeric?: boolean; // Whether this is a numeric (dimension) value\n}\n\n/**\n * Position information from CSS tree parsing\n */\nexport interface PositionInfo {\n start?: { offset: number; line: number; column: number };\n end?: { offset: number; line: number; column: number };\n}\n\n/**\n * Generic callback for processing values with position information\n */\nexport type ValueCallback<T> = (value: T, positionInfo?: PositionInfo) => void;\n\n/**\n * Known valid font-weight values\n */\nconst FONT_WEIGHTS = [\n 'normal',\n 'bold', \n 'bolder',\n 'lighter',\n '100',\n '200', \n '300',\n '400',\n '500',\n '600',\n '700',\n '800',\n '900'\n];\n\n/**\n * Check if a value is a known font-weight\n */\nexport function isKnownFontWeight(value: string | number): boolean {\n const stringValue = value.toString();\n return FONT_WEIGHTS.includes(stringValue.toLowerCase());\n}\n\n/**\n * Generic shorthand auto-fix handler\n * Handles the common logic for reconstructing shorthand values with replacements\n */\nexport function handleShorthandAutoFix(\n declarationNode: any,\n context: HandlerContext,\n valueText: string,\n replacements: ReplacementInfo[]\n) {\n if(!replacements || replacements.length === 0){\n return;\n }\n // Sort replacements by position for proper reconstruction\n const sortedReplacements = replacements.sort((a,b)=> b.start-a.start);\n\n // Get rule options\n const reportNumericValue = context.options?.reportNumericValue || 'always';\n\n const fixCallback = (start:number, originalValue:string, replacement:string) => {\n // Reconstruct the entire value with all replacements\n let newValue = valueText;\n\n newValue = newValue.substring(0, start) + replacement + newValue.substring(start+originalValue.length);\n\n if(newValue !== valueText){\n return (fixer:any)=>{\n return fixer.replaceText(declarationNode.value, newValue);\n }\n }\n }\n\n // Report each individual value\n sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook, isNumeric }) => {\n const originalValue = valueText.substring(start, end);\n \n // Check if we should skip reporting based on reportNumericValue option\n if (isNumeric) {\n if (reportNumericValue === 'never') {\n return; // Skip reporting numeric values\n }\n if (reportNumericValue === 'hasReplacement' && !hasHook) {\n return; // Skip reporting numeric values without replacements\n }\n }\n \n \n const valueColumnStart = declarationNode.value.loc.start.column + start;\n const valueColumnEnd = valueColumnStart + originalValue.length;\n const canAutoFix = originalValue !== replacement;\n \n // Create precise error location for this value\n const { loc: { start: locStart, end: locEnd } } = declarationNode.value;\n const reportNode = {\n ...declarationNode.value,\n loc: {\n ...declarationNode.value.loc,\n start: {\n ...locStart,\n column: valueColumnStart\n },\n end: {\n ...locEnd,\n column: valueColumnEnd\n }\n }\n };\n\n if (hasHook) {\n // Create auto-fix for the entire shorthand value\n const fix = canAutoFix ? fixCallback(start, originalValue, replacement) : undefined;\n\n context.context.report({\n node: reportNode,\n messageId: 'hardcodedValue',\n data: {\n oldValue: originalValue,\n newValue: displayValue\n },\n fix\n });\n } else {\n // No hook available\n context.context.report({\n node: reportNode,\n messageId: 'noReplacement',\n data: {\n oldValue: originalValue\n }\n });\n }\n });\n}\n\n/**\n * Generic CSS tree traversal with position tracking\n * Always provides position information since both handlers need it\n */\nexport function forEachValue<T>(\n valueText: string,\n extractValue: (node: any) => T | null,\n shouldSkipNode: (node: any) => boolean,\n callback: (value: T, positionInfo: PositionInfo) => void\n): void {\n if (!valueText || typeof valueText !== 'string') {\n return;\n }\n\n try {\n const ast = parse(valueText, { context: 'value' as const, positions: true });\n \n walk(ast, {\n enter(node: any) {\n // Skip nodes efficiently using this.skip\n if (shouldSkipNode(node)) {\n return this.skip;\n }\n \n const value = extractValue(node);\n if (value !== null) {\n const positionInfo: PositionInfo = {\n start: node.loc?.start,\n end: node.loc?.end\n };\n callback(value, positionInfo);\n }\n }\n });\n } catch (error) {\n // Silently handle parse errors\n return;\n }\n}\n\n/**\n * Check if color node should be skipped during traversal\n */\nfunction shouldSkipColorNode(node: any): boolean {\n return node.type === 'Function' && isCssFunction(node.name);\n}\n\n/**\n * Check if dimension node should be skipped during traversal\n * Skip all function nodes by default\n */\nfunction shouldSkipDimensionNode(node: any): boolean {\n return node.type === 'Function';\n}\n\n/**\n * Extract dimension value from CSS AST node\n * Returns structured data with number and unit to eliminate regex parsing\n */\nfunction extractDimensionValue(valueNode: any, cssProperty?: string): ParsedUnitValue | null {\n if (!valueNode) return null;\n \n switch (valueNode.type) {\n case 'Dimension':\n // Dimensions: 16px, 1rem -> extract value and unit directly from AST\n const numValue = Number(valueNode.value);\n if (numValue === 0) return null; // Skip zero values\n \n const unit = valueNode.unit.toLowerCase();\n if (!ALLOWED_UNITS.includes(unit)) return null; // Support only allowed units\n \n return {\n number: numValue,\n unit: unit as 'px' | 'rem' | '%' | 'em' | 'ch'\n };\n \n case 'Number':\n // Numbers: 400, 1.5 -> treat as unitless (font-weight, line-height, etc.)\n const numberValue = Number(valueNode.value);\n if (numberValue === 0) return null; // Skip zero values\n \n return {\n number: numberValue,\n unit: null\n };\n \n case 'Percentage':\n // Percentage values: 100%, 50% -> extract value and add % unit\n const percentValue = Number(valueNode.value);\n if (percentValue === 0) return null; // Skip zero values\n \n return {\n number: percentValue,\n unit: '%'\n };\n \n case 'Value':\n // Value wrapper - extract from first child\n return valueNode.children?.[0] ? extractDimensionValue(valueNode.children[0], cssProperty) : null;\n }\n \n return null;\n}\n\n/**\n * Specialized color value traversal\n * Handles color-specific extraction and skipping logic\n */\nexport function forEachColorValue(\n valueText: string,\n callback: (colorValue: string, positionInfo: PositionInfo) => void\n): void {\n forEachValue(valueText, extractColorValue, shouldSkipColorNode, callback);\n}\n\n/**\n * Specialized density value traversal\n * Handles dimension-specific extraction and skipping logic\n */\nexport function forEachDensityValue(\n valueText: string,\n cssProperty: string,\n callback: (parsedDimension: ParsedUnitValue, positionInfo: PositionInfo) => void\n): void {\n forEachValue(\n valueText, \n (node) => extractDimensionValue(node, cssProperty), \n shouldSkipDimensionNode, \n callback\n );\n}\n\n/**\n * Extract font-related values from CSS AST node\n * Handles font-size and font-weight values\n */\nfunction extractFontValue(node: any): ParsedUnitValue | null {\n if (!node) return null;\n \n switch (node.type) {\n case 'Dimension':\n // Font-size: 16px, 1rem, etc.\n const numValue = Number(node.value);\n if (numValue <= 0) return null; // Skip zero/negative values\n \n const unit = node.unit.toLowerCase();\n if (!ALLOWED_UNITS.includes(unit)) return null;\n \n return {\n number: numValue,\n unit: unit as 'px' | 'rem' | '%' | 'em' | 'ch'\n };\n \n case 'Number':\n // Font-weight: 400, 700, etc.\n const numberValue = Number(node.value);\n if (numberValue <= 0) {\n return null; // Skip zero/negative values\n }\n \n // Only accept known font-weight values for unitless numbers\n if (!isKnownFontWeight(numberValue)) {\n return null; // Skip values that aren't valid font-weights\n }\n \n return {\n number: numberValue,\n unit: null\n };\n \n case 'Identifier':\n // Font-weight keywords: normal, bold, etc.\n const namedValue = node.name.toLowerCase();\n \n // Only accept known font-weight keywords\n if (!isKnownFontWeight(namedValue)) {\n return null;\n }\n \n // Convert known keywords to numeric values\n if (namedValue === 'normal') {\n return { number: 400, unit: null };\n }\n \n // For other keywords (bolder, lighter), we can't determine exact numeric value\n // but we know they're valid font-weight values\n return { number: namedValue, unit: null };\n \n case 'Percentage':\n // Percentage values for font-size\n const percentValue = Number(node.value);\n if (percentValue === 0) return null; // Skip zero values\n \n return {\n number: percentValue,\n unit: '%'\n };\n \n case 'Value':\n // Value wrapper - extract from first child\n return node.children?.[0] ? extractFontValue(node.children[0]) : null;\n }\n \n return null;\n}\n\n/**\n * Check if font node should be skipped during traversal\n * Skip all function nodes by default\n */\nfunction shouldSkipFontNode(node: any): boolean {\n return node.type === 'Function';\n}\n\n/**\n * Specialized font value traversal\n * Handles font-specific extraction and skipping logic\n */\nexport function forEachFontValue(\n valueText: string,\n callback: (fontValue: ParsedUnitValue, positionInfo: PositionInfo) => void\n): void {\n forEachValue(valueText, extractFontValue, shouldSkipFontNode, callback);\n}\n", "import { \n forEachValue, \n type PositionInfo \n} from './hardcoded-shared-utils';\n\n/**\n * Check if a CSS property should be targeted for linting based on prefixes or explicit targets\n * @param property - The CSS property name to check\n * @param propertyTargets - Array of specific properties to target (empty means target all)\n * @returns true if the property should be targeted\n */\nexport function isTargetProperty(property: string, propertyTargets: string[] = []): boolean {\n if (typeof property !== 'string') return false;\n return property.startsWith('--sds-')\n || property.startsWith('--slds-')\n || property.startsWith('--lwc-')\n || propertyTargets.length === 0\n || propertyTargets.includes(property);\n}\n\n/**\n * CSS Variable information for SLDS variable detection\n */\nexport interface CssVariableInfo {\n name: string; // Variable name: --slds-g-color-surface-1\n hasFallback: boolean; // Whether var() already has a fallback\n}\n\n/**\n * Generic CSS variable extractor that can be customized for different use cases\n * @param node - AST node to extract from\n * @param filter - Function to validate and extract variable information\n * @returns Extracted variable info or null\n */\nfunction extractCssVariable<T>(\n node: any,\n filter: (variableName: string, childrenArray: any[]) => T | null\n): T | null {\n if (!node || node.type !== 'Function' || node.name !== 'var') {\n return null;\n }\n\n if (!node.children) {\n return null;\n }\n\n // Convert children to array and get the first child (variable name)\n const childrenArray = Array.from(node.children);\n if (childrenArray.length === 0) {\n return null;\n }\n \n const firstChild = childrenArray[0] as any;\n if (!firstChild || firstChild.type !== 'Identifier') {\n return null;\n }\n\n const variableName = firstChild.name;\n if (!variableName) {\n return null;\n }\n\n return filter(variableName, childrenArray);\n}\n\n/**\n * Specialized CSS variable traversal for SLDS variables\n * Finds var(--slds-*) functions and reports their fallback status\n */\nexport function forEachSldsVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--slds-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for SLDS/SDS namespace detection\n * Finds var(--slds-*) or var(--sds-*) functions in CSS values\n * Note: hasFallback is set to false as it's unused for namespace validation\n */\nexport function forEachNamespacedVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName) => {\n // Check for SLDS or SDS namespace\n if (variableName.startsWith('--slds-') || variableName.startsWith('--sds-')) {\n return { name: variableName, hasFallback: false }; // hasFallback unused, but required by interface\n }\n return null;\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Specialized CSS variable traversal for LWC variables\n * Finds var(--lwc-*) functions in CSS values and reports their fallback status\n */\nexport function forEachLwcVariable(\n valueText: string,\n callback: (variableInfo: CssVariableInfo, positionInfo: PositionInfo) => void\n): void {\n const extractor = (node: any) => extractCssVariable(node, (variableName, childrenArray) => {\n if (!variableName.startsWith('--lwc-')) {\n return null;\n }\n\n // Check if there's a fallback (comma separator)\n const hasFallback = childrenArray.some((child: any) => \n child.type === 'Operator' && child.value === ','\n );\n\n return { name: variableName, hasFallback };\n });\n\n forEachValue(valueText, extractor, () => false, callback);\n}\n\n/**\n * Format multiple hook suggestions for better readability\n * @param hooks - Array of hook names to format\n * @returns Formatted string with hooks\n */\nexport function formatSuggestionHooks(hooks: string[]): string {\n if (hooks.length === 1) {\n return `${hooks[0]}`;\n }\n\n // Loop through hooks and append each as a numbered list item with line breaks\n return '\\n' + hooks.map((hook, index) => `${index + 1}. ${hook}`).join('\\n');\n}", "import type { CustomHookMapping } from '../types';\n\n/**\n * Check if a CSS property matches a pattern (supports wildcards)\n * @param cssProperty - The CSS property to check (e.g., \"background-color\")\n * @param pattern - The pattern to match against (e.g., \"background*\" or \"color\")\n * @returns true if the property matches the pattern\n */\nfunction matchesPropertyPattern(cssProperty: string, pattern: string): boolean {\n const normalizedProperty = cssProperty.toLowerCase();\n const normalizedPattern = pattern.toLowerCase();\n\n // Exact match\n if (normalizedProperty === normalizedPattern) {\n return true;\n }\n\n // Wildcard match (e.g., \"background*\" matches \"background-color\", \"background-image\")\n if (normalizedPattern.endsWith('*')) {\n const prefix = normalizedPattern.slice(0, -1);\n return normalizedProperty.startsWith(prefix);\n }\n\n return false;\n}\n\n/**\n * Get custom hook mapping for a given CSS property and value\n * @param cssProperty - The CSS property (e.g., \"background-color\", \"color\")\n * @param value - The hardcoded value (e.g., \"#fff\", \"16px\")\n * @param customMapping - The custom mapping configuration from rule options\n * @returns The hook name if a mapping is found, null otherwise\n */\nexport function getCustomMapping(\n cssProperty: string,\n value: string,\n customMapping?: CustomHookMapping\n): string | null {\n if (!customMapping) {\n return null;\n }\n\n const normalizedValue = value.toLowerCase().trim();\n\n // Iterate through all hook mappings\n for (const [hookName, config] of Object.entries(customMapping)) {\n // Check if any property pattern matches\n const propertyMatches = config.properties.some((pattern) =>\n matchesPropertyPattern(cssProperty, pattern)\n );\n\n if (!propertyMatches) {\n continue;\n }\n\n // Check if the value matches any configured value\n const valueMatches = config.values.some(\n (configValue) => configValue.toLowerCase().trim() === normalizedValue\n );\n\n if (valueMatches) {\n return hookName;\n }\n }\n\n return null;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAAmB;AACnB,sBAAyB;;;ACEzB,IAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,qBAAqB,CAAC,QAAQ,OAAO,KAAK;AAGhD,IAAM,sBAAsB,CAAC,OAAO,QAAQ,OAAO,MAAM;AAMzD,IAAM,oBAAoB,IAAI,OAAO,MAAM,cAAc,KAAK,GAAG,CAAC,GAAG;AAGrE,IAAM,yBAAyB,IAAI,OAAO,OAAO,cAAc,KAAK,GAAG,CAAC,IAAI;AAG5E,IAAM,wBAAwB,IAAI,OAAO,OAAO,mBAAmB,KAAK,GAAG,CAAC,IAAI;AASzE,SAAS,cAAc,OAAwB;AACpD,SAAO,uBAAuB,KAAK,KAAK;AAC1C;AAMO,SAAS,mBAAmB,OAAwB;AACzD,SAAO,oBAAoB,SAAS,KAAK;AAC3C;;;AD/CF,IAAM,mBAAmB;AAMzB,IAAM,eAAe,CAAC,UAAiC;AACrD,MAAI;AAEF,eAAO,iB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F,OAAO;AAEL,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MACA,cAAc;AAAA,MACd,SAAS;AAAA,IACX;AAAA,EACF;AACF;",
6
- "names": ["chroma", "import_css_tree"]
3
+ "sources": ["../../../../../src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts"],
4
+ "sourcesContent": ["import { findClosestColorHook, convertToHex, isValidColor } from '../../../../utils/color-lib-utils';\nimport { resolveColorPropertyToMatch } from '../../../../utils/property-matcher';\nimport { formatSuggestionHooks } from '../../../../utils/css-utils';\nimport { getCustomMapping } from '../../../../utils/custom-mapping-utils';\nimport type { HandlerContext, DeclarationHandler } from '../../../../types';\n\n// Import shared utilities for common logic\nimport { \n handleShorthandAutoFix, \n forEachColorValue,\n type ReplacementInfo,\n type PositionInfo\n} from '../../../../utils/hardcoded-shared-utils';\n\n\n/**\n * Handle color declarations using CSS tree parsing\n * Supports shorthand properties like background, border, etc. \n * Uses css-tree for reliable AST-based parsing + chroma-js validation\n */\nexport const handleColorDeclaration: DeclarationHandler = (node: any, context: HandlerContext) => {\n const cssProperty = node.property.toLowerCase();\n const valueText = context.sourceCode.getText(node.value);\n const replacements: ReplacementInfo[] = [];\n \n forEachColorValue(valueText, (colorValue, positionInfo) => {\n if (colorValue !== 'transparent' && isValidColor(colorValue)) {\n const replacement = createColorReplacement(colorValue, cssProperty, context, positionInfo, valueText);\n if (replacement) {\n replacements.push(replacement);\n }\n }\n });\n \n // Apply shorthand auto-fix once all values are processed\n handleShorthandAutoFix(node, context, valueText, replacements);\n};\n\n\n/**\n * Create color replacement info for shorthand auto-fix\n * Returns replacement data or null if no valid replacement\n */\nfunction createColorReplacement(\n colorValue: string,\n cssProperty: string,\n context: HandlerContext,\n positionInfo: PositionInfo,\n originalValueText?: string\n): ReplacementInfo | null {\n if (!positionInfo?.start) {\n return null;\n }\n\n const hexValue = convertToHex(colorValue);\n if (!hexValue) {\n return null;\n }\n\n // Use position information directly from CSS tree (already 0-based offsets)\n const start = positionInfo.start.offset;\n const end = positionInfo.end.offset;\n \n // Extract the original value from the CSS text to preserve spacing\n const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;\n\n // Check custom mapping first\n const customHook = getCustomMapping(cssProperty, colorValue, context.options?.customMapping);\n let closestHooks: string[] = [];\n \n if (customHook) {\n // Use custom mapping if available\n closestHooks = [customHook];\n } else {\n // Otherwise, find closest hooks from metadata\n const propToMatch = resolveColorPropertyToMatch(cssProperty);\n closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);\n }\n\n let replacement = originalValue;\n let paletteHook = null;\n // Apply preferPaletteHook filter if enabled\n if (context.options?.preferPaletteHook && closestHooks.length > 1) {\n paletteHook = closestHooks.filter(hook => hook.includes('-palette-'))[0];\n }\n if(paletteHook){\n replacement = `var(${paletteHook}, ${colorValue})`;\n } else if(closestHooks.length === 1){\n replacement = `var(${closestHooks[0]}, ${colorValue})`;\n }\n\n if (closestHooks.length > 0) {\n // Multiple hooks - format them for better readability\n return {\n start,\n end,\n replacement, // Use original value to preserve spacing\n displayValue: formatSuggestionHooks(closestHooks),\n hasHook: true \n };\n } else {\n // No hooks - keep original value\n return {\n start,\n end,\n replacement, // Use original value to preserve spacing\n displayValue: originalValue,\n hasHook: false\n };\n }\n}\n\n\n\n\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAiE;AACjE,8BAA4C;AAC5C,uBAAsC;AACtC,kCAAiC;AAIjC,oCAKO;AAQA,IAAM,yBAA6C,CAAC,MAAW,YAA4B;AAChG,QAAM,cAAc,KAAK,SAAS,YAAY;AAC9C,QAAM,YAAY,QAAQ,WAAW,QAAQ,KAAK,KAAK;AACvD,QAAM,eAAkC,CAAC;AAEzC,uDAAkB,WAAW,CAAC,YAAY,iBAAiB;AACzD,QAAI,eAAe,qBAAiB,qCAAa,UAAU,GAAG;AAC5D,YAAM,cAAc,uBAAuB,YAAY,aAAa,SA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