design-system-enforcer 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +249 -2
- package/dist/cli.cjs +2265 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2242 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +2198 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +129 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.js +2150 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Berserk Designs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,250 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Design System Enforcer (DSE) 🛡️
|
|
2
|
+
|
|
3
|
+
> **Zero-compromise Design System Enforcer, AST Linter & Primitive Scaffolder for React, Next.js, and Tailwind projects.**
|
|
4
|
+
|
|
5
|
+
Traditional linters (ESLint, Prettier, Stylelint) check code formatting and basic syntax, but they have zero awareness of **visual design systems**. They allow developers and AI agents to accidentally introduce:
|
|
6
|
+
- Random font sizes (`text-[13px]`, `text-xs`) that break vertical rhythm.
|
|
7
|
+
- Heavy font weights (`font-bold`, `font-semibold`) where medium (500) is standard.
|
|
8
|
+
- Raw HTML primitives (`<button>`, `<select>`, `<table>`) bypassing official design system components.
|
|
9
|
+
- Buttons styled like status badges with dangerous green/red colors (`NO_CHIP_COLORED_BUTTONS`).
|
|
10
|
+
- Double table borders, missing resize dividers, missing column header icons, or vertical text stacking in table cells.
|
|
11
|
+
- Raw ASCII arrows (`->`, `=>`, `→`) instead of standard icon components.
|
|
12
|
+
- Heavy backdrop blurs breaking crisp contrast standards.
|
|
13
|
+
|
|
14
|
+
**DSE stops design drift at the AST level**, crashing builds, pre-commit checks, or dev servers whenever a violation is committed.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ⚡ Quick Start
|
|
19
|
+
|
|
20
|
+
### 1. Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -D design-system-enforcer
|
|
24
|
+
# or
|
|
25
|
+
pnpm add -D design-system-enforcer
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Initialize in Your Project
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx dse init
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This interactive command:
|
|
35
|
+
- Generates `dse.config.js` with sensible defaults.
|
|
36
|
+
- Adds `"dse": "dse"` script to your `package.json`.
|
|
37
|
+
- Detects if you have primitives and offers to scaffold them.
|
|
38
|
+
|
|
39
|
+
### 3. Run the Check
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm run dse
|
|
43
|
+
# or
|
|
44
|
+
npx dse check
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🐍 Python Projects Support (Streamlit, Django, Flask, FastAPI)
|
|
50
|
+
|
|
51
|
+
DSE provides **first-class support for Python projects**! It automatically detects Python repositories (via `requirements.txt`, `pyproject.toml`, or `.streamlit`) and applies the `python` preset without requiring any manual configuration.
|
|
52
|
+
|
|
53
|
+
### What DSE checks in Python projects:
|
|
54
|
+
- **Embedded CSS in Python / Streamlit** (`st.markdown("""<style>...</style>""")`):
|
|
55
|
+
- Font sizes below standard 14px floor or exceeding 32px heading caps.
|
|
56
|
+
- Font weights exceeding 500 (`font-weight: 600`, `font-weight: bold`).
|
|
57
|
+
- Backdrop blur filter violations.
|
|
58
|
+
- Hardcoded `#hex` color literals.
|
|
59
|
+
- **Python UI copy and strings**:
|
|
60
|
+
- Raw text arrows (`->`, `<-`, `→`) in UI labels and buttons.
|
|
61
|
+
- *(Smart parsing: standard Python return type hints like `def foo() -> int:` are automatically preserved and never falsely flagged).*
|
|
62
|
+
- **Jinja2 and Django HTML templates** (`.html`, `.jinja`).
|
|
63
|
+
|
|
64
|
+
### How to use in any Python project:
|
|
65
|
+
|
|
66
|
+
#### Option A: Quick run with `npx` (No Node setup in your Python repo)
|
|
67
|
+
```bash
|
|
68
|
+
# In your Python project directory:
|
|
69
|
+
npx github:not-muzammil/Design-System-Enforcer check
|
|
70
|
+
|
|
71
|
+
# Or initialize a clean dse.config.json:
|
|
72
|
+
npx github:not-muzammil/Design-System-Enforcer init
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Option B: Python Pre-Commit Hook (Standard Python workflow)
|
|
76
|
+
Add DSE to your project's `.pre-commit-config.yaml`:
|
|
77
|
+
```yaml
|
|
78
|
+
repos:
|
|
79
|
+
- repo: https://github.com/not-muzammil/Design-System-Enforcer
|
|
80
|
+
rev: main
|
|
81
|
+
hooks:
|
|
82
|
+
- id: dse
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Whenever you or an AI agent run `git commit` or `pre-commit run --all-files`, DSE automatically validates your Python UI!
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 🎨 Theme Customization with AI Agents
|
|
90
|
+
|
|
91
|
+
When DSE scaffolds primitives and tokens (`npx dse scaffold`), all colors are powered by **standard CSS variables in HSL format**:
|
|
92
|
+
|
|
93
|
+
```css
|
|
94
|
+
/* src/app/globals.css */
|
|
95
|
+
:root {
|
|
96
|
+
--background: 0 0% 100%; /* White */
|
|
97
|
+
--foreground: 0 0% 11%; /* Neutral 900 */
|
|
98
|
+
--primary: 0 0% 9%; /* Dark neutral */
|
|
99
|
+
--border: 0 0% 90%; /* Border stroke */
|
|
100
|
+
--radius-md: 8px; /* Standard controls */
|
|
101
|
+
--radius-lg: 12px; /* Standard cards */
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Want to change the theme or palette?
|
|
106
|
+
Simply instruct your AI assistant:
|
|
107
|
+
> *"Change the primary brand color to ocean blue and use slightly rounded borders."*
|
|
108
|
+
|
|
109
|
+
The AI assistant simply updates the HSL values in `globals.css` or `tokens.ts`. **DSE protects the structure, typography, component hierarchies, and invariants**, while allowing 100% aesthetic flexibility!
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 🧩 Scaffolding Primitives (`dse add` & `dse scaffold`)
|
|
114
|
+
|
|
115
|
+
If your project doesn't have design system components yet, DSE can scaffold production-ready, accessible, 100% compliant primitives:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Scaffold all primitives + tokens + globals.css:
|
|
119
|
+
npx dse scaffold
|
|
120
|
+
|
|
121
|
+
# Or add individual components on demand:
|
|
122
|
+
npx dse add button chip input dropdown table tabs card checkbox skeleton
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Generated components include:
|
|
126
|
+
- `<Button />`: Standard 36px height (`h-[36px] min-h-[36px]`), 8px radius (`rounded-md`), strictly font-weight medium (500), standard neutral variants (`primary`, `outline`, `secondary`, `ghost`), bans chip colors.
|
|
127
|
+
- `<Chip />`: Standard 36px height, 8px radius status pills (`neutral`, `success`, `warning`, `error`).
|
|
128
|
+
- `<Input />`: Standard 36px height, 8px radius, standard 14px typography.
|
|
129
|
+
- `<Dropdown />`: Accessible custom dropdown replacing browser default `<select>`.
|
|
130
|
+
- `<Table />`: Suite with resizable columns, icon support in `<TableHead>`, single border (no double stroke), no divide-y, and windowed pagination.
|
|
131
|
+
- `<Tabs />`: Standard 36px height, 8px radius, with mandatory `items` prop.
|
|
132
|
+
- `<Checkbox />`: Strictly 20px (`size-5`) with 4px corner radius (`rounded-xs`).
|
|
133
|
+
- `<Card />`: Strictly 12px corner radius (`rounded-lg`) for content containers.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## ⚙️ Configuration (`dse.config.js`)
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
import { defineConfig } from "design-system-enforcer";
|
|
141
|
+
|
|
142
|
+
export default defineConfig({
|
|
143
|
+
preset: "berserk", // "berserk" | "recommended" | "minimal"
|
|
144
|
+
targetDir: "src",
|
|
145
|
+
include: ["**/*.{tsx,jsx,ts,js}"],
|
|
146
|
+
exclude: [
|
|
147
|
+
"**/node_modules/**",
|
|
148
|
+
"**/.next/**",
|
|
149
|
+
"src/components/ui/button.tsx", // exempt base primitive files
|
|
150
|
+
],
|
|
151
|
+
tokens: {
|
|
152
|
+
typography: {
|
|
153
|
+
minFontSize: "14px", // Bans text-xs, text-[12px]
|
|
154
|
+
maxFontSize: "32px", // Bans text-3xl, text-4xl
|
|
155
|
+
maxFontWeight: 500, // Bans font-semibold, font-bold
|
|
156
|
+
disallowArbitrarySizes: true, // Bans arbitrary bracket values: text-[13px]
|
|
157
|
+
disallowUppercase: true, // Bans uppercase and capitalize transforms
|
|
158
|
+
},
|
|
159
|
+
geometry: {
|
|
160
|
+
maxControlHeight: 36, // Caps buttons, tabs, inputs at 36px
|
|
161
|
+
allowedRadii: ["0px", "8px", "12px", "16px", "9999px"],
|
|
162
|
+
radiiExceptions: {
|
|
163
|
+
Checkbox: ["4px"], // 4px is strictly limited to checkboxes
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
colors: {
|
|
167
|
+
bannedColorFamilies: ["indigo", "purple", "rose", "cyan"],
|
|
168
|
+
disallowRawHex: true, // Bans inline #1C1C1C, rgb(), rgba()
|
|
169
|
+
disallowButtonChipColors: true,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
components: {
|
|
173
|
+
disallowRawHtml: {
|
|
174
|
+
button: { replaceWith: "Button", importFrom: "@/components/ui/button" },
|
|
175
|
+
select: { replaceWith: "Dropdown", importFrom: "@/components/ui/dropdown" },
|
|
176
|
+
table: { replaceWith: "Table", importFrom: "@/components/ui/table" },
|
|
177
|
+
},
|
|
178
|
+
disallowPseudoChips: true,
|
|
179
|
+
},
|
|
180
|
+
rules: {
|
|
181
|
+
"no-text-arrows": "error",
|
|
182
|
+
"no-backdrop-blur": "error",
|
|
183
|
+
"table-head-icon-required": "error",
|
|
184
|
+
"table-resizable-required": "error",
|
|
185
|
+
"table-no-cell-stacking": "error",
|
|
186
|
+
"table-windowed-pagination": "error",
|
|
187
|
+
"tabs-component-required": "error",
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 🤖 Teaching AI Assistants (`dse export-rules`)
|
|
195
|
+
|
|
196
|
+
Keep your AI agents (Cursor, Antigravity, Claude, Copilot) aligned with your design system automatically:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Export and sync markdown rules directly into AGENTS.md or .cursorrules:
|
|
200
|
+
npx dse export-rules -w AGENTS.md
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
This ensures AI coding agents know your typography limits, button rules, and component imports before generating code!
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 🚫 Inline Overrides & Ignore Comments
|
|
208
|
+
|
|
209
|
+
For rare, intentional exceptions:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
// Ignore a specific line:
|
|
213
|
+
// dse-ignore
|
|
214
|
+
<span className="text-[11px]">Legacy notice</span>
|
|
215
|
+
|
|
216
|
+
// Ignore button color rule:
|
|
217
|
+
// dse-ignore-button-color
|
|
218
|
+
<Button className="bg-red-600">Delete</Button>
|
|
219
|
+
|
|
220
|
+
// Ignore control height cap:
|
|
221
|
+
// dse-ignore-height
|
|
222
|
+
<Button className="h-12">Hero CTA</Button>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 🚀 Next.js Dev Runtime Integration
|
|
228
|
+
|
|
229
|
+
To catch violations immediately in development mode, call the programmatic API in your root layout:
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
// src/app/layout.tsx
|
|
233
|
+
if (process.env.NODE_ENV === "development") {
|
|
234
|
+
const { scanProject } = require("design-system-enforcer");
|
|
235
|
+
scanProject().then((result) => {
|
|
236
|
+
if (result.errorCount > 0) {
|
|
237
|
+
console.error(
|
|
238
|
+
\`[DSE] Found \${result.errorCount} design system violation(s)!\`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 📄 License
|
|
248
|
+
|
|
249
|
+
MIT © [Muzammil](https://github.com/not-muzammil)
|
|
2
250
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|