@salesforce-ux/eslint-plugin-slds 1.0.6-internal → 1.0.7-internal

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +27 -62
  2. package/build/index.js +128 -258
  3. package/build/index.js.map +4 -4
  4. package/build/rules/v9/lwc-token-to-slds-hook.js.map +2 -2
  5. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +30 -86
  6. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +3 -3
  7. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +104 -116
  8. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +3 -3
  9. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +30 -83
  10. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +3 -3
  11. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +74 -78
  12. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +3 -3
  13. package/build/rules/v9/no-hardcoded-values/handlers/index.js +99 -175
  14. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +3 -3
  15. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +101 -221
  16. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
  17. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +101 -221
  18. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
  19. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +101 -221
  20. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +3 -3
  21. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +2 -2
  22. package/build/rules/v9/no-slds-var-without-fallback.js.map +2 -2
  23. package/build/src/types/index.d.ts +0 -31
  24. package/build/src/utils/color-lib-utils.d.ts +9 -16
  25. package/build/src/utils/hardcoded-shared-utils.d.ts +0 -1
  26. package/build/src/utils/property-matcher.d.ts +1 -3
  27. package/build/types/index.js.map +1 -1
  28. package/build/utils/boxShadowValueParser.js.map +2 -2
  29. package/build/utils/color-lib-utils.js +50 -26
  30. package/build/utils/color-lib-utils.js.map +2 -2
  31. package/build/utils/css-utils.js.map +2 -2
  32. package/build/utils/hardcoded-shared-utils.js +16 -29
  33. package/build/utils/hardcoded-shared-utils.js.map +2 -2
  34. package/build/utils/property-matcher.js +6 -20
  35. package/build/utils/property-matcher.js.map +2 -2
  36. package/eslint.config.mjs +2 -5
  37. package/package.json +2 -2
  38. package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js +0 -63
  39. package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js.map +0 -7
  40. package/build/src/rules/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +0 -40
  41. package/build/src/utils/custom-mapping-utils.d.ts +0 -9
  42. package/build/utils/custom-mapping-utils.js +0 -62
  43. package/build/utils/custom-mapping-utils.js.map +0 -7
