@salesforce-ux/eslint-plugin-slds 0.5.3 → 1.0.0-internal-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/build/index.js +2309 -50
  2. package/build/index.js.map +4 -4
  3. package/build/rules/enforce-bem-usage.js +325 -85
  4. package/build/rules/enforce-bem-usage.js.map +4 -4
  5. package/build/rules/modal-close-button-issue.js +324 -179
  6. package/build/rules/modal-close-button-issue.js.map +4 -4
  7. package/build/rules/no-deprecated-classes-slds2.js +247 -53
  8. package/build/rules/no-deprecated-classes-slds2.js.map +4 -4
  9. package/build/rules/v9/enforce-bem-usage.js +236 -0
  10. package/build/rules/v9/enforce-bem-usage.js.map +7 -0
  11. package/build/rules/v9/enforce-component-hook-naming-convention.js +262 -0
  12. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +7 -0
  13. package/build/rules/v9/enforce-sds-to-slds-hooks.js +260 -0
  14. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +7 -0
  15. package/build/rules/v9/lwc-token-to-slds-hook.js +330 -0
  16. package/build/rules/v9/lwc-token-to-slds-hook.js.map +7 -0
  17. package/build/rules/v9/no-deprecated-slds-classes.js +227 -0
  18. package/build/rules/v9/no-deprecated-slds-classes.js.map +7 -0
  19. package/build/rules/v9/no-deprecated-tokens-slds1.js +270 -0
  20. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +7 -0
  21. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +339 -0
  22. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +7 -0
  23. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +348 -0
  24. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +7 -0
  25. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +344 -0
  26. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +7 -0
  27. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +388 -0
  28. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +7 -0
  29. package/build/rules/v9/no-hardcoded-values/handlers/index.js +834 -0
  30. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +7 -0
  31. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +1112 -0
  32. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +7 -0
  33. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +1112 -0
  34. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +7 -0
  35. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +945 -0
  36. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +7 -0
  37. package/build/rules/v9/no-slds-class-overrides.js +233 -0
  38. package/build/rules/v9/no-slds-class-overrides.js.map +7 -0
  39. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +250 -0
  40. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +7 -0
  41. package/build/rules/v9/no-slds-private-var.js +230 -0
  42. package/build/rules/v9/no-slds-private-var.js.map +7 -0
  43. package/build/rules/v9/no-slds-var-without-fallback.js +253 -0
  44. package/build/rules/v9/no-slds-var-without-fallback.js.map +7 -0
  45. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +253 -0
  46. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +7 -0
  47. package/build/rules/v9/no-unsupported-hooks-slds2.js +243 -0
  48. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +7 -0
  49. package/build/rules/v9/reduce-annotations.js +234 -0
  50. package/build/rules/v9/reduce-annotations.js.map +7 -0
  51. package/build/src/rules/enforce-bem-usage.d.ts +17 -0
  52. package/build/{rules → src/rules}/modal-close-button-issue.d.ts +2 -1
  53. package/build/{rules → src/rules}/no-deprecated-classes-slds2.d.ts +2 -1
  54. package/build/src/rules/v9/enforce-bem-usage.d.ts +3 -0
  55. package/build/src/rules/v9/enforce-component-hook-naming-convention.d.ts +3 -0
  56. package/build/src/rules/v9/enforce-sds-to-slds-hooks.d.ts +3 -0
  57. package/build/src/rules/v9/lwc-token-to-slds-hook.d.ts +3 -0
  58. package/build/src/rules/v9/no-deprecated-slds-classes.d.ts +3 -0
  59. package/build/src/rules/v9/no-deprecated-tokens-slds1.d.ts +3 -0
  60. package/build/src/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.d.ts +5 -0
  61. package/build/src/rules/v9/no-hardcoded-values/handlers/colorHandler.d.ts +7 -0
  62. package/build/src/rules/v9/no-hardcoded-values/handlers/densityHandler.d.ts +7 -0
  63. package/build/src/rules/v9/no-hardcoded-values/handlers/fontHandler.d.ts +6 -0
  64. package/build/src/rules/v9/no-hardcoded-values/handlers/index.d.ts +8 -0
  65. package/build/src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.d.ts +3 -0
  66. package/build/src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.d.ts +3 -0
  67. package/build/src/rules/v9/no-hardcoded-values/noHardcodedValueRule.d.ts +9 -0
  68. package/build/src/rules/v9/no-slds-class-overrides.d.ts +8 -0
  69. package/build/src/rules/v9/no-slds-namespace-for-custom-hooks.d.ts +3 -0
  70. package/build/src/rules/v9/no-slds-private-var.d.ts +3 -0
  71. package/build/src/rules/v9/no-slds-var-without-fallback.d.ts +3 -0
  72. package/build/src/rules/v9/no-sldshook-fallback-for-lwctoken.d.ts +3 -0
  73. package/build/src/rules/v9/no-unsupported-hooks-slds2.d.ts +3 -0
  74. package/build/src/rules/v9/reduce-annotations.d.ts +3 -0
  75. package/build/src/types/index.d.ts +26 -0
  76. package/build/src/utils/boxShadowValueParser.d.ts +17 -0
  77. package/build/src/utils/color-lib-utils.d.ts +18 -0
  78. package/build/src/utils/css-functions.d.ts +7 -0
  79. package/build/src/utils/css-utils.d.ts +7 -0
  80. package/build/src/utils/hardcoded-shared-utils.d.ts +60 -0
  81. package/build/src/utils/property-matcher.d.ts +23 -0
  82. package/build/src/utils/styling-hook-utils.d.ts +7 -0
  83. package/build/src/utils/value-utils.d.ts +40 -0
  84. package/build/types/index.js +18 -0
  85. package/build/types/index.js.map +7 -0
  86. package/build/types/yaml.d.js +1 -0
  87. package/build/types/yaml.d.js.map +7 -0
  88. package/build/utils/boxShadowValueParser.js +197 -0
  89. package/build/utils/boxShadowValueParser.js.map +7 -0
  90. package/build/utils/color-lib-utils.js +160 -0
  91. package/build/utils/color-lib-utils.js.map +7 -0
  92. package/build/utils/css-functions.js +68 -0
  93. package/build/utils/css-functions.js.map +7 -0
  94. package/build/utils/css-utils.js +33 -0
  95. package/build/utils/css-utils.js.map +7 -0
  96. package/build/utils/hardcoded-shared-utils.js +300 -0
  97. package/build/utils/hardcoded-shared-utils.js.map +7 -0
  98. package/build/utils/node.js +158 -0
  99. package/build/{rules/utils → utils}/node.js.map +2 -2
  100. package/build/utils/property-matcher.js +159 -0
  101. package/build/utils/property-matcher.js.map +7 -0
  102. package/build/utils/styling-hook-utils.js +80 -0
  103. package/build/utils/styling-hook-utils.js.map +7 -0
  104. package/build/utils/value-utils.js +65 -0
  105. package/build/utils/value-utils.js.map +7 -0
  106. package/package.json +9 -4
  107. package/src/config/rule-messages.yml +143 -0
  108. package/build/rules/enforce-bem-usage.d.ts +0 -28
  109. package/build/rules/utils/node.js +0 -197
  110. package/build/rules/utils/rule.d.ts +0 -7
  111. package/build/rules/utils/rule.js +0 -10
  112. package/build/rules/utils/rule.js.map +0 -7
  113. /package/build/{index.d.ts → src/index.d.ts} +0 -0
  114. /package/build/{rules → src}/utils/node.d.ts +0 -0
