designsnitch 0.1.0 → 0.2.0
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.ko.md +426 -0
- package/README.md +289 -242
- package/bin/designsnitch.js +27 -1
- package/package.json +1 -1
- package/skills/designsnitch-check/SKILL.md +107 -0
- package/skills/designsnitch-eslint/SKILL.md +128 -0
- package/skills/designsnitch-hooks/SKILL.md +90 -0
- package/skills/designsnitch-palette/SKILL.md +140 -0
- package/skills/designsnitch-setup/SKILL.md +107 -0
- package/src/check.js +116 -32
- package/src/cli.js +64 -19
- package/src/colors.js +166 -0
- package/src/config.js +4 -1
- package/src/core/classes.js +14 -10
- package/src/core/css.js +54 -0
- package/src/core/tokens.js +0 -39
- package/src/engine.js +37 -0
- package/src/files.js +46 -0
- package/src/format.js +42 -3
- package/src/hook.js +100 -0
- package/src/index.js +4 -7
- package/src/install.js +95 -0
- package/src/rules/load-tokens.js +11 -4
- package/skills/designsnitch/SKILL.md +0 -107
- package/src/core/scale.js +0 -71
- package/src/rules/scale-labels.js +0 -6
- package/src/rules/scale-unknown.js +0 -43
- package/src/rules/scale-use-token.js +0 -38
package/README.md
CHANGED
|
@@ -1,42 +1,104 @@
|
|
|
1
1
|
# designsnitch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [한국어](./README.ko.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
designsnitch helps keep a UI codebase manageable and consistent when the project has no design system, or has one in name only. It is built for code written by AI agents, which produce plausible UI quickly and scatter colors, spacing and components across screens as they go.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
It works inside the code, with no designer or Figma file required.
|
|
8
|
+
|
|
9
|
+
1. **Establish a standard.** It collects the values the code already uses so you can turn them into tokens.
|
|
10
|
+
2. **Keep to it.** It checks new code against that standard and tells you what to use instead.
|
|
11
|
+
3. **Clean up.** It helps bring code that has already drifted back to the standard.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Deciding what the standard is stays with the developer. The tool's job is to bring what is needed to make that decision.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
It has four parts.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
| Part | What it is for |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| CLI | A tool for the AI agent. It collects the colors in use, checks code, and says what to do with each violation. |
|
|
20
|
+
| Agent skills | Tell an AI agent how to set the project up, when to run the CLI, what to fix, and what to ask a person about. |
|
|
21
|
+
| ESLint plugin | Blocks and warns. The same rules show up as errors and warnings in the editor and in the lint step. |
|
|
22
|
+
| Agent hook | Blocks while the code is being written. The agent is told about errors after each edit and cannot finish while errors it can fix remain. |
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
It supports **React/Next.js projects that use Tailwind CSS v4**.
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
| --- | --- | --- |
|
|
23
|
-
| `color-use-token` | 오류 | 토큰이 있는 색을 hex로 씀 |
|
|
24
|
-
| `color-unknown` | 경고 | 토큰이 없는 hex |
|
|
25
|
-
| `scale-use-token` | 오류 | 스케일에 있는 간격, 폰트 크기, radius를 임의 값으로 씀 |
|
|
26
|
-
| `scale-unknown` | 경고 | 스케일에 없는 간격, 폰트 크기, radius |
|
|
27
|
-
| `use-ds-component` | 오류 | 디자인 시스템 컴포넌트가 있는 raw 태그를 디자인 시스템 경로 밖에서 씀 |
|
|
26
|
+
> **Status:** MVP (0.2.x). CLI messages are in Korean for now. The JSON output carries the same information in language-neutral fields.
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
## Getting started
|
|
30
29
|
|
|
31
30
|
```sh
|
|
32
31
|
npm install --save-dev designsnitch
|
|
32
|
+
npx designsnitch install
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Node.js 22
|
|
35
|
+
The second command copies the agent skills into `.claude/skills` and registers the agent hook in `.claude/settings.json`. It targets Claude Code for now. Node.js 22 or later is required.
|
|
36
|
+
|
|
37
|
+
Then ask your coding agent:
|
|
38
|
+
|
|
39
|
+
> Set up designsnitch in this project.
|
|
40
|
+
|
|
41
|
+
The agent follows the `designsnitch-setup` skill and does the rest.
|
|
42
|
+
|
|
43
|
+
1. It checks that the project is supported.
|
|
44
|
+
2. It finds the token CSS and the shared component directory, and writes `designsnitch.config.json`.
|
|
45
|
+
3. If the project has no color tokens, it collects the colors the code uses and proposes tokens. Nothing is written until you approve.
|
|
46
|
+
4. It puts the rules into ESLint, installing ESLint if the project has none.
|
|
47
|
+
5. It shows you what it chose and what the first check found.
|
|
48
|
+
|
|
49
|
+
From then on:
|
|
50
|
+
|
|
51
|
+
- The agent is told about errors right after it edits a file, and cannot finish while errors it can fix remain.
|
|
52
|
+
- Errors fail the lint step, and show up in the editor.
|
|
53
|
+
- `npx designsnitch check` reports where the code stands at any time.
|
|
54
|
+
|
|
55
|
+
To do any of this without an agent, see [Setting up by hand](#setting-up-by-hand).
|
|
56
|
+
|
|
57
|
+
## Why
|
|
58
|
+
|
|
59
|
+
When there is no standard, every screen makes its own choices. An AI agent makes them quickly and plausibly, and they add up.
|
|
60
|
+
|
|
61
|
+
- The same blue is `#3B82F6` on one screen and `#3B82F5` on another.
|
|
62
|
+
- A color is written by hand in a hundred places, so changing the brand color or adding dark mode means finding every one of them.
|
|
63
|
+
- Each screen builds its own button from `<button>`, each a little different, some without a focus style.
|
|
64
|
+
|
|
65
|
+
The result is a codebase that is hard to manage and a product that is hard to keep consistent. And with no standard, there is nothing to check new code against. designsnitch helps you set a standard from what the code already does, and then holds new code to it.
|
|
66
|
+
|
|
67
|
+
## What it catches
|
|
36
68
|
|
|
37
|
-
|
|
69
|
+
Severity follows one rule.
|
|
38
70
|
|
|
39
|
-
|
|
71
|
+
| Severity | Meaning |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| **Error** | The design system has a token or component for this, and the code did not use it. Even if the screen looks the same today, this code will not follow when the design system changes. |
|
|
74
|
+
| **Warning** | The design system has no matching token. A person has to decide whether a new value is really needed or it is a mistake. |
|
|
75
|
+
|
|
76
|
+
| Rule | Severity | What it catches |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `color-use-token` | Error | A hex color that has a token, written as an arbitrary value (`bg-[#3B82F6]`) or in a CSS declaration (`color: #3B82F6`) |
|
|
79
|
+
| `color-unknown` | Warning | A hex color with no matching token |
|
|
80
|
+
| `use-ds-component` | Error | A raw tag such as `<button>` used outside the design system directory, when a shared component replaces it |
|
|
81
|
+
|
|
82
|
+
Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in CSS files.
|
|
83
|
+
|
|
84
|
+
## Commands
|
|
85
|
+
|
|
86
|
+
| Command | What it does |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `designsnitch install` | Copies the skills and registers the agent hook in the project. |
|
|
89
|
+
| `designsnitch colors` | Lists the colors the code uses. Works without a config file. |
|
|
90
|
+
| `designsnitch check` | Checks code against the standard and says what to do with each violation. |
|
|
91
|
+
| `designsnitch hook` | Called from the agent's hook. Checks the files the agent just changed. |
|
|
92
|
+
|
|
93
|
+
`check` and `colors` take paths, `--format json`, and `--config <file>`.
|
|
94
|
+
|
|
95
|
+
## Setting up by hand
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
npm install --save-dev designsnitch
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Create `designsnitch.config.json` in the project root.
|
|
40
102
|
|
|
41
103
|
```json
|
|
42
104
|
{
|
|
@@ -52,71 +114,113 @@ Node.js 22 이상이 필요합니다.
|
|
|
52
114
|
}
|
|
53
115
|
```
|
|
54
116
|
|
|
55
|
-
|
|
117
|
+
Then run the check.
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
npx designsnitch check # the whole project
|
|
121
|
+
npx designsnitch check src/PayButton.tsx # some files only
|
|
122
|
+
npx designsnitch check --format json # for CI and AI agents
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The fields are described in [Configuration](#configuration). To block violations, add the rules to [ESLint](#eslint) and register the [agent hook](#agent-hook).
|
|
126
|
+
|
|
127
|
+
## Starting without tokens
|
|
128
|
+
|
|
129
|
+
Some projects have no color tokens yet: colors are written straight into the code. `designsnitch colors` lists the colors the code uses, so you can turn them into tokens. It works without a config file.
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
npx designsnitch colors
|
|
133
|
+
npx designsnitch colors --format json
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
코드에서 쓰는 색: hex 5개, 기본 팔레트 1개 (사용 10곳, 파일 1개 검사)
|
|
138
|
+
|
|
139
|
+
hex 색
|
|
140
|
+
#3a11d8 3곳 파일 1개 bg 2, 문자열 1
|
|
141
|
+
#484646 2곳 파일 1개 text 2
|
|
142
|
+
#ffffff 2곳 파일 1개 bg 1, text 1
|
|
143
|
+
#484645 1곳 파일 1개 text 1
|
|
144
|
+
#e2e1e5 1곳 파일 1개 border 1
|
|
145
|
+
|
|
146
|
+
Tailwind 기본 팔레트
|
|
147
|
+
gray-700 1곳 파일 1개 text 1
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Part of the output | Meaning |
|
|
56
151
|
| --- | --- |
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
152
|
+
| `hex 색` (hex colors) | Hex colors, most used first, with the number of uses (`곳`) and files (`파일`). |
|
|
153
|
+
| `bg 2`, `text 1` | Uses per Tailwind utility. `bg-[#3a11d8]` counts under `bg`. |
|
|
154
|
+
| `문자열 1` (strings) | Strings that are a hex color on their own, such as inline styles and chart options. |
|
|
155
|
+
| `CSS 2` | Uses in CSS declarations. The JSON output breaks these down by property. |
|
|
156
|
+
| `Tailwind 기본 팔레트` (default palette) | Colors from Tailwind's default palette used by name, such as `text-gray-700`. |
|
|
157
|
+
|
|
158
|
+
When a config file exists, each color also shows the tokens that already have that value (`토큰: --color-brand`), or `토큰 없음` when there is none. The JSON output has the same data plus a few example locations per color.
|
|
60
159
|
|
|
61
|
-
`
|
|
160
|
+
The [`designsnitch-palette` skill](#agent-skills) uses this output to propose tokens, and writes them after you approve.
|
|
62
161
|
|
|
63
|
-
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
| Field | Description |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `tokens` | The CSS file that defines the tokens. Required. |
|
|
167
|
+
| `components.path` | The directory that holds the design system components. Raw tags are allowed inside it. |
|
|
168
|
+
| `components.replaces` | Raw tags and the components that replace them. Use an array when several components replace one tag. |
|
|
64
169
|
|
|
65
|
-
|
|
170
|
+
Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
|
|
171
|
+
|
|
172
|
+
This is what is read from the token CSS.
|
|
173
|
+
|
|
174
|
+
| Variable | Used for | When missing |
|
|
66
175
|
| --- | --- | --- |
|
|
67
|
-
| `--color-*` |
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| `--text-*` | 폰트 크기 | 폰트 크기를 검사하지 않습니다 |
|
|
176
|
+
| `--color-*` | Colors. The value must be a hex color, or a `var()` that leads to one. | Every hex color becomes a warning |
|
|
177
|
+
|
|
178
|
+
Both of these shapes work.
|
|
71
179
|
|
|
72
180
|
```css
|
|
181
|
+
/* Values directly in @theme */
|
|
73
182
|
@theme {
|
|
74
183
|
--color-primary-500: #3B82F6;
|
|
75
184
|
--color-surface: #ffffff;
|
|
76
|
-
--radius-sm: 0.25rem;
|
|
77
|
-
--radius-md: 0.375rem;
|
|
78
|
-
--text-sm: 0.875rem;
|
|
79
|
-
--text-base: 1rem;
|
|
80
185
|
}
|
|
81
|
-
```
|
|
82
186
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
187
|
+
/* Values in :root, referenced from @theme */
|
|
188
|
+
:root {
|
|
189
|
+
--primary-500: #3B82F6;
|
|
190
|
+
}
|
|
191
|
+
@theme {
|
|
192
|
+
--color-primary-500: var(--primary-500);
|
|
193
|
+
}
|
|
89
194
|
```
|
|
90
195
|
|
|
196
|
+
## Output
|
|
197
|
+
|
|
91
198
|
```
|
|
92
|
-
디자인 시스템: 색 토큰 2개,
|
|
199
|
+
디자인 시스템: 색 토큰 2개, 컴포넌트 2개
|
|
93
200
|
|
|
94
201
|
src/PayButton.tsx
|
|
95
202
|
5:6 오류 <button> 대신 디자인 시스템 컴포넌트를 사용하세요: Button (./components/ui) (use-ds-component)
|
|
96
|
-
7:10 오류 rounded-[6px]의 값은 radius 토큰에 있습니다. 대신 사용: rounded-md (scale-use-token)
|
|
97
|
-
7:24 오류 px-[16px]의 값은 간격 스케일에 있습니다. 대신 사용: px-4 (scale-use-token)
|
|
98
|
-
7:34 경고 py-[7px]의 값은 간격 스케일에 없습니다. 가까운 값: py-1.5 (6px), py-2 (8px) (scale-unknown)
|
|
99
203
|
7:55 오류 bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500 (color-use-token)
|
|
100
204
|
8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
|
|
101
205
|
|
|
102
|
-
오류
|
|
206
|
+
오류 2개, 경고 1개 (파일 3개 검사)
|
|
207
|
+
바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건
|
|
103
208
|
```
|
|
104
209
|
|
|
105
|
-
|
|
210
|
+
The first line shows how many tokens and components were read from the config. A wrong path shows up here as a zero. If no color token could be read, a line starting with `주의:` (notice) explains why. `오류` means error and `경고` means warning. The last line says how many violations can be replaced right away (`바로 바꿀 수 있는 것`) and how many need a person's decision (`사람이 정해야 하는 것`).
|
|
106
211
|
|
|
107
|
-
`--format json
|
|
212
|
+
`--format json` prints the same result as structured data.
|
|
108
213
|
|
|
109
214
|
```json
|
|
110
215
|
{
|
|
111
|
-
"designSystem": {
|
|
112
|
-
"colorTokens": 2,
|
|
113
|
-
"radiusTokens": 2,
|
|
114
|
-
"textTokens": 2,
|
|
115
|
-
"components": 2,
|
|
116
|
-
"replacedTags": 2
|
|
117
|
-
},
|
|
216
|
+
"designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
|
|
118
217
|
"problems": [],
|
|
119
|
-
"
|
|
218
|
+
"next": [
|
|
219
|
+
"action이 replace인 2건은 found를 candidates의 값으로 바꾸세요.",
|
|
220
|
+
"action이 ask인 1건은 바꾸지 말고 사용자에게 물으세요. ...",
|
|
221
|
+
"고친 뒤 같은 명령을 다시 실행하세요."
|
|
222
|
+
],
|
|
223
|
+
"summary": { "files": 3, "errors": 2, "warnings": 1 },
|
|
120
224
|
"violations": [
|
|
121
225
|
{
|
|
122
226
|
"file": "src/PayButton.tsx",
|
|
@@ -128,252 +232,195 @@ src/PayButton.tsx
|
|
|
128
232
|
"severity": "error",
|
|
129
233
|
"message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
|
|
130
234
|
"found": "bg-[#3B82F6]",
|
|
131
|
-
"candidates": ["bg-primary-500"]
|
|
235
|
+
"candidates": ["bg-primary-500"],
|
|
236
|
+
"action": "replace"
|
|
132
237
|
}
|
|
133
238
|
]
|
|
134
239
|
}
|
|
135
240
|
```
|
|
136
241
|
|
|
137
|
-
|
|
|
242
|
+
| Field | Content |
|
|
138
243
|
| --- | --- |
|
|
139
|
-
| `designSystem` |
|
|
140
|
-
| `problems` |
|
|
141
|
-
| `violations[].found` |
|
|
142
|
-
| `violations[].candidates` |
|
|
143
|
-
|
|
144
|
-
|
|
|
244
|
+
| `designSystem` | How many tokens and components were read from the config |
|
|
245
|
+
| `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
|
|
246
|
+
| `violations[].found` | The offending piece of code |
|
|
247
|
+
| `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
|
|
248
|
+
| `violations[].action` | How to handle the violation. `replace`: an error with exactly one candidate, so replace `found` with it. `ask`: a person has to decide (several candidates, or a color with no token). `repair`: the file could not be parsed. |
|
|
249
|
+
| `next` | What an agent should do with this result, in order |
|
|
250
|
+
|
|
251
|
+
| Exit code | Meaning |
|
|
145
252
|
| --- | --- |
|
|
146
|
-
| 0 |
|
|
147
|
-
| 1 |
|
|
148
|
-
| 2 |
|
|
253
|
+
| 0 | No errors (warnings alone still exit 0) |
|
|
254
|
+
| 1 | Errors found |
|
|
255
|
+
| 2 | Could not run (missing config file, token CSS or component directory, or bad arguments) |
|
|
149
256
|
|
|
150
|
-
|
|
257
|
+
The check does not depend on the project's ESLint config. It reads `.js`, `.jsx`, `.ts`, `.tsx` and `.css` files and skips `node_modules`, `.next`, `dist`, `build`, `out` and `coverage`.
|
|
151
258
|
|
|
152
|
-
|
|
259
|
+
## Exceptions
|
|
153
260
|
|
|
154
|
-
|
|
261
|
+
Mark intentional exceptions with a comment.
|
|
155
262
|
|
|
156
263
|
```tsx
|
|
157
|
-
{/* eslint-disable-next-line designsnitch/color-unknown --
|
|
158
|
-
<p className="text-[#FF00AA]"
|
|
264
|
+
{/* eslint-disable-next-line designsnitch/color-unknown -- campaign-only color */}
|
|
265
|
+
<p className="text-[#FF00AA]">Campaign</p>
|
|
159
266
|
```
|
|
160
267
|
|
|
161
|
-
|
|
268
|
+
In a CSS file, put this comment on the line before the declaration.
|
|
162
269
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
270
|
+
```css
|
|
271
|
+
.campaign {
|
|
272
|
+
/* designsnitch-disable-next-line -- campaign-only color */
|
|
273
|
+
color: #FF00AA;
|
|
274
|
+
}
|
|
168
275
|
```
|
|
169
276
|
|
|
170
|
-
|
|
277
|
+
## Agent skills
|
|
278
|
+
|
|
279
|
+
`npx designsnitch install` copies the skills into `.claude/skills`. Run it again after upgrading the package to get the current versions. The skills are in the `skills/` directory of the package if you want to copy them somewhere else.
|
|
171
280
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
281
|
+
Each skill does one job.
|
|
282
|
+
|
|
283
|
+
| Skill | When the agent uses it | What it does |
|
|
284
|
+
| --- | --- | --- |
|
|
285
|
+
| `designsnitch-check` | After changing UI code | Runs the check, replaces what can be replaced, and asks a person about the rest with the facts needed to decide. |
|
|
286
|
+
| `designsnitch-setup` | When the config file is missing | Finds the token CSS and the shared component directory in the codebase, writes `designsnitch.config.json`, verifies what was read, and then wires the ESLint plugin and the agent hook. |
|
|
287
|
+
| `designsnitch-palette` | When the project has no color tokens | Collects the colors in use with `designsnitch colors`, proposes tokens, and writes them after a person approves. |
|
|
288
|
+
| `designsnitch-hooks` | As part of setup | Registers `designsnitch hook` with the coding agent, so it is told about errors after each edit and cannot finish while fixable errors remain. |
|
|
289
|
+
| `designsnitch-eslint` | As part of setup | Puts the rules into the project's ESLint, and installs ESLint if the project has none. Asks first if the project already has errors. |
|
|
177
290
|
|
|
178
|
-
|
|
291
|
+
The skills share a few rules. The agent does not pick one of several candidates on its own, does not silence a rule to make the check pass, and does not change an existing config file or token without asking. The config file and the tokens are the standard the code is judged against.
|
|
179
292
|
|
|
180
|
-
|
|
293
|
+
## ESLint
|
|
181
294
|
|
|
182
|
-
|
|
295
|
+
The same rules can run inside your project's ESLint, so violations show up in the editor and in the lint step you already have. The ESLint config reads `designsnitch.config.json`, so the standard is written in one place.
|
|
183
296
|
|
|
184
297
|
```js
|
|
185
298
|
// eslint.config.js
|
|
186
299
|
import designsnitch from "designsnitch";
|
|
300
|
+
import designSystem from "./designsnitch.config.json" with { type: "json" };
|
|
187
301
|
|
|
188
302
|
export default [
|
|
189
|
-
|
|
303
|
+
// ...your existing config
|
|
190
304
|
{
|
|
191
|
-
|
|
192
|
-
|
|
305
|
+
files: ["**/*.{js,jsx,ts,tsx}"],
|
|
306
|
+
plugins: { designsnitch },
|
|
307
|
+
settings: { designsnitch: designSystem },
|
|
308
|
+
rules: {
|
|
309
|
+
// error: the design system has a token or component for this, and it was not used
|
|
310
|
+
"designsnitch/color-use-token": "error",
|
|
311
|
+
"designsnitch/use-ds-component": "error",
|
|
312
|
+
// warn: the value is not in the design system, so a person has to decide
|
|
313
|
+
"designsnitch/color-unknown": "warn",
|
|
193
314
|
},
|
|
194
315
|
},
|
|
195
316
|
];
|
|
196
317
|
```
|
|
197
318
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
- **검사하는 곳:** 코드 안의 문자열과 템플릿 리터럴입니다. `className`뿐 아니라 `cn()`, `clsx()`, `cva()`의 인자도 잡힙니다. 주석은 보지 않습니다.
|
|
201
|
-
- **간격:** padding, margin, gap, space 유틸리티만 봅니다. `w-[320px]` 같은 크기 유틸리티는 보지 않습니다.
|
|
202
|
-
- **간격 스케일:** 간격 단위의 0.5배수(`p-0.5`, `p-1.5`, `p-4`)와 `p-px`를 스케일로 봅니다.
|
|
203
|
-
- **단위:** `px`와 `rem`만 봅니다. `1rem`은 16px로 계산합니다.
|
|
204
|
-
|
|
205
|
-
### 아직 안 되는 것
|
|
206
|
-
|
|
207
|
-
- hex가 아닌 색(`rgb()`, `hsl()`, `oklch()`)
|
|
208
|
-
- Tailwind 기본 테마의 값. 프로젝트의 토큰 CSS에 적힌 값만 읽습니다.
|
|
209
|
-
- 색의 가장 가까운 토큰 제시
|
|
210
|
-
- 어느 테마의 값인지 알려주기. 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 토큰의 값으로 보지만, 어느 테마인지는 구분하지 않습니다.
|
|
211
|
-
- 인라인 스타일
|
|
212
|
-
- 직접 만든 컴포넌트와 디자인 시스템 컴포넌트의 스타일 비교
|
|
213
|
-
- 스킬을 설치해 주는 명령
|
|
214
|
-
|
|
215
|
-
### 개발
|
|
216
|
-
|
|
217
|
-
```sh
|
|
218
|
-
npm install
|
|
219
|
-
npm test
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## 왜 필요한가
|
|
223
|
-
|
|
224
|
-
AI 에이전트가 만든 UI는 얼핏 보면 그럴듯하지만, 자세히 보면 조금씩 틀려 있는 경우가 많습니다.
|
|
225
|
-
|
|
226
|
-
- primary 색을 토큰 대신 `bg-[#3B82F6]`으로 박아 둬서, 다크 모드로 바꾸면 그 부분만 색이 그대로 남습니다.
|
|
227
|
-
- 버튼 색이 primary와 거의 같지만 미묘하게 다릅니다.
|
|
228
|
-
- 간격이 `p-4`여야 할 곳에 `p-[15px]`나 `p-[18px]`가 들어가 있습니다.
|
|
229
|
-
- 디자인 시스템에 Button이 있는데 `<button>`으로 새로 만들어서, 높이가 조금 낮거나 focus 스타일이 없습니다.
|
|
319
|
+
The same set of rules is available as `designsnitch.configs.recommended`. In a project that already has many violations, the error-level rules will make the existing lint step fail, so run `designsnitch check` first to see how many there are. Replacement candidates appear as ESLint suggestions, which editors show as quick fixes. CSS files are checked by the CLI only, not through ESLint.
|
|
230
320
|
|
|
231
|
-
|
|
321
|
+
## Blocking violations
|
|
232
322
|
|
|
233
|
-
|
|
323
|
+
The CLI and the skills put an AI agent in a position to do the right thing. Blocking is done in two other places.
|
|
234
324
|
|
|
235
|
-
|
|
|
236
|
-
| --- | --- |
|
|
237
|
-
| **오류** | 디자인 시스템에 쓸 토큰이나 컴포넌트가 있는데 쓰지 않았습니다. 지금 화면이 같아 보여도, 디자인 시스템이 바뀌면 이 코드만 따라가지 않습니다. |
|
|
238
|
-
| **경고** | 디자인 시스템에 맞는 토큰이 없습니다. 새 값이 정말 필요한 건지 실수인지 사람이 판단해야 합니다. |
|
|
239
|
-
|
|
240
|
-
## 감지 대상 한눈에 보기
|
|
241
|
-
|
|
242
|
-
| 대상 | 오류 | 경고 |
|
|
325
|
+
| Where | When it catches a violation | How |
|
|
243
326
|
| --- | --- | --- |
|
|
244
|
-
|
|
|
245
|
-
|
|
|
246
|
-
| 컴포넌트 | 디자인 시스템 컴포넌트가 있는데 raw 태그나 직접 만든 컴포넌트를 씀 | 없음 |
|
|
247
|
-
|
|
248
|
-
## 검사하는 곳
|
|
249
|
-
|
|
250
|
-
Tailwind 프로젝트에서 값을 직접 쓰는 곳은 주로 두 군데입니다.
|
|
251
|
-
|
|
252
|
-
- **임의 값 클래스:** `bg-[#3B82F6]`, `p-[15px]`, `rounded-[6px]`, `text-[13px]`처럼 대괄호 안에 값을 직접 쓴 클래스입니다. `className` 문자열과 `cn()`, `clsx()`, `cva()` 같은 함수의 인자를 봅니다.
|
|
253
|
-
- **인라인 스타일:** `style={{ color: "#3B82F6", padding: 16 }}`
|
|
254
|
-
|
|
255
|
-
이 문서에서는 편의상 hex라고 부르지만, `rgb()`, `hsl()`, `oklch()`로 쓴 색도 같은 색으로 변환해서 비교합니다.
|
|
256
|
-
|
|
257
|
-
## 감지 대상
|
|
327
|
+
| ESLint plugin | In the editor and in the lint step | Errors fail the lint step. Run lint in CI and require it to pass, and nothing with an error can be merged. |
|
|
328
|
+
| Agent hook | While the agent is writing code | `designsnitch hook` runs after each edit and before the agent finishes. |
|
|
258
329
|
|
|
259
|
-
###
|
|
330
|
+
### Agent hook
|
|
260
331
|
|
|
261
|
-
|
|
332
|
+
A skill is advice that an agent may not follow. A hook is run by the agent's runtime every time. `npx designsnitch install` registers it for Claude Code. This is what it adds to `.claude/settings.json`.
|
|
262
333
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
334
|
+
```json
|
|
335
|
+
{
|
|
336
|
+
"hooks": {
|
|
337
|
+
"PostToolUse": [
|
|
338
|
+
{
|
|
339
|
+
"matcher": "Edit|Write|MultiEdit",
|
|
340
|
+
"hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
|
|
341
|
+
}
|
|
342
|
+
],
|
|
343
|
+
"Stop": [
|
|
344
|
+
{
|
|
345
|
+
"hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
}
|
|
278
350
|
```
|
|
279
351
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
팔레트에 없는 색입니다. 팔레트 색과 아주 가까우면 근사값이나 오타일 가능성이 크므로, 가장 가까운 토큰을 함께 제시합니다.
|
|
352
|
+
`designsnitch hook` checks only the files the agent just changed.
|
|
283
353
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
가장 가까운 토큰: --color-primary-500 (#3B82F6) → bg-primary-500
|
|
288
|
-
```
|
|
354
|
+
- After an edit, if the file has errors, the agent receives them along with what to do next.
|
|
355
|
+
- When the agent is about to finish, it is stopped if errors it can fix itself remain. Errors that need a person's decision do not stop it, because it has to stop in order to ask.
|
|
356
|
+
- Warnings never block, and violations in files the agent did not touch are left alone.
|
|
289
357
|
|
|
290
|
-
|
|
358
|
+
The command reads an optional JSON object from stdin (`tool_input.file_path`, `hook_event_name`, `stop_hook_active`), exits with 2 and writes to stderr when it blocks, and falls back to the files git reports as changed when no file is given. Other agents with command hooks that follow these conventions can use it too. The `designsnitch-hooks` skill sets this up.
|
|
291
359
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
```
|
|
295
|
-
src/features/checkout/Summary.tsx:30:5 오류
|
|
296
|
-
p-[16px] 는 간격 스케일에 있는 값입니다.
|
|
297
|
-
→ p-4 를 사용하세요.
|
|
298
|
-
```
|
|
360
|
+
### Tailwind's default palette
|
|
299
361
|
|
|
300
|
-
|
|
362
|
+
designsnitch does not flag default palette classes such as `bg-blue-500`. If the project should only use its own tokens, Tailwind v4 can remove the default palette, and then those classes stop working at all.
|
|
301
363
|
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
364
|
+
```css
|
|
365
|
+
@theme {
|
|
366
|
+
--color-*: initial;
|
|
367
|
+
--color-primary-500: #3B82F6;
|
|
368
|
+
}
|
|
306
369
|
```
|
|
307
370
|
|
|
308
|
-
|
|
371
|
+
## Scope
|
|
309
372
|
|
|
310
|
-
|
|
373
|
+
- **Where it looks in JS and TS:** string literals and template literals. This covers `className` and the arguments of `cn()`, `clsx()` and `cva()`. Comments are ignored.
|
|
374
|
+
- **Where it looks in CSS:** hex colors in declaration values, in `.css` files including CSS Modules. Declarations that define a variable (`--name: ...`) are skipped, since that is where tokens are defined. Only colors are checked in CSS for now.
|
|
375
|
+
- **Themes:** when a token has different values per theme, all of them count as that token's value.
|
|
376
|
+
- **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
|
|
311
377
|
|
|
312
|
-
|
|
378
|
+
### Not supported yet
|
|
313
379
|
|
|
314
|
-
-
|
|
315
|
-
-
|
|
380
|
+
- Colors that are not hex (`rgb()`, `hsl()`, `oklch()`)
|
|
381
|
+
- Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
|
|
382
|
+
- Tailwind v3 (`tailwind.config.js`)
|
|
383
|
+
- The nearest token for a color that has none
|
|
384
|
+
- Inline styles
|
|
385
|
+
- SCSS and other preprocessors
|
|
386
|
+
- Spacing, font size and radius. They were left out of this version on purpose.
|
|
387
|
+
- Classes inside `@apply`
|
|
388
|
+
- Comparing a hand-made component's styles with the design system component
|
|
389
|
+
- Installing the skills and the hook for agents other than Claude Code
|
|
316
390
|
|
|
317
|
-
|
|
391
|
+
Comparing a screen with a design file such as Figma is out of scope. The standard is the design system alone.
|
|
318
392
|
|
|
319
|
-
|
|
320
|
-
- hover, focus, disabled 같은 상태 스타일이 빠졌는지
|
|
393
|
+
## How it works
|
|
321
394
|
|
|
322
|
-
|
|
323
|
-
src/features/checkout/ConfirmModal.tsx:5:10 오류
|
|
324
|
-
raw <dialog> 를 디자인 시스템 밖에서 사용했습니다.
|
|
325
|
-
→ @/components/ui/Dialog 를 사용하세요.
|
|
326
|
-
```
|
|
395
|
+
The split between a skill and a tool that does the work follows Modern Web Guidance by the Chrome team. The CLI makes the verdicts, and the skills only decide when the agent calls the CLI and what it does with the result. People and AI use the same rules and the same results.
|
|
327
396
|
|
|
328
|
-
|
|
329
|
-
src/features/checkout/ConfirmButton.tsx:4:10 오류
|
|
330
|
-
디자인 시스템 Button 과 역할이 같은 컴포넌트입니다.
|
|
331
|
-
- height 36px (Button: 40px)
|
|
332
|
-
- :focus-visible 스타일 없음
|
|
333
|
-
→ @/components/ui/Button 을 사용하세요.
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
> 이 절의 출력은 목표 동작을 설명하는 예시입니다. 실제 출력은 [실행](#실행)을 보세요.
|
|
337
|
-
|
|
338
|
-
## 설계
|
|
339
|
-
|
|
340
|
-
### 구조
|
|
341
|
-
|
|
342
|
-
스킬과 실행 도구를 나누는 방식은 Chrome 팀의 Modern Web Guidance를 참고했습니다. 판정은 CLI가 하고, 스킬은 에이전트가 언제 CLI를 부르고 결과를 어떻게 다룰지만 정합니다. 사람과 AI가 같은 규칙과 같은 결과를 씁니다.
|
|
343
|
-
|
|
344
|
-
| 층 | 위치 | 하는 일 |
|
|
397
|
+
| Layer | Location | What it does |
|
|
345
398
|
| --- | --- | --- |
|
|
346
|
-
|
|
|
347
|
-
|
|
|
348
|
-
|
|
|
349
|
-
| CLI | `src/cli.js` |
|
|
350
|
-
|
|
|
351
|
-
|
|
352
|
-
오류와 경고는 별도 규칙으로 나눕니다. 대체 후보는 ESLint의 제안(suggestion)으로 보고하므로, 에디터에서는 빠른 수정으로 보이고 CLI의 JSON에는 `candidates`로 나옵니다. 후보가 하나여도 자동 수정은 하지 않습니다.
|
|
399
|
+
| Core | `src/core` | Reads the token CSS into a value-to-token table, and finds color classes and values in strings and CSS. Does not depend on ESLint. |
|
|
400
|
+
| Rules | `src/rules` | Find strings and JSX tags in the AST, ask the core, and report violations with candidates. Written as ESLint rules. |
|
|
401
|
+
| Check engine | `src/check.js` | Runs the rules on a project and turns the results into a list of violations. Uses ESLint internally to parse and walk the code. |
|
|
402
|
+
| CLI | `src/cli.js` | Reads arguments and the config file, calls the engine, and prints the result. |
|
|
403
|
+
| Hook | `src/hook.js` | Checks the files an agent just changed and decides whether to block. |
|
|
404
|
+
| Skills | `skills/` | Instructions for the agent, one skill per job. |
|
|
353
405
|
|
|
354
|
-
|
|
406
|
+
## Development
|
|
355
407
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
5. 스킬 설치 명령
|
|
408
|
+
```sh
|
|
409
|
+
npm install
|
|
410
|
+
npm test
|
|
411
|
+
```
|
|
361
412
|
|
|
362
|
-
|
|
413
|
+
### Releasing
|
|
363
414
|
|
|
364
|
-
|
|
365
|
-
- **CSS 파일:** `.css`와 CSS Modules 안의 값은 첫 버전에서 검사하지 않습니다.
|
|
415
|
+
Merging into `main` does not publish anything. Pushing a version tag makes GitHub Actions run the tests and publish to npm.
|
|
366
416
|
|
|
367
|
-
|
|
417
|
+
```sh
|
|
418
|
+
npm version patch # bumps package.json, commits, and creates a tag such as v0.1.1
|
|
419
|
+
git push --follow-tags # pushing the commit and the tag starts the release
|
|
420
|
+
```
|
|
368
421
|
|
|
369
|
-
|
|
370
|
-
| --- | --- |
|
|
371
|
-
| Tailwind 버전 | CSS의 `@theme`으로 토큰을 정의하는 v4를 먼저 지원한다고 가정했습니다. `tailwind.config.js`를 쓰는 v3도 지원할지 정해야 합니다. |
|
|
372
|
-
| Tailwind 기본 팔레트 | 디자인 시스템에 `bg-primary`가 있는데 `bg-blue-500`을 쓴 경우를 잡을지 정해야 합니다. 임의 값은 아니지만 디자인 시스템을 벗어난 색일 수 있습니다. |
|
|
373
|
-
| 간격 스케일의 정의 | 지금은 간격 단위의 0.5배수를 모두 스케일로 봅니다. 프로젝트가 쓰는 단계만 허용하도록 좁힐지 정해야 합니다. |
|
|
374
|
-
| 근사값 판정 | 토큰이 없는 색이나 값을 볼 때, 얼마나 가까워야 가장 가까운 토큰을 제시할지 정해야 합니다. |
|
|
375
|
-
| 역할 판정 | 직접 만든 컴포넌트가 어떤 디자인 시스템 컴포넌트와 역할이 같은지 판단하는 방법을 정해야 합니다. |
|
|
422
|
+
The release stops if the tag and the version in `package.json` differ, or if the tagged commit is not on `main`.
|
|
376
423
|
|
|
377
|
-
##
|
|
424
|
+
## License
|
|
378
425
|
|
|
379
426
|
[MIT](./LICENSE)
|