package/README.md CHANGED
@@ -27,6 +27,8 @@ module.exports = {
27
27
 
28
28
  ### ESLint v9+ (Flat Config)
29
29
 
30
+ #### Basic Configuration
31
+
30
32
  ```javascript
31
33
  // eslint.config.js
32
34
  const { defineConfig } = require('eslint/config');
@@ -42,6 +44,31 @@ module.exports = defineConfig([
42
44
  ]);
43
45
  ```
44
46
 
47
+ #### Using with Other Plugins
48
+
49
+ To use the ESLint plugin with other plugins, add the `sldsCssPlugin()` helper function to the `eslint.config.mjs` configuration file. The `sldsCssPlugin()` function returns an object that contains the configurations for the ESLint plugin. This makes it easy to combine the ESLint plugin with other plugins while maintaining all the required dependencies.
50
+
51
+ For example, to use the ESLint plugin with the CSS plugin, add the CSS plugin configuration to the object containing the ESLint plugin configuration.
52
+
53
+ ```javascript
54
+ // eslint.config.mjs
55
+ import { defineConfig } from 'eslint/config';
56
+ import css from '@eslint/css';
57
+ import { sldsCssPlugin } from '@salesforce-ux/eslint-plugin-slds';
58
+
59
+ export default defineConfig([
60
+ {
61
+ files: ['**/*.css'],
62
+ language: 'css/css',
63
+ plugins: {
64
+ css: css,
65
+ ...sldsCssPlugin()
66
+ },
67
+ extends: ['@salesforce-ux/slds/recommended', 'css/recommended']
68
+ }
69
+ ]);
70
+ ```
71
+
45
72
  ## Migrate to the Latest Version
46
73
 
47
74
  By default, the latest version of the plugin supports legacy and flat config systems.
@@ -69,68 +96,6 @@ By default, the latest version of the plugin supports legacy and flat config sys
69
96
  - `reduce-annotations`: Identifies annotations that must be removed from the code.
70
97
  - `lwc-token-to-slds-hook`: Identifies the deprecated --lwc tokens that must be replaced with the latest --slds tokens. For more information, see lightningdesignsystem.com.
71
98
 
72
- ## Closest Color Suggestion Logic
73
-
74
- This plugin suggests SLDS styling hooks that are perceptually closest to a given hardcoded color. The logic lives in `src/utils/color-lib-utils.ts` and is used by `no-hardcoded-values-slds2`.
75
-
76
- - **API surface**
77
- - `findClosestColorHook(color, supportedColors, cssProperty): string[]`
78
- Returns up to 5 hook names, ordered by category priority and perceptual distance.
79
- - `isHardCodedColor(value): boolean`
80
- Detects if a string likely represents a hardcoded color (excludes CSS `var(...)`).
81
-
82
- - **Perceptual metric**
83
- - Uses `chroma.deltaE` (CIEDE2000) to compare the input color against known SLDS color values.
84
- - A threshold (`DELTAE_THRESHOLD = 25`) controls how strict the matching is.
85
- - Exact hex matches short-circuit to distance `0` to avoid float rounding differences.
86
-
87
- - **Category ordering**
88
- - Hooks are ranked by category, then by distance (ascending):
89
- 1. Semantic hooks (e.g., surface, accent, error, success, etc.)
90
- 2. System hooks
91
- 3. Palette hooks
92
- - Only the top 5 suggestions are returned.
93
-
94
- - **Property awareness**
95
- - Suggestions consider the CSS property from rule context.
96
- - Hooks declared for the same property (or `*`) are prioritized if within the distance threshold.
97
-
98
- - **CSS variables**
99
- - Values using `var(...)` are not flagged as hardcoded colors and are excluded from matching.
100
-
101
- - **Semantic hook ordering by CSS property**
102
- The sorter always applies the same category priority (semantic → system → palette). Within the semantic category, ordering is purely by perceptual distance for the current CSS property; there is no hardcoded sub-priority among semantic families (surface, accent, error, etc.). Property awareness comes from the metadata (`properties` on each hook).
103
-
104
- - `color`
105
- - Prefers semantic hooks that declare `properties: ['color']` (e.g., text/foreground-oriented tokens).
106
- - If multiple semantic hooks are eligible, they are ordered by Delta E (closest first).
107
- - If none are within threshold, the sorter may fall back to system, then palette.
108
-
109
- - `background-color`
110
- - Prefers semantic surface/role tokens that declare `['background-color']`.
111
- - Among eligible semantic hooks, order is by Delta E.
112
-
113
- - `border-color` (and `outline-color`)
114
- - Prefers semantic or system hooks that declare `['border-color']` (or `['outline-color']`).
115
- - If semantic hooks exist for borders, they are ranked before system; otherwise system hooks lead.
116
- - Order within the chosen category is by Delta E.
117
-
118
- - `box-shadow`
119
- - For color components inside shadows, prefers hooks declaring `['box-shadow']` or universal `['*']`.
120
- - Ordering within semantic remains by Delta E.
121
-
122
- - Other properties
123
- - If hook metadata specifies the current property, those hooks are preferred.
124
- - Hooks with `['*']` (universal) are considered next.
125
- - If still none within threshold, different-property hooks may be considered (still subject to category priority and Delta E).
126
-
127
- - **Example**
128
- ```js
129
- // Given a hex color and a CSS property like 'color'
130
- const suggestions = findClosestColorHook('#ff0000', supportedColors, 'color');
131
- // => ['--slds-...semantic-...', '--slds-...system-...', ...]
132
- ```
133
-
134
99
  ## License
135
100
 
136
101
  ISC