@salesforce-ux/eslint-plugin-slds 1.0.4 → 1.0.6-internal
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/build/index.js +280 -141
- package/build/index.js.map +4 -4
- package/build/rules/enforce-bem-usage.js +5 -5
- package/build/rules/enforce-bem-usage.js.map +3 -3
- package/build/rules/no-deprecated-classes-slds2.js +2 -2
- package/build/rules/no-deprecated-classes-slds2.js.map +2 -2
- package/build/rules/v9/enforce-bem-usage.js +2 -2
- package/build/rules/v9/enforce-bem-usage.js.map +2 -2
- package/build/rules/v9/enforce-component-hook-naming-convention.js +2 -2
- package/build/rules/v9/enforce-component-hook-naming-convention.js.map +2 -2
- package/build/rules/v9/enforce-sds-to-slds-hooks.js +2 -2
- package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +2 -2
- package/build/rules/v9/lwc-token-to-slds-hook.js +2 -2
- package/build/rules/v9/lwc-token-to-slds-hook.js.map +2 -2
- package/build/rules/v9/no-deprecated-slds-classes.js +2 -2
- package/build/rules/v9/no-deprecated-slds-classes.js.map +2 -2
- package/build/rules/v9/no-deprecated-tokens-slds1.js +2 -2
- package/build/rules/v9/no-deprecated-tokens-slds1.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +86 -30
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +116 -104
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +83 -30
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +78 -74
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/index.js +175 -99
- package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +223 -103
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +223 -103
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +221 -101
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js +63 -0
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js.map +7 -0
- package/build/rules/v9/no-slds-class-overrides.js +2 -2
- package/build/rules/v9/no-slds-class-overrides.js.map +2 -2
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +2 -2
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js.map +2 -2
- package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +2 -2
- package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +2 -2
- package/build/rules/v9/no-unsupported-hooks-slds2.js +2 -2
- package/build/rules/v9/no-unsupported-hooks-slds2.js.map +2 -2
- package/build/src/rules/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +40 -0
- package/build/src/types/index.d.ts +31 -0
- package/build/src/utils/color-lib-utils.d.ts +16 -9
- package/build/src/utils/custom-mapping-utils.d.ts +9 -0
- package/build/src/utils/hardcoded-shared-utils.d.ts +1 -0
- package/build/src/utils/property-matcher.d.ts +3 -1
- package/build/types/index.js.map +1 -1
- package/build/utils/boxShadowValueParser.js.map +2 -2
- package/build/utils/color-lib-utils.js +26 -50
- package/build/utils/color-lib-utils.js.map +2 -2
- package/build/utils/css-utils.js.map +2 -2
- package/build/utils/custom-mapping-utils.js +62 -0
- package/build/utils/custom-mapping-utils.js.map +7 -0
- package/build/utils/hardcoded-shared-utils.js +29 -16
- package/build/utils/hardcoded-shared-utils.js.map +2 -2
- package/build/utils/property-matcher.js +20 -6
- package/build/utils/property-matcher.js.map +2 -2
- package/build/utils/styling-hook-utils.js.map +1 -1
- package/eslint.config.mjs +1 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -69,6 +69,68 @@ By default, the latest version of the plugin supports legacy and flat config sys
|
|
|
69
69
|
- `reduce-annotations`: Identifies annotations that must be removed from the code.
|
|
70
70
|
- `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
71
|
|
|
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
|
+
|
|
72
134
|
## License
|
|
73
135
|
|
|
74
136
|
ISC
|