Introduction¶
When using LLMs to generate or modify React components, hardcoded colors (#ff0000) and deprecated component names are difficult for models to identify. Regex-based matching easily produces false positives on strings and comments, and renaming components may introduce runtime errors. The DSH plugin system supports AST parsing, making it well-suited for tasks like “static checking + diff generation.”
Plugin Overview¶
liuhange789/dsh-design-audit-to-code is a workflow plugin maintained by liuhange789. It parses JSX/TSX via Babel AST, replaces hardcoded hex colors with design tokens var(--color-*), and flags deprecated components. It returns a unified diff that can be piped directly into git apply or handed to a model to apply file changes. The tool itself does not write to disk.
Core Features¶
- AST-based audit: Uses
@babel/parser+@babel/traverseto parse JSX/TSX with no reliance on regex. - Hardcoded color auto-fix: Identifies
#rgb/#rgba/#rrggbb/#rrggbbaaliterals, maps them to semantic color families and shades, and generates a diff. - Deprecated component flagging: Reports only, does not auto-rename, to avoid introducing runtime errors due to props/semantic differences.
- Returns a unified diff: Replaces by source code range, preserves original quotes and indentation, and does not reformat the code.
- Speed: Parsing + audit of a typical component completes in < 200ms.
Installation & Activation¶
npm install @liuhange/dsh-design-audit-to-code
Add the plugin to your project configuration:
{
"dsh": {
"profile": {
"bundles": [
"@deepseek-ai/dsh-base",
"@deepseek-ai/dsh-headless",
"@liuhange/dsh-design-audit-to-code"
]
}
},
"dependencies": {
"@liuhange/dsh-design-audit-to-code": "0.1.0"
}
}
After restarting the profile, the tool audit_ui_code becomes available.
Typical Usage¶
You: Audit this button component and replace hardcoded colors with design tokens
Model: audit_ui_code code="<full source of Button.tsx>" filename="Button.tsx"
Example response:
### Found 4 standardization issues (3 safely auto-fixable)
- 🛠️ **Line 5** `'#ff0000'` → `'var(--color-danger)'`: Hardcoded color — replace with design token
- 🛠️ **Line 6** `'#00aa55'` → `'var(--color-success)'`: Hardcoded color — replace with design token
- 🛠️ **Line 10** `'#0b6bcb'` → `'var(--color-info)'`: Hardcoded color — replace with design token
- ⚠️ **Line 18** `LegacyButton` → `Button`: Deprecated component
### Auto-fix (Unified Diff)
```diff
--- Button.tsx
+++ Button.tsx
@@ -3,4 +3,4 @@
- color: '#ff0000',
+ color: 'var(--color-danger)',
```
Pass the diff to git apply, or let the model apply the changes directly to the file.
Use Cases & Caveats¶
- Ideal for automatically standardizing React component colors and component names within a DSH workflow, reducing manual review.
- Currently supports only JSX/TSX source strings; does not process
.css/.scss/.lessfiles or<style>tags. - Does not perform cross-file component name resolution; whether a same-named component is deprecated must be confirmed via repo-level linting.
- Does not modify non-color properties (spacing, font size, border radius, box shadow, etc.), as these values depend on the specific design system.
- The plugin runs under the current DSH process permissions; review the source code and license before installing.
Conclusion¶
This plugin uses AST-based auditing to convert hardcoded colors into design tokens and returns a directly applicable diff, making it well-suited for agent workflows that require design system standardization. See the plugin directory page for more details: https://www.skillhub.cn/plugins/liuhange789/dsh-design-audit-to-code