@@ -0,0 +1,1112 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml
33
+ var require_rule_messages = __commonJS({
34
+ "yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml"(exports2, module2) {
35
+ module2.exports = {
36
+ "no-slds-class-overrides": {
37
+ "description": "Create new custom CSS classes instead of overriding SLDS selectors",
38
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-class-overrides",
39
+ "type": "problem",
40
+ "messages": {
41
+ "sldsClassOverride": "Overriding .{{className}} isn't supported. To differentiate SLDS and custom classes, create a CSS class in your namespace. Examples: myapp-input, myapp-button."
42
+ }
43
+ },
44
+ "no-deprecated-slds-classes": {
45
+ "description": "Please replace the deprecated classes with a modern equivalent",
46
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-slds-classes",
47
+ "type": "problem",
48
+ "messages": {
49
+ "deprecatedClass": "The class {{className}} is deprecated and not available in SLDS2. Please update to a supported class."
50
+ }
51
+ },
52
+ "no-deprecated-tokens-slds1": {
53
+ "description": "Update outdated design tokens to SLDS 2 styling hooks with similar values. For more information, see Styling Hooks on lightningdesignsystem.com.",
54
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-tokens-slds1",
55
+ "type": "problem",
56
+ "messages": {
57
+ "deprecatedToken": "Consider removing {{oldValue}} or replacing it with {{newValue}}. Set the fallback to {{oldValue}}. For more info, see Styling Hooks on lightningdesignsystem.com.",
58
+ "noReplacement": "Update outdated design tokens to SLDS 2 styling hooks with similar values. For more information, see Styling Hooks on lightningdesignsystem.com."
59
+ }
60
+ },
61
+ "enforce-sds-to-slds-hooks": {
62
+ "description": "Convert your existing --sds styling hooks to --slds styling hooks. See lightningdesignsystem.com for more info.",
63
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-sds-to-slds-hooks",
64
+ "type": "problem",
65
+ "messages": {
66
+ "replaceSdsWithSlds": "Replace {{oldValue}} with {{suggestedMatch}} styling hook."
67
+ }
68
+ },
69
+ "enforce-bem-usage": {
70
+ "description": "Replace BEM double-dash syntax in class names with single underscore syntax",
71
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-bem-usage",
72
+ "type": "problem",
73
+ "messages": {
74
+ "bemDoubleDash": "{{actual}} has been retired. Update it to the new name {{newValue}}.",
75
+ "fixBemNaming": "Update to correct BEM naming convention"
76
+ }
77
+ },
78
+ "modal-close-button-issue": {
79
+ "description": "Update component attributes or CSS classes for the modal close button to comply with the modal component blueprint",
80
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#modal-close-button-issue",
81
+ "type": "problem",
82
+ "messages": {
83
+ "modalCloseButtonIssue": "Update component attributes or CSS classes for the modal close button to comply with the modal component blueprint.",
84
+ "removeClass": "Remove the slds-button_icon-inverse class from the modal close button in components that use the SLDS modal blueprint.",
85
+ "changeVariant": "Change the variant attribute value from bare-inverse to bare in <lightning-button-icon> or <lightning-icon>.",
86
+ "removeVariant": "Remove the variant attribute from the <lightning-icon> component inside the <button> element.",
87
+ "ensureButtonClasses": "Add or move slds-button and slds-button_icon to the class attribute of the <button> element or <lightning-button-icon> component.",
88
+ "ensureSizeAttribute": "To size icons properly, set the size attribute \u200Cto large in the <lightning-icon> and <lightning-button-icon> components."
89
+ }
90
+ },
91
+ "no-deprecated-classes-slds2": {
92
+ "description": "Replace classes that aren't available with SLDS 2 classes",
93
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-classes-slds2",
94
+ "type": "problem",
95
+ "messages": {
96
+ "deprecatedClass": "The class {{className}} isn't available in SLDS 2. Update it to a class supported in SLDS 2. See lightningdesignsystem.com for more information.",
97
+ "updateToModernClass": "Replace deprecated class with modern equivalent",
98
+ "checkDocumentation": "See lightningdesignsystem.com for SLDS 2 class alternatives"
99
+ }
100
+ },
101
+ "lwc-token-to-slds-hook": {
102
+ "description": "Replace the deprecated --lwc tokens with the latest --slds tokens. See lightningdesignsystem.com for more info.",
103
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#lwc-token-to-slds-hook",
104
+ "type": "problem",
105
+ "messages": {
106
+ "errorWithReplacement": "The '{{oldValue}}' design token is deprecated. Replace it with '{{newValue}}'. For more info, see Global Styling Hooks on lightningdesignsystem.com.",
107
+ "errorWithStyleHooks": "The '{{oldValue}}' design token is deprecated. Replace it with the SLDS 2 '{{newValue}}' styling hook and set the fallback to '{{oldValue}}'. For more info, see Global Styling Hooks on lightningdesignsystem.com.",
108
+ "errorWithNoRecommendation": "The '{{oldValue}}' design token is deprecated. For more info, see the New Global Styling Hook Guidance on lightningdesignsystem.com."
109
+ }
110
+ },
111
+ "no-sldshook-fallback-for-lwctoken": {
112
+ "description": "Avoid using --slds styling hooks as fallback values for --lwc tokens.",
113
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-sldshook-fallback-for-lwctoken",
114
+ "type": "problem",
115
+ "messages": {
116
+ "unsupportedFallback": "Remove the {{sldsToken}} styling hook that is used as a fallback value for {{lwcToken}}."
117
+ }
118
+ },
119
+ "no-unsupported-hooks-slds2": {
120
+ "description": "Identifies styling hooks that aren't present in SLDS 2. They must be replaced with styling hooks that have a similar effect, or they must be removed.",
121
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-unsupported-hooks-slds2",
122
+ "type": "problem",
123
+ "messages": {
124
+ "deprecated": "The {{token}} styling hook isn't present in SLDS 2 and there's no equivalent replacement. Remove it or replace it with a styling hook with a similar effect."
125
+ }
126
+ },
127
+ "no-slds-var-without-fallback": {
128
+ "description": "Add fallback values to SLDS styling hooks. The fallback values are used in Salesforce environments where styling hooks are unavailable.",
129
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-var-without-fallback",
130
+ "type": "problem",
131
+ "messages": {
132
+ "varWithoutFallback": "Your code uses the {{cssVar}} styling hook without a fallback value. Styling hooks are unavailable in some Salesforce environments. To render your component correctly in all environments, add this fallback value: var({{cssVar}}, {{recommendation}}). To make this fallback value brand-aware, use a branded design token instead of a static value. See Design Tokens on v1.lightningdesignsystem.com."
133
+ }
134
+ },
135
+ "no-slds-namespace-for-custom-hooks": {
136
+ "description": "To differentiate custom styling hooks from SLDS styling hooks, create custom styling hooks in your namespace.",
137
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-namespace-for-custom-hooks",
138
+ "type": "problem",
139
+ "messages": {
140
+ "customHookNamespace": "Using the --slds namespace for {{token}} isn't supported. Create the custom styling hook in your namespace. Example: --myapp-{{tokenWithoutNamespace}}"
141
+ }
142
+ },
143
+ "no-slds-private-var": {
144
+ "description": "Some SLDS styling hooks are private and reserved only for internal Salesforce use. Private SLDS styling hooks have prefixes --_slds- and --slds-s-. For more information, look up private CSS in lightningdesignsystem.com.",
145
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-private-var",
146
+ "type": "problem",
147
+ "messages": {
148
+ "privateVar": "This styling hook is reserved for internal Salesforce use. Remove the --_slds- or \u2013slds-s private variable within selector {{prop}}. For more information, look up private CSS in lightningdesignsystem.com."
149
+ }
150
+ },
151
+ "enforce-component-hook-naming-convention": {
152
+ "description": "Replace component styling hooks that use a deprecated naming convention.",
153
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-component-hook-naming-convention",
154
+ "type": "problem",
155
+ "messages": {
156
+ "replace": "Replace the deprecated {{oldValue}} component styling hook with {{suggestedMatch}}."
157
+ }
158
+ },
159
+ "no-hardcoded-values-slds1": {
160
+ "description": "Replace static values with SLDS 1 design tokens. For more information, look up design tokens on lightningdesignsystem.com.",
161
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
162
+ "type": "suggestion",
163
+ "messages": {
164
+ "hardcodedValue": "Replace the {{oldValue}} static value with an SLDS 1 styling hook: {{newValue}}.",
165
+ "noReplacement": "There's no replacement styling hook for the {{oldValue}} static value. Remove the static value."
166
+ }
167
+ },
168
+ "no-hardcoded-values-slds2": {
169
+ "description": "Replace static values with SLDS 2 styling hooks. For more information, look up design tokens on lightningdesignsystem.com.",
170
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
171
+ "type": "suggestion",
172
+ "messages": {
173
+ "hardcodedValue": "Consider replacing the {{oldValue}} static value with an SLDS 2 styling hook that has a similar value: {{newValue}}.",
174
+ "noReplacement": "There's no replacement styling hook for the {{oldValue}} static value. Remove the static value."
175
+ }
176
+ },
177
+ "reduce-annotations": {
178
+ "description": "Remove your annotations and update your code.",
179
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#reduce-annotations",
180
+ "type": "problem",
181
+ "messages": {
182
+ "removeAnnotation": "Remove this annotation and update the code to SLDS best practices. For help, file an issue at https://github.com/salesforce-ux/slds-linter/"
183
+ }
184
+ }
185
+ };
186
+ }
187
+ });
188
+
189
+ // src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.ts
190
+ var no_hardcoded_values_slds2_exports = {};
191
+ __export(no_hardcoded_values_slds2_exports, {
192
+ default: () => no_hardcoded_values_slds2_default
193
+ });
194
+ module.exports = __toCommonJS(no_hardcoded_values_slds2_exports);
195
+ var import_next = __toESM(require("@salesforce-ux/sds-metadata/next"));
196
+ var import_rule_messages = __toESM(require_rule_messages());
197
+
198
+ // src/utils/color-lib-utils.ts
199
+ var import_chroma_js = __toESM(require("chroma-js"));
200
+ var import_css_tree = require("@eslint/css-tree");
201
+
202
+ // src/utils/css-functions.ts
203
+ var CSS_FUNCTIONS = [
204
+ "attr",
205
+ "calc",
206
+ "color-mix",
207
+ "conic-gradient",
208
+ "counter",
209
+ "cubic-bezier",
210
+ "linear-gradient",
211
+ "max",
212
+ "min",
213
+ "radial-gradient",
214
+ "repeating-conic-gradient",
215
+ "repeating-linear-gradient",
216
+ "repeating-radial-gradient",
217
+ "var"
218
+ ];
219
+ var CSS_MATH_FUNCTIONS = ["calc", "min", "max"];
220
+ var RGB_COLOR_FUNCTIONS = ["rgb", "rgba", "hsl", "hsla"];
221
+ var cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join("|")})`);
222
+ var cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join("|")})$`);
223
+ var cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join("|")})$`);
224
+ function isCssFunction(value) {
225
+ return cssFunctionsExactRegex.test(value);
226
+ }
227
+ function isCssColorFunction(value) {
228
+ return RGB_COLOR_FUNCTIONS.includes(value);
229
+ }
230
+
231
+ // src/utils/color-lib-utils.ts
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
+ };
237
+ var convertToHex = (color) => {
238
+ try {
239
+ return (0, import_chroma_js.default)(color).hex();
240
+ } catch (e) {
241
+ return null;
242
+ }
243
+ };
244
+ var findClosestColorHook = (color, supportedColors, cssProperty) => {
245
+ const returnStylingHooks = [];
246
+ const closestHooksWithSameProperty = [];
247
+ const closestHooksWithoutSameProperty = [];
248
+ const closestHooksWithAllProperty = [];
249
+ const labColor = (0, import_chroma_js.default)(color).lab();
250
+ Object.entries(supportedColors).forEach(([sldsValue, data]) => {
251
+ if (sldsValue && isHexCode(sldsValue)) {
252
+ const hooks = data;
253
+ hooks.forEach((hook) => {
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
+ }
268
+ }
269
+ });
270
+ }
271
+ });
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));
287
+ }
288
+ }
289
+ return Array.from(new Set(returnStylingHooks));
290
+ };
291
+ var isValidColor = (val) => import_chroma_js.default.valid(val);
292
+ var extractColorValue = (node) => {
293
+ let colorValue = null;
294
+ switch (node.type) {
295
+ case "Hash":
296
+ colorValue = `#${node.value}`;
297
+ break;
298
+ case "Identifier":
299
+ colorValue = node.name;
300
+ break;
301
+ case "Function":
302
+ if (isCssColorFunction(node.name)) {
303
+ colorValue = (0, import_css_tree.generate)(node);
304
+ }
305
+ break;
306
+ }
307
+ return colorValue && isValidColor(colorValue) ? colorValue : null;
308
+ };
309
+
310
+ // src/utils/property-matcher.ts
311
+ var DIRECTION_VALUES = "(?:top|right|bottom|left|inline|block|inline-start|inline-end|start|end|block-start|block-end)";
312
+ var CORNER_VALUES = "(?:top-left|top-right|bottom-right|bottom-left|start-start|start-end|end-start|end-end)";
313
+ var INSET_VALUES = "(?:inline|block|inline-start|inline-end|block-start|block-end)";
314
+ var BORDER_COLOR_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-color$`);
315
+ var BORDER_WIDTH_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-width$`);
316
+ var MARGIN_REGEX = new RegExp(`^margin(?:-${DIRECTION_VALUES})?$`);
317
+ var PADDING_REGEX = new RegExp(`^padding(?:-${DIRECTION_VALUES})?$`);
318
+ var BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);
319
+ var INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);
320
+ function isBorderColorProperty(cssProperty) {
321
+ return BORDER_COLOR_REGEX.test(cssProperty);
322
+ }
323
+ function isBorderWidthProperty(cssProperty) {
324
+ return BORDER_WIDTH_REGEX.test(cssProperty);
325
+ }
326
+ function isMarginProperty(cssProperty) {
327
+ return MARGIN_REGEX.test(cssProperty);
328
+ }
329
+ function isPaddingProperty(cssProperty) {
330
+ return PADDING_REGEX.test(cssProperty);
331
+ }
332
+ function isBorderRadius(cssProperty) {
333
+ return BORDER_RADIUS_REGEX.test(cssProperty);
334
+ }
335
+ function isDimensionProperty(cssProperty) {
336
+ return ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProperty);
337
+ }
338
+ function isInsetProperty(cssProperty) {
339
+ return INSET_REGEX.test(cssProperty);
340
+ }
341
+ var fontProperties = [
342
+ "font",
343
+ "font-size",
344
+ "font-weight"
345
+ ];
346
+ var colorProperties = [
347
+ "color",
348
+ "fill",
349
+ "background",
350
+ "background-color",
351
+ "stroke",
352
+ "border",
353
+ "border*",
354
+ "border*-color",
355
+ "outline",
356
+ "outline-color"
357
+ ];
358
+ var densificationProperties = [
359
+ "border*",
360
+ "margin*",
361
+ "padding*",
362
+ "width",
363
+ "height",
364
+ "min-width",
365
+ "max-width",
366
+ "min-height",
367
+ "max-height",
368
+ "inset",
369
+ "top",
370
+ "right",
371
+ "left",
372
+ "bottom",
373
+ "outline",
374
+ "outline-width",
375
+ "line-height"
376
+ ];
377
+ function toSelector(properties) {
378
+ const selectorParts = properties.map((prop) => {
379
+ if (prop.includes("*")) {
380
+ const regexPattern = prop.replace(/\*/g, ".*");
381
+ return `Declaration[property=/${regexPattern}$/]`;
382
+ } else {
383
+ return `Declaration[property='${prop}']`;
384
+ }
385
+ });
386
+ return selectorParts.join(", ");
387
+ }
388
+ function resolvePropertyToMatch(cssProperty) {
389
+ const propertyToMatch = cssProperty.toLowerCase();
390
+ if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
391
+ return "border-width";
392
+ } else if (isMarginProperty(propertyToMatch)) {
393
+ return "margin";
394
+ } else if (isPaddingProperty(propertyToMatch)) {
395
+ return "padding";
396
+ } else if (isBorderRadius(propertyToMatch)) {
397
+ return "border-radius";
398
+ } else if (isDimensionProperty(propertyToMatch)) {
399
+ return "width";
400
+ } else if (isInsetProperty(propertyToMatch)) {
401
+ return "top";
402
+ } else if (cssProperty === "background" || cssProperty === "background-color") {
403
+ return "background-color";
404
+ } else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
405
+ return "border-color";
406
+ }
407
+ return propertyToMatch;
408
+ }
409
+
410
+ // src/utils/hardcoded-shared-utils.ts
411
+ var import_css_tree2 = require("@eslint/css-tree");
412
+ var FONT_WEIGHTS = [
413
+ "normal",
414
+ "bold",
415
+ "bolder",
416
+ "lighter",
417
+ "100",
418
+ "200",
419
+ "300",
420
+ "400",
421
+ "500",
422
+ "600",
423
+ "700",
424
+ "800",
425
+ "900"
426
+ ];
427
+ function isKnownFontWeight(value) {
428
+ const stringValue = value.toString();
429
+ return FONT_WEIGHTS.includes(stringValue.toLowerCase());
430
+ }
431
+ function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
432
+ const sortedReplacements = replacements.sort((a, b) => a.start - b.start);
433
+ const hasAnyHooks = sortedReplacements.some((r) => r.hasHook);
434
+ const canAutoFix = hasAnyHooks;
435
+ sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook }) => {
436
+ const originalValue = valueText.substring(start, end);
437
+ const valueStartColumn = declarationNode.value.loc.start.column;
438
+ const valueColumn = valueStartColumn + start;
439
+ const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
440
+ const reportNode = {
441
+ ...declarationNode.value,
442
+ loc: {
443
+ ...declarationNode.value.loc,
444
+ start: {
445
+ ...locStart,
446
+ column: valueColumn
447
+ },
448
+ end: {
449
+ ...locEnd,
450
+ column: valueColumn + originalValue.length
451
+ }
452
+ }
453
+ };
454
+ if (hasHook) {
455
+ const fix = canAutoFix ? (fixer) => {
456
+ let newValue = valueText;
457
+ for (let i = sortedReplacements.length - 1; i >= 0; i--) {
458
+ const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];
459
+ newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);
460
+ }
461
+ return fixer.replaceText(declarationNode.value, newValue);
462
+ } : void 0;
463
+ context.context.report({
464
+ node: reportNode,
465
+ messageId: "hardcodedValue",
466
+ data: {
467
+ oldValue: originalValue,
468
+ newValue: displayValue
469
+ },
470
+ fix
471
+ });
472
+ } else {
473
+ context.context.report({
474
+ node: reportNode,
475
+ messageId: "noReplacement",
476
+ data: {
477
+ oldValue: originalValue
478
+ }
479
+ });
480
+ }
481
+ });
482
+ }
483
+ function forEachValue(valueText, extractValue, shouldSkipNode, callback) {
484
+ if (!valueText || typeof valueText !== "string") {
485
+ return;
486
+ }
487
+ try {
488
+ const ast = (0, import_css_tree2.parse)(valueText, { context: "value", positions: true });
489
+ (0, import_css_tree2.walk)(ast, {
490
+ enter(node) {
491
+ if (shouldSkipNode(node)) {
492
+ return this.skip;
493
+ }
494
+ const value = extractValue(node);
495
+ if (value !== null) {
496
+ const positionInfo = {
497
+ start: node.loc?.start,
498
+ end: node.loc?.end
499
+ };
500
+ callback(value, positionInfo);
501
+ }
502
+ }
503
+ });
504
+ } catch (error) {
505
+ return;
506
+ }
507
+ }
508
+ function shouldSkipColorNode(node) {
509
+ return node.type === "Function" && isCssFunction(node.name);
510
+ }
511
+ function shouldSkipDimensionNode(node) {
512
+ return node.type === "Function";
513
+ }
514
+ function extractDimensionValue(valueNode, cssProperty) {
515
+ if (!valueNode) return null;
516
+ switch (valueNode.type) {
517
+ case "Dimension":
518
+ const numValue = Number(valueNode.value);
519
+ if (numValue === 0) return null;
520
+ const unit = valueNode.unit.toLowerCase();
521
+ if (unit !== "px" && unit !== "rem" && unit !== "%") return null;
522
+ return {
523
+ number: numValue,
524
+ unit
525
+ };
526
+ case "Number":
527
+ const numberValue = Number(valueNode.value);
528
+ if (numberValue === 0) return null;
529
+ return {
530
+ number: numberValue,
531
+ unit: null
532
+ };
533
+ case "Percentage":
534
+ const percentValue = Number(valueNode.value);
535
+ if (percentValue === 0) return null;
536
+ return {
537
+ number: percentValue,
538
+ unit: "%"
539
+ };
540
+ case "Value":
541
+ return valueNode.children?.[0] ? extractDimensionValue(valueNode.children[0], cssProperty) : null;
542
+ }
543
+ return null;
544
+ }
545
+ function forEachColorValue(valueText, callback) {
546
+ forEachValue(valueText, extractColorValue, shouldSkipColorNode, callback);
547
+ }
548
+ function forEachDensityValue(valueText, cssProperty, callback) {
549
+ forEachValue(
550
+ valueText,
551
+ (node) => extractDimensionValue(node, cssProperty),
552
+ shouldSkipDimensionNode,
553
+ callback
554
+ );
555
+ }
556
+ function extractFontValue(node) {
557
+ if (!node) return null;
558
+ switch (node.type) {
559
+ case "Dimension":
560
+ const numValue = Number(node.value);
561
+ if (numValue <= 0) return null;
562
+ const unit = node.unit.toLowerCase();
563
+ if (unit !== "px" && unit !== "rem" && unit !== "%") return null;
564
+ return {
565
+ number: numValue,
566
+ unit
567
+ };
568
+ case "Number":
569
+ const numberValue = Number(node.value);
570
+ if (numberValue <= 0) {
571
+ return null;
572
+ }
573
+ if (!isKnownFontWeight(numberValue)) {
574
+ return null;
575
+ }
576
+ return {
577
+ number: numberValue,
578
+ unit: null
579
+ };
580
+ case "Identifier":
581
+ const namedValue = node.name.toLowerCase();
582
+ if (!isKnownFontWeight(namedValue)) {
583
+ return null;
584
+ }
585
+ if (namedValue === "normal") {
586
+ return { number: 400, unit: null };
587
+ }
588
+ return { number: namedValue, unit: null };
589
+ case "Percentage":
590
+ const percentValue = Number(node.value);
591
+ if (percentValue === 0) return null;
592
+ return {
593
+ number: percentValue,
594
+ unit: "%"
595
+ };
596
+ case "Value":
597
+ return node.children?.[0] ? extractFontValue(node.children[0]) : null;
598
+ }
599
+ return null;
600
+ }
601
+ function shouldSkipFontNode(node) {
602
+ return node.type === "Function";
603
+ }
604
+ function forEachFontValue(valueText, callback) {
605
+ forEachValue(valueText, extractFontValue, shouldSkipFontNode, callback);
606
+ }
607
+
608
+ // src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
609
+ var handleColorDeclaration = (node, context) => {
610
+ const cssProperty = node.property.toLowerCase();
611
+ const valueText = context.sourceCode.getText(node.value);
612
+ const replacements = [];
613
+ forEachColorValue(valueText, (colorValue, positionInfo) => {
614
+ if (colorValue !== "transparent" && isValidColor(colorValue)) {
615
+ const replacement = createColorReplacement(colorValue, cssProperty, context, positionInfo, valueText);
616
+ if (replacement) {
617
+ replacements.push(replacement);
618
+ }
619
+ }
620
+ });
621
+ handleShorthandAutoFix(node, context, valueText, replacements);
622
+ };
623
+ function createColorReplacement(colorValue, cssProperty, context, positionInfo, originalValueText) {
624
+ if (!positionInfo?.start) {
625
+ return null;
626
+ }
627
+ const hexValue = convertToHex(colorValue);
628
+ if (!hexValue) {
629
+ return null;
630
+ }
631
+ const propToMatch = resolvePropertyToMatch(cssProperty);
632
+ const closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
633
+ const start = positionInfo.start.offset;
634
+ const end = positionInfo.end.offset;
635
+ const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;
636
+ if (closestHooks.length === 1) {
637
+ return {
638
+ start,
639
+ end,
640
+ replacement: `var(${closestHooks[0]}, ${colorValue})`,
641
+ displayValue: closestHooks[0],
642
+ hasHook: true
643
+ };
644
+ } else if (closestHooks.length > 1) {
645
+ return {
646
+ start,
647
+ end,
648
+ replacement: originalValue,
649
+ // Use original value to preserve spacing
650
+ displayValue: closestHooks.join(", "),
651
+ hasHook: true
652
+ // ← THE FIX: Multiple hooks still means "has hooks"
653
+ };
654
+ } else {
655
+ return {
656
+ start,
657
+ end,
658
+ replacement: originalValue,
659
+ // Use original value to preserve spacing
660
+ displayValue: originalValue,
661
+ hasHook: false
662
+ };
663
+ }
664
+ }
665
+
666
+ // src/utils/value-utils.ts
667
+ function parseUnitValue(value) {
668
+ if (!value) return null;
669
+ const match = value.match(/^(-?\d*\.?\d+)(px|rem|%)?$/);
670
+ if (!match) return null;
671
+ const number = parseFloat(match[1]);
672
+ const unit = match[2] ? match[2] : null;
673
+ if (isNaN(number)) return null;
674
+ return { number, unit };
675
+ }
676
+ function toAlternateUnitValue(numberVal, unitType) {
677
+ if (unitType === "px") {
678
+ let floatValue = parseFloat(`${numberVal / 16}`);
679
+ if (!isNaN(floatValue)) {
680
+ return {
681
+ unit: "rem",
682
+ number: parseFloat(floatValue.toFixed(4))
683
+ };
684
+ }
685
+ } else if (unitType === "rem") {
686
+ const intValue = parseInt(`${numberVal * 16}`);
687
+ if (!isNaN(intValue)) {
688
+ return {
689
+ unit: "px",
690
+ number: intValue
691
+ };
692
+ }
693
+ }
694
+ return null;
695
+ }
696
+
697
+ // src/utils/styling-hook-utils.ts
698
+ function isValueMatch(valueToMatch, sldsValue) {
699
+ if (!valueToMatch || !sldsValue) {
700
+ return false;
701
+ }
702
+ return valueToMatch.unit == sldsValue.unit && valueToMatch.number === sldsValue.number;
703
+ }
704
+ function getStylingHooksForDensityValue(parsedValue, supportedStylinghooks, cssProperty) {
705
+ if (!parsedValue) return [];
706
+ const alternateValue = toAlternateUnitValue(parsedValue.number, parsedValue.unit);
707
+ const matchedHooks = [];
708
+ for (const [sldsValue, hooks] of Object.entries(supportedStylinghooks)) {
709
+ const parsedSldsValue = parseUnitValue(sldsValue);
710
+ if (isValueMatch(parsedValue, parsedSldsValue) || alternateValue && isValueMatch(alternateValue, parsedSldsValue)) {
711
+ hooks.filter((hook) => hook.properties.includes(cssProperty)).forEach((hook) => matchedHooks.push(hook.name));
712
+ }
713
+ }
714
+ return matchedHooks;
715
+ }
716
+
717
+ // src/rules/v9/no-hardcoded-values/handlers/densityHandler.ts
718
+ var handleDensityDeclaration = (node, context) => {
719
+ const cssProperty = node.property.toLowerCase();
720
+ const valueText = context.sourceCode.getText(node.value);
721
+ const replacements = [];
722
+ forEachDensityValue(valueText, cssProperty, (parsedDimension, positionInfo) => {
723
+ if (parsedDimension) {
724
+ const replacement = createDimensionReplacement(parsedDimension, cssProperty, context, positionInfo);
725
+ if (replacement) {
726
+ replacements.push(replacement);
727
+ }
728
+ }
729
+ });
730
+ handleShorthandAutoFix(node, context, valueText, replacements);
731
+ };
732
+ function createDimensionReplacement(parsedDimension, cssProperty, context, positionInfo) {
733
+ if (!parsedDimension || !positionInfo?.start) {
734
+ return null;
735
+ }
736
+ const rawValue = parsedDimension.unit ? `${parsedDimension.number}${parsedDimension.unit}` : parsedDimension.number.toString();
737
+ const propToMatch = resolvePropertyToMatch(cssProperty);
738
+ const closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
739
+ const start = positionInfo.start.offset;
740
+ const end = positionInfo.end.offset;
741
+ if (closestHooks.length === 1) {
742
+ return {
743
+ start,
744
+ end,
745
+ replacement: `var(${closestHooks[0]}, ${rawValue})`,
746
+ displayValue: closestHooks[0],
747
+ hasHook: true
748
+ };
749
+ } else if (closestHooks.length > 1) {
750
+ return {
751
+ start,
752
+ end,
753
+ replacement: rawValue,
754
+ displayValue: closestHooks.join(", "),
755
+ hasHook: true
756
+ };
757
+ } else {
758
+ return {
759
+ start,
760
+ end,
761
+ replacement: rawValue,
762
+ displayValue: rawValue,
763
+ hasHook: false
764
+ };
765
+ }
766
+ }
767
+
768
+ // src/rules/v9/no-hardcoded-values/handlers/fontHandler.ts
769
+ var handleFontDeclaration = (node, context) => {
770
+ const cssProperty = node.property.toLowerCase();
771
+ const valueText = context.sourceCode.getText(node.value);
772
+ const replacements = [];
773
+ forEachFontValue(valueText, (fontValue, positionInfo) => {
774
+ if (fontValue && isValidFontValue(fontValue, cssProperty)) {
775
+ const replacement = createFontReplacement(fontValue, cssProperty, context, positionInfo);
776
+ if (replacement) {
777
+ replacements.push(replacement);
778
+ }
779
+ }
780
+ });
781
+ handleShorthandAutoFix(node, context, valueText, replacements);
782
+ };
783
+ function isValidFontValue(fontValue, cssProperty) {
784
+ if (cssProperty === "font-size") {
785
+ return !!fontValue.unit;
786
+ } else if (cssProperty === "font-weight") {
787
+ return !fontValue.unit && isKnownFontWeight(fontValue.number);
788
+ } else if (cssProperty === "font") {
789
+ if (!fontValue.unit && isKnownFontWeight(fontValue.number)) {
790
+ return true;
791
+ } else if (fontValue.unit) {
792
+ return true;
793
+ } else {
794
+ return false;
795
+ }
796
+ }
797
+ return false;
798
+ }
799
+ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
800
+ if (!positionInfo?.start) {
801
+ return null;
802
+ }
803
+ const rawValue = fontValue.unit ? `${fontValue.number}${fontValue.unit}` : fontValue.number.toString();
804
+ const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? resolvePropertyToMatch("font-weight") : resolvePropertyToMatch("font-size");
805
+ const closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
806
+ const start = positionInfo.start.offset;
807
+ const end = positionInfo.end.offset;
808
+ if (closestHooks.length === 1) {
809
+ return {
810
+ start,
811
+ end,
812
+ replacement: `var(${closestHooks[0]}, ${rawValue})`,
813
+ displayValue: closestHooks[0],
814
+ hasHook: true
815
+ };
816
+ } else if (closestHooks.length > 1) {
817
+ return {
818
+ start,
819
+ end,
820
+ replacement: rawValue,
821
+ displayValue: closestHooks.join(", "),
822
+ hasHook: true
823
+ };
824
+ } else {
825
+ return {
826
+ start,
827
+ end,
828
+ replacement: rawValue,
829
+ displayValue: rawValue,
830
+ hasHook: false
831
+ };
832
+ }
833
+ }
834
+
835
+ // src/utils/boxShadowValueParser.ts
836
+ var import_css_tree3 = require("@eslint/css-tree");
837
+ function isColorValue(node) {
838
+ if (!node) return false;
839
+ switch (node.type) {
840
+ case "Hash":
841
+ return true;
842
+ // #hex colors
843
+ case "Identifier":
844
+ return isValidColor(node.name);
845
+ case "Function":
846
+ return isCssColorFunction(node.name.toLowerCase());
847
+ default:
848
+ return false;
849
+ }
850
+ }
851
+ function isLengthValue(node) {
852
+ if (!node) return false;
853
+ switch (node.type) {
854
+ case "Dimension":
855
+ const dimensionStr = `${node.value}${node.unit}`;
856
+ return parseUnitValue(dimensionStr) !== null;
857
+ case "Number":
858
+ return Number(node.value) === 0;
859
+ default:
860
+ return false;
861
+ }
862
+ }
863
+ function isInsetKeyword(node) {
864
+ return node?.type === "Identifier" && node.name.toLowerCase() === "inset";
865
+ }
866
+ function extractShadowParts(valueText) {
867
+ const shadows = [];
868
+ let currentShadow = {
869
+ lengthParts: [],
870
+ colorParts: [],
871
+ inset: false
872
+ };
873
+ try {
874
+ const ast = (0, import_css_tree3.parse)(valueText, { context: "value" });
875
+ (0, import_css_tree3.walk)(ast, {
876
+ enter(node) {
877
+ if (node.type === "Function") {
878
+ return this.skip;
879
+ }
880
+ if (isInsetKeyword(node)) {
881
+ currentShadow.inset = true;
882
+ } else if (isLengthValue(node)) {
883
+ currentShadow.lengthParts.push((0, import_css_tree3.generate)(node));
884
+ } else if (isColorValue(node)) {
885
+ currentShadow.colorParts.push((0, import_css_tree3.generate)(node));
886
+ }
887
+ }
888
+ });
889
+ if (currentShadow.lengthParts.length > 0 || currentShadow.colorParts.length > 0 || currentShadow.inset) {
890
+ shadows.push(currentShadow);
891
+ }
892
+ } catch (error) {
893
+ return [];
894
+ }
895
+ return shadows;
896
+ }
897
+ function parseBoxShadowValue(value) {
898
+ const shadowStrings = value.split(",").map((s) => s.trim());
899
+ const allShadows = [];
900
+ for (const shadowString of shadowStrings) {
901
+ const shadows = extractShadowParts(shadowString);
902
+ const parsedShadows = shadows.map((shadow) => {
903
+ const shadowValue = {};
904
+ const lengthProps = ["offsetX", "offsetY", "blurRadius", "spreadRadius"];
905
+ lengthProps.forEach((prop, index) => {
906
+ if (shadow.lengthParts.length > index) {
907
+ shadowValue[prop] = shadow.lengthParts[index];
908
+ }
909
+ });
910
+ if (shadow.colorParts.length > 0) {
911
+ shadowValue.color = shadow.colorParts[0];
912
+ }
913
+ if (shadow.inset) {
914
+ shadowValue.inset = true;
915
+ }
916
+ return shadowValue;
917
+ });
918
+ allShadows.push(...parsedShadows);
919
+ }
920
+ return allShadows;
921
+ }
922
+ function normalizeLengthValue(value) {
923
+ if (!value) return "0px";
924
+ if (value === "0") return "0px";
925
+ return value;
926
+ }
927
+ function isBoxShadowMatch(parsedCssValue, parsedValueHook) {
928
+ if (parsedCssValue.length !== parsedValueHook.length) {
929
+ return false;
930
+ }
931
+ for (let i = 0; i < parsedCssValue.length; i++) {
932
+ const cssShadow = parsedCssValue[i];
933
+ const hookShadow = parsedValueHook[i];
934
+ if (cssShadow.color !== hookShadow.color || cssShadow.inset !== hookShadow.inset) {
935
+ return false;
936
+ }
937
+ const lengthProps = ["offsetX", "offsetY", "blurRadius", "spreadRadius"];
938
+ for (const prop of lengthProps) {
939
+ if (normalizeLengthValue(cssShadow[prop]) !== normalizeLengthValue(hookShadow[prop])) {
940
+ return false;
941
+ }
942
+ }
943
+ }
944
+ return true;
945
+ }
946
+
947
+ // src/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.ts
948
+ function containsCssVariable(valueText) {
949
+ return valueText.includes("var(");
950
+ }
951
+ var handleBoxShadowDeclaration = (node, context) => {
952
+ const cssProperty = node.property.toLowerCase();
953
+ const valueText = context.sourceCode.getText(node.value);
954
+ if (containsCssVariable(valueText)) {
955
+ return;
956
+ }
957
+ const replacements = [];
958
+ const parsedCssValue = parseAndValidateBoxShadow(valueText);
959
+ if (parsedCssValue) {
960
+ const shadowHooks = getBoxShadowHooks(context.valueToStylinghook);
961
+ const closestHooks = findMatchingBoxShadowHooks(parsedCssValue, shadowHooks);
962
+ const positionInfo = {
963
+ start: { offset: 0, line: 1, column: 1 },
964
+ end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
965
+ };
966
+ const replacement = createBoxShadowReplacement(
967
+ valueText,
968
+ closestHooks,
969
+ context,
970
+ positionInfo
971
+ );
972
+ if (replacement) {
973
+ replacements.push(replacement);
974
+ }
975
+ }
976
+ handleShorthandAutoFix(node, context, valueText, replacements);
977
+ };
978
+ function getBoxShadowHooks(supportedStylinghooks) {
979
+ return Object.entries(supportedStylinghooks).filter(([key, value]) => {
980
+ return value.some((hook) => hook.properties.includes("box-shadow"));
981
+ }).map(([key, value]) => {
982
+ return [key, value.map((hook) => hook.name)];
983
+ });
984
+ }
985
+ function parseAndValidateBoxShadow(cssValue) {
986
+ const parsedCssValue = parseBoxShadowValue(cssValue).filter((shadow) => Object.keys(shadow).length > 0);
987
+ if (parsedCssValue.length === 0) {
988
+ return null;
989
+ }
990
+ return parsedCssValue;
991
+ }
992
+ function findMatchingBoxShadowHooks(parsedCssValue, shadowHooks) {
993
+ for (const [shadowHookValue, closestHooks] of shadowHooks) {
994
+ const parsedHookValue = parseAndValidateBoxShadow(shadowHookValue);
995
+ if (parsedHookValue && isBoxShadowMatch(parsedCssValue, parsedHookValue)) {
996
+ return closestHooks;
997
+ }
998
+ }
999
+ return [];
1000
+ }
1001
+ function createBoxShadowReplacement(originalValue, hooks, context, positionInfo) {
1002
+ if (!positionInfo?.start) {
1003
+ return null;
1004
+ }
1005
+ const start = positionInfo.start.offset;
1006
+ const end = positionInfo.end.offset;
1007
+ if (hooks.length === 1) {
1008
+ return {
1009
+ start,
1010
+ end,
1011
+ replacement: `var(${hooks[0]}, ${originalValue})`,
1012
+ displayValue: hooks[0],
1013
+ hasHook: true
1014
+ };
1015
+ } else if (hooks.length > 1) {
1016
+ return {
1017
+ start,
1018
+ end,
1019
+ replacement: originalValue,
1020
+ displayValue: hooks.join(", "),
1021
+ hasHook: true
1022
+ };
1023
+ } else {
1024
+ return {
1025
+ start,
1026
+ end,
1027
+ replacement: originalValue,
1028
+ displayValue: originalValue,
1029
+ hasHook: false
1030
+ };
1031
+ }
1032
+ }
1033
+
1034
+ // src/rules/v9/no-hardcoded-values/noHardcodedValueRule.ts
1035
+ function defineNoHardcodedValueRule(config) {
1036
+ const { ruleConfig: ruleConfig2 } = config;
1037
+ const { type: type2, description: description2, url: url2, messages: messages2 } = ruleConfig2;
1038
+ return {
1039
+ meta: {
1040
+ type: type2,
1041
+ docs: {
1042
+ description: description2,
1043
+ recommended: true,
1044
+ url: url2
1045
+ },
1046
+ fixable: "code",
1047
+ messages: messages2
1048
+ },
1049
+ create(context) {
1050
+ const handlerContext = {
1051
+ valueToStylinghook: config.valueToStylinghook,
1052
+ context,
1053
+ sourceCode: context.sourceCode
1054
+ };
1055
+ const colorOnlySelector = toSelector(colorProperties);
1056
+ const densityOnlySelector = toSelector(densificationProperties);
1057
+ const fontDensitySelector = toSelector(fontProperties);
1058
+ const overlappingProperties = colorProperties.filter((colorProp) => {
1059
+ return densificationProperties.some((densityProp) => {
1060
+ if (densityProp === colorProp) {
1061
+ return true;
1062
+ }
1063
+ if (densityProp.includes("*")) {
1064
+ const regexPattern = new RegExp("^" + densityProp.replace(/\*/g, ".*") + "$");
1065
+ return regexPattern.test(colorProp);
1066
+ }
1067
+ return false;
1068
+ });
1069
+ });
1070
+ const overlappingSet = new Set(overlappingProperties);
1071
+ const colorOnlyProps = colorProperties.filter((prop) => !overlappingSet.has(prop));
1072
+ const densityOnlyProps = densificationProperties.filter((prop) => !overlappingSet.has(prop));
1073
+ const visitors = {};
1074
+ if (colorOnlyProps.length > 0) {
1075
+ const colorOnlySelector2 = toSelector(colorOnlyProps);
1076
+ visitors[colorOnlySelector2] = (node) => {
1077
+ handleColorDeclaration(node, handlerContext);
1078
+ };
1079
+ }
1080
+ if (densityOnlyProps.length > 0) {
1081
+ const densityOnlySelector2 = toSelector(densityOnlyProps);
1082
+ visitors[densityOnlySelector2] = (node) => {
1083
+ handleDensityDeclaration(node, handlerContext);
1084
+ };
1085
+ }
1086
+ visitors[fontDensitySelector] = (node) => {
1087
+ handleFontDeclaration(node, handlerContext);
1088
+ };
1089
+ visitors['Declaration[property="box-shadow"]'] = (node) => {
1090
+ handleBoxShadowDeclaration(node, handlerContext);
1091
+ };
1092
+ if (overlappingProperties.length > 0) {
1093
+ const overlappingSelector = toSelector(overlappingProperties);
1094
+ visitors[overlappingSelector] = (node) => {
1095
+ handleColorDeclaration(node, handlerContext);
1096
+ handleDensityDeclaration(node, handlerContext);
1097
+ };
1098
+ }
1099
+ return visitors;
1100
+ }
1101
+ };
1102
+ }
1103
+
1104
+ // src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.ts
1105
+ var ruleConfig = import_rule_messages.default["no-hardcoded-values-slds2"];
1106
+ var { type, description, url, messages } = ruleConfig;
1107
+ var valueToStylinghook = import_next.default.valueToStylingHooksCosmos;
1108
+ var no_hardcoded_values_slds2_default = defineNoHardcodedValueRule({
1109
+ ruleConfig,
1110
+ valueToStylinghook
1111
+ });
1112
+ //# sourceMappingURL=no-hardcoded-values-slds2.js.map