validating-slds
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSLDS Quality Audit
SLDS质量审计
Audit Lightning Web Components for SLDS compliance and produce an automated scorecard plus a required manual review gate. Combines SLDS linter output with supplementary static analysis to catch what the linter misses.
审计Lightning Web Components的SLDS合规性,生成自动化评分卡并设置必要的人工审核关卡。结合SLDS linter输出与补充静态分析,捕捉linter遗漏的问题。
Scope
适用范围
Also valid for: auditing SLDS compliance across a project or component set, and before/after quality comparison after making changes.
Not for:
- Fixing linter violations — use instead
uplifting-components-to-slds2 - Building new components — use instead
applying-slds - Just running the linter — run directly
npx @salesforce-ux/slds-linter@latest lint . - Full WCAG accessibility audit — this skill checks attribute presence only (labels, alt text, focus indicators), not contrast ratios, keyboard flows, or screen reader behavior
- Framework-specific template auditing beyond ,
.css, and.htmlfiles — JSX/TSX/Vue/Svelte outputs need additional manual review.js
也适用于:审计整个项目或组件集的SLDS合规性,以及修改前后的质量对比。
不适用于:
- 修复linter违规问题 —— 请改用
uplifting-components-to-slds2 - 构建新组件 —— 请改用
applying-slds - 仅运行linter —— 直接执行
npx @salesforce-ux/slds-linter@latest lint . - 完整WCAG可访问性审计 —— 本技能仅检查属性是否存在(标签、替代文本、焦点指示器),不检查对比度、键盘流程或屏幕阅读器行为
- 除、
.css和.html文件外的框架特定模板审计 —— JSX/TSX/Vue/Svelte输出需额外人工审核.js
Quality Validation Process
质量验证流程
1. Run SLDS Linter → Collect violation counts (linter's job)
2. Run Analyze Script → Check what linter doesn't cover (supplementary)
3. Agent Review → Required manual review gate
4. Score & Grade → Compute automated score + final recommendation
5. Generate Report → Produce formatted scorecard1. 运行SLDS Linter → 收集违规数量(linter的职责)
2. 运行分析脚本 → 检查linter未覆盖的内容(补充分析)
3. 人工审核 → 必要的人工审核关卡
4. 评分与评级 → 计算自动化分数 + 最终建议
5. 生成报告 → 生成格式化评分卡Step 1: Run SLDS Linter
步骤1:运行SLDS Linter
Run the linter to collect baseline violation data:
bash
npx @salesforce-ux/slds-linter@latest lint <component-path> 2>&1Count violations by rule. These feed directly into the Linter Compliance score:
| Rule | Impact |
|---|---|
| Breaks theming, dark mode |
| SLDS 1 technical debt |
| Breaks theming, accessibility |
Linter Compliance Score = , minimum 0.
100 - (total_violations × 10)If the linter is unavailable (no Node.js, no network access, CI sandbox restrictions): skip this step, note "Linter not run" in the report header, mark Linter Compliance as N/A, and compute the Overall score using the remaining 4 categories renormalized to 100%:
Overall (linter unavailable) = (Theming × 0.29) + (Accessibility × 0.29)
+ (CodeQuality × 0.21) + (ComponentUsage × 0.21)运行linter收集基线违规数据:
bash
npx @salesforce-ux/slds-linter@latest lint <component-path> 2>&1按规则统计违规数量,这些数据直接计入Linter合规性得分:
| 规则 | 影响 |
|---|---|
| 破坏主题、深色模式 |
| SLDS 1技术债务 |
| 破坏主题、可访问性 |
Linter合规性得分 = ,最低为0。
100 - (总违规数 × 10)若linter不可用(无Node.js、无网络访问、CI沙箱限制):跳过此步骤,在报告标题中注明「Linter未运行」,标记Linter合规性为N/A,并使用剩余4个分类重新归一化至100%计算整体得分:
整体得分(linter不可用) = (主题 × 0.29) + (可访问性 × 0.29)
+ (代码质量 × 0.21) + (组件使用 × 0.21)Step 2: Run Supplementary Analysis
步骤2:运行补充分析
Run the analyze script to catch issues the linter doesn't cover. The bundled analyzer scans , , and files only:
.css.html.jsbash
node scripts/analyze-quality.cjs <component-path>The script outputs JSON with findings organized by severity. It checks:
运行分析脚本捕捉linter未覆盖的问题。内置分析器仅扫描、和文件:
.css.html.jsbash
node scripts/analyze-quality.cjs <component-path>脚本输出按严重程度分类的JSON结果,检查内容包括:
CSS Checks (linter-complementary)
CSS检查(补充linter)
| Check | What It Catches | Severity |
|---|---|---|
| Missing fallbacks | | Critical |
| Invented hooks (T051) | | Critical |
| Hook pairing | Background hooks without matching foreground hooks | Warning |
| Specificity overrides | Warning |
| Magic pixel values | Hardcoded | Warning |
| High z-index | z-index values > 99 | Warning |
| Outline removal | | Warning |
| 检查项 | 检测内容 | 严重程度 |
|---|---|---|
| 缺失回退值 | | 严重 |
| 自定义钩子(T051) | | 严重 |
| 钩子配对 | 背景钩子未匹配对应前景钩子 | 警告 |
| 优先级覆盖 | 警告 |
| 魔法像素值 | 硬编码 | 警告 |
| 高z-index | z-index值>99 | 警告 |
| 移除轮廓 | | 警告 |
JS Checks
JS检查
| Check | What It Catches | Severity |
|---|---|---|
| Inline style assignment | | Warning |
| SLDS class manipulation | Dynamic | Warning |
| 检查项 | 检测内容 | 严重程度 |
|---|---|---|
| 内联样式赋值 | | 警告 |
| SLDS类操作 | 动态 | 警告 |
HTML Checks
HTML检查
| Check | What It Catches | Severity |
|---|---|---|
| LBC input labels | | Critical |
| Icon alt text | | Critical |
| Image alt text | | Critical |
| Heading hierarchy | Skipped heading levels (h2 to h4) | Warning |
| Positive tabindex | | Warning |
| Clickable divs | | Warning |
| Inline styles | | Warning |
| Native elements | | Warning |
| 检查项 | 检测内容 | 严重程度 |
|---|---|---|
| LBC输入标签 | | 严重 |
| 图标替代文本 | | 严重 |
| 图片替代文本 | | 严重 |
| 标题层级 | 跳过标题层级(如h2直接到h4) | 警告 |
| 正tabindex值 | | 警告 |
| 可点击div | 使用 | 警告 |
| 内联样式 | | 警告 |
| 原生元素 | 在可用LBC替代方案的情况下使用 | 警告 |
Hook Pairing Validation
钩子配对验证
The script checks that background/foreground hooks are semantically paired:
surface-* backgrounds → on-surface-* text
surface-container-* bg → on-surface-* text
accent-* backgrounds → on-accent-* text
accent-container-* bg → on-accent-* textLimitation: Hook pairing is checked at the file level, not per-selector. A file withinsurface-1and.classAinon-accent-1would pass because both surface and accent families are present. Review pairing correctness per-selector during manual review (Step 3)..classB
脚本检查背景/前景钩子是否语义配对:
surface-* 背景 → on-surface-* 文本
surface-container-* 背景 → on-surface-* 文本
accent-* 背景 → on-accent-* 文本
accent-container-* 背景 → on-accent-* 文本局限性: 钩子配对按文件级别检查,而非选择器级别。若文件中使用.classA,surface-1使用.classB,因同时存在surface和accent系列,会判定为通过。需在人工审核(步骤3)中按选择器检查配对正确性。on-accent-1
Invented Hook Detection (T051)
自定义钩子检测(T051)
The script cross-references every token in CSS against . Any hook not found in metadata is flagged as critical — this catches the most common agent mistake of inventing hooks from naming patterns.
--slds-g-*hooks-index.json脚本将CSS中所有令牌与交叉比对。任何未在元数据中找到的钩子会被标记为严重问题——这能捕捉到最常见的错误:根据命名模式自定义钩子。
--slds-g-*hooks-index.jsonStep 3: Agent Manual Review
步骤3:人工审核
These checks require understanding the component's purpose and cannot be automated reliably. Review each and classify findings as either:
- Blocking — incorrect blueprint structure, missing required states, or semantic/interaction issues that make the component not production-ready
- Advisory — worthwhile improvements that do not block shipping on their own
| Review Area | What to Look For |
|---|---|
| Loading states | Does the component show a spinner or skeleton when fetching data? |
| Error states | Are errors surfaced to the user with actionable messages? |
| Empty states | Is there a meaningful empty state when no data exists? |
| Disabled states | Do interactive elements visually and functionally handle disabled? |
| Semantic HTML | Are |
| SLDS blueprint compliance | Do cards, modals, forms follow SLDS blueprint structure? |
Manual review findings are not automated, but they do affect the final recommendation. Do not report an automated grade as the only verdict.
这些检查需要理解组件用途,无法可靠自动化。逐一检查并将结果分类为:
- 阻塞性 —— 蓝图结构错误、缺失必要状态,或语义/交互问题导致组件无法投入生产
- 建议性 —— 值得改进但不单独阻碍发布的问题
| 审核领域 | 检查要点 |
|---|---|
| 加载状态 | 组件在获取数据时是否显示加载动画或骨架屏? |
| 错误状态 | 是否向用户展示可操作的错误提示信息? |
| 空状态 | 无数据时是否显示有意义的空状态? |
| 禁用状态 | 交互元素是否在视觉和功能上正确处理禁用状态? |
| 语义化HTML | 是否在合适场景使用 |
| SLDS蓝图合规性 | 卡片、模态框、表单是否遵循SLDS蓝图结构? |
人工审核结果无法自动化,但会影响最终建议。不能仅以自动化评级作为唯一结论。
Step 4: Calculate Automated Scores and Final Recommendation
步骤4:计算自动化分数与最终建议
Component Complexity
组件复杂度
Before scoring, classify the component to give the score context:
| Complexity | Criteria | Report Note |
|---|---|---|
| Small | 1-2 files, < 100 total lines | Score is high-confidence (small surface area) |
| Medium | 3-6 files, 100-500 total lines | Score reflects typical component |
| Large | 7+ files, 500+ total lines | Score reflects absolute issue count — even well-built large components may score lower |
Include the complexity classification in the report header. This prevents misreading a "B" on a 1000-line component vs. a "B" on a 20-line component.
评分前先对组件分类,为分数提供上下文:
| 复杂度 | 判定标准 | 报告备注 |
|---|---|---|
| 小型 | 1-2个文件,总行数<100 | 分数可信度高(影响范围小) |
| 中型 | 3-6个文件,总行数100-500 | 分数反映典型组件水平 |
| 大型 | 7+个文件,总行数500+ | 分数反映绝对问题数量——即使构建良好的大型组件分数可能较低 |
需在报告标题中包含复杂度分类,避免误解:比如1000行组件的「B」级与20行组件的「B」级含义不同。
Automated Scoring Formula
自动化评分公式
Category Score = 100 - (critical_issues × 10) - (warnings × 3) - (info × 1)
Minimum score: 0分类得分 = 100 - (严重问题数 × 10) - (警告数 × 3) - (信息类问题数 × 1)
最低得分:0Categories and Weights
分类与权重
| Category | Weight | Source |
|---|---|---|
| Linter Compliance | 30% | SLDS linter output (Step 1) |
| Theming | 20% | Script: fallbacks, hook pairing (Step 2) |
| Accessibility | 20% | Script: labels, alt text, focus (Step 2) |
| Code Quality | 15% | Script: !important, inline styles, z-index (Step 2) |
| Component Usage | 15% | Script: native elements (Step 2) plus manual semantic/blueprint review (Step 3) |
| 分类 | 权重 | 数据来源 |
|---|---|---|
| Linter合规性 | 30% | SLDS linter输出(步骤1) |
| 主题 | 20% | 脚本:回退值、钩子配对(步骤2) |
| 可访问性 | 20% | 脚本:标签、替代文本、焦点(步骤2) |
| 代码质量 | 15% | 脚本:!important、内联样式、z-index(步骤2) |
| 组件使用 | 15% | 脚本:原生元素(步骤2) + 人工语义/蓝图审核(步骤3) |
Automated Overall Score
自动化整体得分
Overall = (Linter × 0.30) + (Theming × 0.20) + (Accessibility × 0.20)
+ (CodeQuality × 0.15) + (ComponentUsage × 0.15)整体得分 = (Linter得分 × 0.30) + (主题得分 × 0.20) + (可访问性得分 × 0.20)
+ (代码质量得分 × 0.15) + (组件使用得分 × 0.15)Automated Grade Thresholds
自动化评级阈值
| Score | Grade | Meaning |
|---|---|---|
| 90-100 | A | Excellent automated score |
| 80-89 | B | Good automated score |
| 70-79 | C | Acceptable automated score |
| 60-69 | D | Weak automated score |
| 0-59 | F | Failing automated score |
| 分数 | 评级 | 含义 |
|---|---|---|
| 90-100 | A | 自动化得分优秀 |
| 80-89 | B | 自动化得分良好 |
| 70-79 | C | 自动化得分合格 |
| 60-69 | D | 自动化得分较差 |
| 0-59 | F | 自动化得分不合格 |
Manual Review Gate
人工审核关卡
After computing the automated score, apply the manual review outcome:
| Gate | When to use it | Effect on final recommendation |
|---|---|---|
| Pass | No manual findings | Final recommendation can follow the automated score |
| Advisory | Only non-blocking manual findings | Final recommendation can be "Ready with follow-ups" at best |
| Blocking | One or more blocking manual findings | Final recommendation is not ready for production, regardless of automated grade |
计算自动化得分后,结合人工审核结果:
| 关卡状态 | 适用场景 | 对最终建议的影响 |
|---|---|---|
| 通过 | 无人工审核问题 | 最终建议可遵循自动化得分 |
| 建议性 | 仅存在非阻塞性人工审核问题 | 最终建议最高为「需跟进优化,可发布」 |
| 阻塞性 | 存在一个或多个阻塞性人工审核问题 | 无论自动化评级如何,最终建议为未就绪,不可投入生产 |
Final Recommendation Rules
最终建议规则
Use both the automated score and the manual review gate:
| Final Recommendation | Conditions |
|---|---|
| Ready for production | Automated grade A/B, no critical findings, manual gate = Pass |
| Ready with follow-ups | Automated grade A/B, no critical findings, manual gate = Advisory |
| Needs work | Any critical findings, automated grade C/D, or manual gate = Blocking |
| Failing | Automated grade F |
结合自动化得分与人工审核关卡结果:
| 最终建议 | 条件 |
|---|---|
| 可投入生产 | 自动化评级A/B,无严重问题,人工审核关卡=通过 |
| 需跟进优化,可发布 | 自动化评级A/B,无严重问题,人工审核关卡=建议性 |
| 需要改进 | 存在任何严重问题、自动化评级C/D,或人工审核关卡=阻塞性 |
| 不合格 | 自动化评级F |
Step 5: Generate Quality Report
步骤5:生成质量报告
Use the template in report-format.md to produce the final report. Default to the compact format for initial output and expand sections on request.
The report includes:
- Executive summary with automated grade and final recommendation
- Manual review gate outcome (,
Pass, orAdvisory)Blocking - Scores by category with visual indicators
- Detailed findings organized by severity
- Specific code locations and recommendations
- Checklist of required actions
使用**report-format.md中的模板生成最终报告。初始输出默认使用紧凑格式**,可根据需求展开章节。
报告包含:
- 执行摘要(含自动化评级与最终建议)
- 人工审核关卡结果(、
通过或建议性)阻塞性 - 各分类得分与可视化指标
- 按严重程度分类的详细问题
- 具体代码位置与改进建议
- 必要操作清单
Quick Validation Mode
快速验证模式
For a rapid quality check without full analysis:
- Run linter:
npx @salesforce-ux/slds-linter@latest lint <path> - Count violations by type
- Report summary only
Quick Quality Check: <component-name>
─────────────────────────────────────
Linter Violations:
• Class Override: 0
• Deprecated Tokens: 3
• Hardcoded Values: 5
Quick Automated Grade: C (estimated)
Run full validation for detailed report.无需完整分析的快速质量检查:
- 运行linter:
npx @salesforce-ux/slds-linter@latest lint <path> - 按类型统计违规数量
- 仅报告摘要
快速质量检查:<component-name>
─────────────────────────────────────
Linter违规:
• 类覆盖: 0
• 已弃用令牌: 3
• 硬编码值: 5
快速自动化评级:C(预估)
运行完整验证获取详细报告。Edge Cases and False Positives
边缘情况与误报
| Situation | Guidance |
|---|---|
| Headless components (JS-only, no HTML) | Skip HTML checks; score only CSS + linter categories |
| Wrapper/container components | May legitimately have minimal CSS; don't penalize low hook usage |
| Intentional native elements | |
| Components outside LEX | LWR/Experience Cloud components may not use Lightning Base Components; note context in report |
| Test/demo components | Lower the bar — note in report but don't block on warnings |
If a check produces a false positive, note it in the report as "suppressed" with justification rather than silently dropping it.
| 场景 | 处理指南 |
|---|---|
| 无头组件(仅JS,无HTML) | 跳过HTML检查;仅对CSS + linter分类评分 |
| 包装/容器组件 | 可能合理使用少量CSS;不要因钩子使用率低而扣分 |
| 有意使用原生元素 | 在自定义SLDS蓝图内使用 |
| LEX外组件 | LWR/Experience Cloud组件可能不使用Lightning Base Components;在报告中注明上下文 |
| 测试/演示组件 | 降低标准——在报告中注明但不因警告阻塞发布 |
若检查产生误报,需在报告中注明「已抑制」并说明理由,而非直接忽略。
References
参考资料
- Quality Checks - Complete list of all quality checks with detection patterns
- Report Format - Quality report template and formatting guide
- Analyze Script - Automated analysis for linter-complementary checks
- uplifting-components-to-slds2 skill - How to fix linter violations
- applying-slds skill - Guide for building new components with correct patterns
- 质量检查 - 所有质量检查的完整列表与检测模式
- 报告格式 - 质量报告模板与格式指南
- 分析脚本 - 用于补充linter检查的自动化分析工具
- uplifting-components-to-slds2技能 - 如何修复linter违规问题
- applying-slds技能 - 正确构建新组件的指南