@salesforce/afv-skills 1.5.2 → 1.5.3
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 +5 -6
- package/package.json +3 -3
- package/skills/generating-apex/SKILL.md +16 -9
- package/skills/generating-apex/assets/abstract.cls +0 -1
- package/skills/generating-apex/assets/batch.cls +0 -1
- package/skills/generating-apex/assets/domain.cls +0 -1
- package/skills/generating-apex/assets/dto.cls +0 -1
- package/skills/generating-apex/assets/exception.cls +0 -1
- package/skills/generating-apex/assets/interface.cls +0 -1
- package/skills/generating-apex/assets/invocable.cls +0 -1
- package/skills/generating-apex/assets/queueable.cls +0 -1
- package/skills/generating-apex/assets/schedulable.cls +0 -1
- package/skills/generating-apex/assets/selector.cls +0 -1
- package/skills/generating-apex/assets/service.cls +0 -1
- package/skills/generating-apex/assets/trigger.cls +1 -1
- package/skills/generating-apex/assets/utility.cls +0 -1
- package/skills/generating-apex/references/AccountDeduplicationBatch.cls +0 -1
- package/skills/generating-apex/references/AccountSelector.cls +0 -1
- package/skills/generating-apex/references/AccountService.cls +0 -1
- package/skills/generating-apex-test/assets/test-class-template.cls +3 -3
- package/skills/generating-apex-test/references/assertion-patterns.md +1 -1
- package/skills/generating-apex-test/references/async-testing.md +1 -1
- package/skills/uplifting-components-to-slds2/SKILL.md +236 -0
- package/skills/uplifting-components-to-slds2/references/color-hooks-decision-guide.md +438 -0
- package/skills/uplifting-components-to-slds2/references/common-patterns.md +87 -0
- package/skills/uplifting-components-to-slds2/references/examples.md +443 -0
- package/skills/uplifting-components-to-slds2/references/migration-checklist.md +67 -0
- package/skills/uplifting-components-to-slds2/references/non-color-hooks-decision-guide.md +333 -0
- package/skills/uplifting-components-to-slds2/references/rule-lwc-token-to-slds-hook.md +135 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-deprecated-tokens-slds1.md +211 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-hardcoded-values.md +160 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-slds-class-overrides.md +126 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Rule: No Hardcoded Values
|
|
2
|
+
|
|
3
|
+
**Rule ID:** `slds/no-hardcoded-values-slds2`
|
|
4
|
+
**Severity:** Warning
|
|
5
|
+
**Scope:** All CSS properties with hardcoded values that have SLDS 2 hook equivalents — colors, spacing, sizing, typography, borders, radius, and shadows.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What the Linter Does
|
|
10
|
+
|
|
11
|
+
The linter detects hardcoded values and reports them as warnings. Here's real output for an icon component:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
3:10 warning Consider replacing the 32px static value with an SLDS 2 styling hook
|
|
15
|
+
that has a similar value: --slds-g-sizing-9. slds/no-hardcoded-values-slds2
|
|
16
|
+
|
|
17
|
+
5:21 warning Dynamic element with css-class "icon-container" using static value
|
|
18
|
+
"#066afe" for "background-color" css property. Consider replacing
|
|
19
|
+
the #066AFE static value with an SLDS 2 styling hook:
|
|
20
|
+
1. --slds-g-color-surface-inverse-1
|
|
21
|
+
2. --slds-g-color-surface-inverse-2
|
|
22
|
+
3. --slds-g-color-surface-container-inverse-1 slds/no-hardcoded-values-slds2
|
|
23
|
+
|
|
24
|
+
9:9 warning Dynamic element with css-class "account-icon" using static value
|
|
25
|
+
"#ffffff" for "fill" css property. Consider replacing:
|
|
26
|
+
1. --slds-g-color-on-accent-1
|
|
27
|
+
2. --slds-g-color-on-accent-2
|
|
28
|
+
3. --slds-g-color-error-base-95
|
|
29
|
+
4. --slds-g-color-warning-base-95 slds/no-hardcoded-values-slds2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Non-color values** get single suggestions — auto-fixable with `--fix`:
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
/* 32px → sizing-9 (single suggestion, auto-fixed) */
|
|
36
|
+
width: var(--slds-g-sizing-9, 32px);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Color values** get multiple suggestions — requires manual selection. The linter suggests hooks based on color-value similarity, **not semantic context**. You must inspect the HTML to choose correctly.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## What to Fix vs What to Skip
|
|
44
|
+
|
|
45
|
+
| Property Type | Example Values | Action |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Color properties (`color`, `fill`, `background`, `background-color`, `stroke`, `border-*-color`, `outline-color`) | `#fff`, `rgb(0,0,0)` | **Fix** — replace with color hook + fallback |
|
|
48
|
+
| Spacing properties (`margin`, `padding`, `gap`) | `16px`, `1rem`, `24px` | **Fix** — replace with spacing hook + fallback |
|
|
49
|
+
| Sizing properties (`width`, `height`, `min-*`, `max-*`) | `32px`, `2rem` | **Fix** — replace with sizing hook + fallback |
|
|
50
|
+
| Font properties (`font-size`, `font-weight`, `line-height`) | `14px`, `bold`, `1.5` | **Fix** — replace with typography hook + fallback |
|
|
51
|
+
| Border properties (`border-radius`, `border-width`) | `8px`, `1px` | **Fix** — replace with radius/border hook + fallback |
|
|
52
|
+
| Shadow properties (`box-shadow`) | `0 4px 8px rgba(…)` | **Fix** — replace with shadow hook + fallback |
|
|
53
|
+
| Layout/structural values | `100%`, `auto`, `0`, `inherit`, `none` | **Skip** — leave unchanged, removing breaks rendering |
|
|
54
|
+
|
|
55
|
+
When the linter says "Remove the static value" for a layout value like `width: 100%` or `height: auto`, **do not remove it**.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Replacement Pattern
|
|
60
|
+
|
|
61
|
+
Always include the original value as fallback:
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
property: var(--slds-g-[hook], originalValue);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The fallback must be the **exact original value** from the source CSS (e.g., `#066AFE`, not a converted equivalent).
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Decision Tree
|
|
72
|
+
|
|
73
|
+
When examining a hardcoded value or deprecated token, follow this decision tree:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
1. SLDS utility class available?
|
|
77
|
+
└─ Yes → Remove CSS, add utility class to HTML
|
|
78
|
+
└─ No ↓
|
|
79
|
+
|
|
80
|
+
2. At least one 1:1 styling hook mapping?
|
|
81
|
+
├─ Exactly one → Use it with fallback
|
|
82
|
+
├─ Multiple → Inspect HTML context to choose (see decision guides)
|
|
83
|
+
└─ None ↓
|
|
84
|
+
|
|
85
|
+
3. No exact match
|
|
86
|
+
└─ No close match → Leave hardcoded
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 1: Check for Utility Classes
|
|
90
|
+
|
|
91
|
+
If an SLDS utility class sets the exact property to the exact value, remove the CSS and replace with the class on the HTML element(s).
|
|
92
|
+
|
|
93
|
+
**Best fit vs perfect fit:** Use existing utilities that get you close enough, even if it means combining two or three classes. This keeps markup readable, styles consistent, and avoids unnecessary custom CSS. Don't write new CSS rules for edge cases unless absolutely necessary.
|
|
94
|
+
|
|
95
|
+
**When modifying CSS classes:**
|
|
96
|
+
- Before removing a CSS declaration, ensure you understand how it's used in HTML and in JS (computed classes)
|
|
97
|
+
- Update any tests after changing CSS classes — some tests use class query selectors that should be replaced with `data-tid` attributes
|
|
98
|
+
|
|
99
|
+
#### Example: Replacing with Utility Classes
|
|
100
|
+
|
|
101
|
+
Common CSS like `display: flex` with alignment can often be replaced entirely:
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
/* Before — component.css */
|
|
105
|
+
.container {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: row;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
align-items: center;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<!-- Before — component.html -->
|
|
115
|
+
<div class="container">
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
These styles map to SLDS grid utility classes:
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<!-- After — component.html (CSS removed entirely) -->
|
|
122
|
+
<div class="slds-grid slds-grid_align-center slds-grid_vertical-align-center">
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Note: `flex-direction: row` is the default for `display: flex` — it can be removed entirely.
|
|
126
|
+
|
|
127
|
+
### Steps 2 & 3: Choose the Right Hook
|
|
128
|
+
|
|
129
|
+
For choosing between multiple hooks or finding the closest match, see the decision guides:
|
|
130
|
+
|
|
131
|
+
| Category | Decision Guide |
|
|
132
|
+
|---|---|
|
|
133
|
+
| Color (background, foreground, border color) | [color-hooks-decision-guide.md](color-hooks-decision-guide.md) — surface vs container, semantic vs palette, applied examples from real PRs |
|
|
134
|
+
| Spacing, sizing, typography, borders, radius, shadows | [non-color-hooks-decision-guide.md](non-color-hooks-decision-guide.md) — numbered scales, closest-match rules, density-aware variants |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Common Mistakes
|
|
139
|
+
|
|
140
|
+
1. **Inventing hook names** — Only use hooks documented in the SLDS design system.
|
|
141
|
+
2. **Missing fallback** — Always include the original value: `var(--slds-g-hook, originalValue)`
|
|
142
|
+
3. **Confusing spacing and sizing** — Spacing is for margins/padding/gaps. Sizing is for width/height/dimensions.
|
|
143
|
+
4. **Using named hooks** — `--slds-g-spacing-medium`, `--slds-g-font-weight-bold`, `--slds-g-radius-large` do NOT exist. Only numbered hooks exist.
|
|
144
|
+
5. **Replacing layout values** — Don't replace `100%`, `auto`, `flex: 1`, `none`, or `0` with hooks.
|
|
145
|
+
6. **Blindly trusting linter suggestions for colors** — The linter matches by color value, not semantic context. Always inspect HTML before choosing.
|
|
146
|
+
|
|
147
|
+
## What NOT to Replace
|
|
148
|
+
|
|
149
|
+
Leave these unchanged (no SLDS hooks apply):
|
|
150
|
+
|
|
151
|
+
```css
|
|
152
|
+
width: 100%; /* layout values */
|
|
153
|
+
height: auto; /* layout values */
|
|
154
|
+
flex: 1; /* layout values */
|
|
155
|
+
display: none; /* layout values */
|
|
156
|
+
transition: color 0.3s ease; /* animation values */
|
|
157
|
+
opacity: 0.5; /* opacity */
|
|
158
|
+
background: linear-gradient(…); /* gradients */
|
|
159
|
+
left: 50%; /* positioning offsets */
|
|
160
|
+
```
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Rule: No SLDS Class Overrides
|
|
2
|
+
|
|
3
|
+
**Rule ID:** `slds/no-slds-class-overrides`
|
|
4
|
+
**Severity:** Warning
|
|
5
|
+
**Scope:** Detects CSS selectors that directly target `.slds-*` classes.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What the Linter Does
|
|
10
|
+
|
|
11
|
+
The linter detects CSS classes that directly override SLDS classes and reports them as **warnings**. It does **not** auto-fix — all changes require manual work in both CSS and HTML.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
1:1 warning Overriding slds-button isn't supported. To differentiate SLDS and
|
|
15
|
+
custom classes, create a CSS class in your namespace.
|
|
16
|
+
Examples: myapp-input, myapp-button. slds/no-slds-class-overrides
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Manual steps required:**
|
|
20
|
+
1. Rename `.slds-*` selectors in CSS to `{componentName}-{sldsElementPart}`
|
|
21
|
+
2. Add the new component class to markup (`.html` for LWC, `.cmp` for Aura) **alongside** the original SLDS class
|
|
22
|
+
3. Never remove the original SLDS class from markup
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Naming Convention
|
|
27
|
+
|
|
28
|
+
**Format:** `{componentName}-{sldsElementPart}` (camelCase component name)
|
|
29
|
+
|
|
30
|
+
| SLDS Class | Component: `userProfile` | Result |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `.slds-button` | `userProfile` | `userProfile-button` |
|
|
33
|
+
| `.slds-card` | `userProfile` | `userProfile-card` |
|
|
34
|
+
| `.slds-modal__content` | `userProfile` | `userProfile-modal__content` |
|
|
35
|
+
| `.slds-button_brand` | `userProfile` | `userProfile-button_brand` |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Common Patterns
|
|
40
|
+
|
|
41
|
+
### Pattern 1: Simple Selector
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
/* Before CSS */
|
|
45
|
+
.slds-button { border-radius: 8px; }
|
|
46
|
+
|
|
47
|
+
/* After CSS */
|
|
48
|
+
.myComponent-button { border-radius: 8px; }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<!-- After HTML (manual) -->
|
|
53
|
+
<button class="slds-button myComponent-button">Click</button>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Pattern 2: Descendant Selector
|
|
57
|
+
|
|
58
|
+
```css
|
|
59
|
+
/* Before CSS */
|
|
60
|
+
.slds-card .slds-button { margin-top: 1rem; }
|
|
61
|
+
|
|
62
|
+
/* After CSS */
|
|
63
|
+
.myComponent-card .myComponent-button { margin-top: 1rem; }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<!-- After HTML (manual) — each SLDS class gets a component class -->
|
|
68
|
+
<div class="slds-card myComponent-card">
|
|
69
|
+
<button class="slds-button myComponent-button">Click</button>
|
|
70
|
+
</div>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Pattern 3: Multi-Class Selector
|
|
74
|
+
|
|
75
|
+
```css
|
|
76
|
+
/* Before CSS */
|
|
77
|
+
.slds-card.slds-p-around_medium { border: 1px solid blue; }
|
|
78
|
+
|
|
79
|
+
/* After CSS */
|
|
80
|
+
.myComponent-card.myComponent-p-around_medium { border: 1px solid blue; }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<!-- After HTML (manual) -->
|
|
85
|
+
<div class="slds-card slds-p-around_medium myComponent-card myComponent-p-around_medium">
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Core Rules
|
|
91
|
+
|
|
92
|
+
1. **Never remove SLDS classes** from markup (`.html` or `.cmp`) — only ADD component classes alongside them
|
|
93
|
+
2. **One-to-one mapping** — each SLDS class in a CSS selector gets exactly one component class
|
|
94
|
+
3. **CamelCase component name** — `sampleComponent-button`, not `sample-component-button`
|
|
95
|
+
4. **Preserve SLDS element names** — `.slds-button` becomes `componentName-button` (strip `slds-` prefix, keep the rest)
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Interaction with Other Rules
|
|
100
|
+
|
|
101
|
+
If the overridden CSS properties include hardcoded colors, you must also apply `rule-no-hardcoded-values.md` to those properties:
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
/* Before */
|
|
105
|
+
.slds-icon-action-check { background: #4bca81; }
|
|
106
|
+
|
|
107
|
+
/* After — both rules applied */
|
|
108
|
+
.myComponent-icon-action-check { background: var(--slds-g-color-success-base-70, #4bca81); }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Validation Checklist
|
|
116
|
+
|
|
117
|
+
**CSS:**
|
|
118
|
+
- [ ] All `.slds-*` overrides reported by the linter are addressed
|
|
119
|
+
- [ ] Component name is camelCase
|
|
120
|
+
- [ ] SLDS element names preserved after prefix
|
|
121
|
+
|
|
122
|
+
**Markup (`.html` for LWC, `.cmp` for Aura):**
|
|
123
|
+
- [ ] Original SLDS classes preserved
|
|
124
|
+
- [ ] Component classes added alongside SLDS classes
|
|
125
|
+
- [ ] Every element in CSS selector chain updated in markup
|
|
126
|
+
- [ ] One component class per SLDS class
|