An automated design specification checking tool that compares Figma design tokens with actual code implementation to ensure development teams follow design standards.
- Design Specification Checking: Automatically compares Figma design tokens with CSS/HTML implementation
- Multi-source Support: Supports fetching code from GitHub repositories or local files
- Smart Matching: Supports intelligent matching of various design properties including colors, fonts, and spacing
- Slack Integration: Quick component compliance checking through Slack commands
- Detailed Reports: Generates detailed difference reports and compliance scores
- Tolerance Handling: Supports numerical tolerance and font inclusion matching
design-lint-bot/
βββ api/ # FastAPI backend service
β βββ main.py # Main API service
βββ core/ # Core functionality modules
β βββ differ.py # Design specification comparison logic
β βββ parser_css.py # CSS parser
β βββ parser_html.py # HTML parser
β βββ utils.py # Utility functions
βββ configs/ # Configuration files
β βββ mapping.json # Design token to CSS property mapping
β βββ mock_figma_tokens/ # Design tokens examples
βββ integrations/ # Third-party integrations
β βββ github_client.py # GitHub API client
βββ slack/ # Slack integration
β βββ app.py # Slack Bot application
βββ samples/ # Example files
β βββ button/ # Button component example
βββ storage/ # Storage directory
βββ artifacts/ # Check results archive
git clone <repository-url>
cd design-lint-bot
pip install fastapi uvicorn python-dotenv requests beautifulsoup4 cssutils slack-bolt
Create a .env
file and configure the following environment variables:
# GitHub Configuration
GITHUB_TOKEN=your_github_token
GITHUB_REPO=your-username/your-repo
GITHUB_DEFAULT_BRANCH=main
# Slack Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
SLACK_APP_LEVEL_TOKEN=xapp-your-app-level-token
# API Configuration
CHECK_API_URL=http://localhost:8000/check
cd api
uvicorn main:app --reload --port 8000
cd slack
python app.py
GET /health
POST /check
Content-Type: application/json
{
"component": "button",
"branch": "main",
"source": "auto"
}
Parameters:
component
: Component name (required)branch
: Git branch name (optional, defaults to configured default branch)source
: Data source (optional, auto/github/local)
Use the following commands in Slack:
/component button
/component button main
Configure the mapping between design tokens and CSS properties in configs/mapping.json
:
{
"color.background": ["background-color"],
"color.text": ["color"],
"color.border": ["border-color"],
"color.hoverBackground": [".:hover.background-color"],
"typography.fontFamily": ["font-family"],
"typography.fontSize": ["font-size"],
"typography.fontWeight": ["font-weight"],
"typography.lineHeight": ["line-height"],
"typography.letterSpacing": ["letter-spacing"],
"spacing.paddingTop": ["padding-top", "padding"],
"spacing.paddingRight": ["padding-right", "padding"],
"spacing.paddingBottom": ["padding-bottom", "padding"],
"spacing.paddingLeft": ["padding-left", "padding"],
"spacing.borderRadius": ["border-radius"]
}
Design tokens files should follow this format (refer to configs/mock_figma_tokens/button.json
):
{
"component": "button/primary",
"tokens": {
"color": {
"background": "#0D6EFD",
"text": "#FFFFFF",
"border": "#0D6EFD",
"hoverBackground": "#0B5ED7"
},
"typography": {
"fontFamily": "Inter",
"fontSize": 14,
"fontWeight": 600,
"lineHeight": 20,
"letterSpacing": 0
},
"spacing": {
"paddingTop": 8,
"paddingRight": 12,
"paddingBottom": 8,
"paddingLeft": 12,
"borderRadius": 6
}
}
}
- Supports HEX, RGB, RGBA formats
- Automatic normalization comparison (e.g.,
#fff
and#ffffff
are considered identical)
- Supports font family inclusion matching
- Code containing the design font is sufficient to pass
- Supports numerical tolerance (Β±1px)
- Automatic handling of
px
unit conversion
- Intelligent parsing of CSS padding shorthand
- Supports 1-4 value padding syntax
Check results include the following information:
{
"summary": {
"passed": 10,
"failed": 2,
"warnings": 0,
"score": 0.83
},
"diffs": [
{
"token": "color.background",
"design": "#0D6EFD",
"code": "#0D6EFD",
"match": true,
"severity": null
}
],
"component": "button",
"artifacts": {
"source": "github",
"branch": "main",
"mainSelector": ".btn-primary"
},
"generatedAt": "2024-01-01T12:00:00Z"
}
- Ensure you have the corresponding design tokens file:
configs/mock_figma_tokens/button.json
- Ensure you have the corresponding code files:
- GitHub:
src/components/button/button.css
andsrc/components/button/button.html
- Local:
samples/button/button.css
andsamples/button/button.html
- GitHub:
- Call the check API or use Slack commands
Issues and Pull Requests are welcome to improve this project!
MIT License