designsnitch 0.4.0 → 0.5.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 CHANGED
@@ -21,9 +21,9 @@ designsnitch는 디자인 시스템이 없거나 이름뿐인 프로젝트에서
21
21
  | ESLint 플러그인 | 막고 경고합니다. 같은 규칙이 에디터와 lint 단계에서 오류와 경고로 나옵니다. |
22
22
  | 에이전트 훅 | 코드를 쓰는 동안 막습니다. 에이전트는 파일을 고칠 때마다 오류를 전달받고, 스스로 고칠 수 있는 오류가 남아 있으면 작업을 끝내지 못합니다. |
23
23
 
24
- **Tailwind CSS v4를 쓰는 React/Next.js 프로젝트**를 지원합니다.
24
+ **Tailwind CSS v4를 쓰는 React/Next.js 프로젝트**를 지원합니다. Tailwind v3 프로젝트도 검사하지만 후보가 적습니다([Tailwind v3](#tailwind-v3) 참고).
25
25
 
26
- > **상태:** MVP(0.2.x). 메시지는 기본이 영어이고 한국어로 바꿀 수 있습니다. 이 문서의 출력 예시는 한국어로 설정했을 때의 모습입니다. [언어](#언어)를 보세요.
26
+ > **상태:** MVP(0.5.x). 지금은 색과 공용 컴포넌트를 검사합니다. 간격, 폰트 크기, radius는 아직 검사하지 않습니다([검사 범위](#검사-범위) 참고). 메시지는 기본이 영어이고 한국어로 바꿀 수 있습니다. 이 문서의 출력 예시는 한국어로 설정했을 때의 모습입니다. [언어](#언어)를 보세요.
27
27
 
28
28
  ## 시작하기
29
29
 
@@ -94,10 +94,12 @@ Codex, Gemini CLI, Grok Build는 새 프로젝트 훅을 승인하거나 프로
94
94
 
95
95
  | 규칙 | 등급 | 잡는 것 |
96
96
  | --- | --- | --- |
97
- | `color-use-token` | 오류 | 토큰이 있는 hex 색을 임의 값(`bg-[#3B82F6]`), 인라인 스타일(`style={{ color: "#3B82F6" }}`), CSS 선언(`color: #3B82F6`)에 직접 씀 |
98
- | `color-unknown` | 경고 | 맞는 토큰이 없는 hex 색 |
97
+ | `color-use-token` | 오류 | 토큰이 있는 색을 임의 값(`bg-[#3B82F6]`), 인라인 스타일(`style={{ color: "#3B82F6" }}`), CSS 선언(`color: #3B82F6`), `@apply`에 직접 씀 |
98
+ | `color-unknown` | 경고 | 직접 쓴 색인데 맞는 토큰이 없음 |
99
99
  | `use-ds-component` | 오류 | 공용 컴포넌트가 대체하는 `<button>` 같은 raw 태그를 디자인 시스템 경로 밖에서 씀 |
100
100
 
101
+ 직접 쓴 색이란 hex, 숫자를 그대로 적은 색 함수(`rgb()`, `hsl()`, `oklch()`), `white` 같은 색 이름입니다. 표기는 상관없습니다. `#3B82F6`, `rgb(59 130 246)`, `hsl(217 91% 60%)`는 검사에서 같은 색입니다.
102
+
101
103
  오류에는 대신 쓸 것이 함께 나옵니다. JS와 TS 파일에서는 클래스나 컴포넌트이고, 인라인 스타일과 CSS 파일에서는 `var(--토큰)`입니다. Tailwind v4는 소스에서 `var()`로 쓴 테마 변수를 출력하므로, 인라인 스타일의 `var(--토큰)`도 같은 색으로 보입니다.
102
104
 
103
105
  ## 명령
@@ -171,7 +173,7 @@ Tailwind 기본 팔레트
171
173
  | --- | --- |
172
174
  | `hex 색` | hex 색을 많이 쓰인 순서로 보여줍니다. 쓰인 횟수와 파일 수가 함께 나옵니다. |
173
175
  | `bg 2`, `text 1` | Tailwind 유틸리티별 사용 횟수입니다. `bg-[#3a11d8]`은 `bg`로 셉니다. |
174
- | `문자열 1` | 문자열 전체가 hex 색인 경우입니다. 인라인 스타일이나 차트 옵션이 여기에 들어갑니다. |
176
+ | `문자열 1` | 문자열 전체가 색인 경우입니다. 인라인 스타일이나 차트 옵션이 여기에 들어갑니다. |
175
177
  | `CSS 2` | CSS 선언에서 쓴 횟수입니다. JSON 출력에는 속성별로 나뉘어 들어갑니다. |
176
178
  | `Tailwind 기본 팔레트` | `text-gray-700`처럼 Tailwind 기본 팔레트의 색을 이름으로 쓴 경우입니다. |
177
179
 
@@ -186,6 +188,7 @@ Tailwind 기본 팔레트
186
188
  | `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. 경로를 적거나, `file`과 선택 항목 `exclude`, `prefer`를 담은 객체로 적습니다(아래 참고). |
187
189
  | `components.path` | 디자인 시스템 컴포넌트가 있는 경로입니다. 이 안에서는 raw 태그를 써도 됩니다. |
188
190
  | `components.replaces` | raw 태그와 그것을 대체하는 컴포넌트입니다. 한 태그를 대체하는 컴포넌트가 여러 개면 배열로 적습니다. 컴포넌트가 태그의 일부 변형만 맡으면 `{ "component": ..., "when": { ... } }`로 적습니다(아래 참고). |
191
+ | `palette` | `"tailwind"`로 두면 Tailwind 기본 팔레트를 기준에 넣습니다([Tailwind 기본 팔레트](#tailwind-기본-팔레트) 참고). |
189
192
  | `lang` | 메시지의 언어입니다. `en`(기본) 또는 `ko`입니다. |
190
193
 
191
194
  `components`를 생략하면 컴포넌트 검사를 하지 않습니다. 다른 경로의 설정 파일을 쓰려면 `--config <파일>`을 붙입니다. 설정 파일 안의 경로는 설정 파일이 있는 디렉터리를 기준으로 풉니다.
@@ -210,14 +213,14 @@ Tailwind 기본 팔레트
210
213
  ```
211
214
 
212
215
  - `<input type="file">`은 컴포넌트가 맡지 않으므로 보고하지 않습니다.
213
- - `<input type="text">`와 `<input>`은 바로 바꿀 수 있는 오류로 보고합니다.
216
+ - `<input type="text">`와 `<input>`은 컴포넌트로 옮길 오류(`migrate`)로 보고합니다.
214
217
  - `<input type={kind}>`와 `<input {...props}>`는 보고하되 `ask`로 표시합니다. 값을 실행할 때에야 알 수 있거나 spread가 값을 덮어쓸 수 있어서, 바꿔도 안전한지 알 수 없기 때문입니다.
215
218
 
216
219
  토큰 CSS에서 읽는 것은 다음과 같습니다.
217
220
 
218
221
  | 변수 | 쓰임 | 없을 때 |
219
222
  | --- | --- | --- |
220
- | `--color-*` | 색. 값이 hex이거나, `var()`를 따라가면 hex가 나와야 합니다. | 모든 hex 색이 경고가 됩니다 |
223
+ | `--color-*` | 색. 값이 hex, `rgb()`, `hsl()`, `oklch()` 색이거나, `var()`를 따라가면 그런 값이 나와야 합니다. | 직접 쓴 색이 모두 경고가 됩니다 |
221
224
 
222
225
  아래 두 형태를 모두 읽습니다.
223
226
 
@@ -237,6 +240,18 @@ Tailwind 기본 팔레트
237
240
  }
238
241
  ```
239
242
 
243
+ 토큰은 Tailwind가 읽는 곳에서도 읽습니다.
244
+
245
+ - **import한 CSS.** 토큰 CSS가 다른 CSS 파일을 불러오면(`@import "../brand/theme.css"`나 패키지) 그 파일의 `@theme` 토큰도 읽습니다.
246
+ - **접두어.** `@import "tailwindcss" prefix(tw)`를 쓰면 Tailwind가 CSS 변수 이름을 `--tw-color-*`로 만들므로, `var()` 후보도 그렇게 적습니다. 클래스 후보는 `tw:` 뒤의 부분만 바꿉니다.
247
+ - **JavaScript 설정.** `@config "./tailwind.config.js"`가 있으면 `theme.extend.colors`(프리셋 포함)의 색이 토큰이 되고, `theme.colors`는 기본 팔레트를 대체합니다. Tailwind v4의 동작과 같습니다. 이 색들은 클래스로만 있습니다. Tailwind가 CSS 변수를 만들지 않기 때문입니다. 인라인 스타일이나 CSS 선언에 직접 쓰면 오류로 알리되 후보는 없고, 어떻게 할지는 사람이 정합니다. 설정을 읽으려면 그 파일을 실행하므로, 그 파일이 require하는 것이 설치돼 있어야 합니다. 불러오지 못하면 결과의 `problems`에 알립니다.
248
+
249
+ ### Tailwind v3
250
+
251
+ v3 프로젝트는 색을 `tailwind.config.js`에 두고, CSS는 `@tailwind base`로 시작합니다. `tokens`는 평소처럼 CSS 파일을 가리키면 됩니다. 그 CSS가 `@tailwind`를 쓰면 `designsnitch.config.json` 옆의 `tailwind.config.js`(또는 `.cjs`, `.mjs`, `.ts`)를 읽습니다. `tokens`에 설정 파일을 직접 적어도 됩니다. `"palette": "tailwind"`는 v3 팔레트를 `tailwindcss/colors`에서 읽습니다.
252
+
253
+ v3는 색에 CSS 변수를 만들지 않으므로 모든 토큰이 클래스 전용입니다. 임의 값 색 클래스에는 토큰 클래스를 후보로 내고, CSS 선언과 인라인 스타일에 직접 쓴 색은 후보 없이 알립니다.
254
+
240
255
  ## 언어
241
256
 
242
257
  메시지는 기본이 영어입니다. 한국어로 보려면 `designsnitch.config.json`에 `"lang": "ko"`를 적거나, 환경 변수 `DESIGNSNITCH_LANG=ko`를 설정하거나, `--lang ko`를 붙입니다. 여러 개를 함께 주면 `--lang`, 설정 파일, 환경 변수 순으로 우선합니다.
@@ -254,10 +269,10 @@ src/PayButton.tsx
254
269
  8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
255
270
 
256
271
  오류 2개, 경고 1개 (파일 3개 검사)
257
- 바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건 (결정 1개)
272
+ 바로 바꿀 수 있는 것 1건, 컴포넌트로 옮길 것 1건, 사람이 정해야 하는 것 1건 (결정 1개)
258
273
  ```
259
274
 
260
- 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는 위반과 사람이 정해야 하는 위반이 각각 몇 건이고, 사람이 정할 것이 질문 몇 개로 묶이는지 알려줍니다.
275
+ 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는 위반, 컴포넌트로 옮길 태그, 사람이 정해야 하는 위반이 각각 몇 건이고, 사람이 정할 것이 질문 몇 개로 묶이는지 알려줍니다.
261
276
 
262
277
  `--format json`은 같은 결과를 구조화해서 출력합니다. 아래 예시는 위반을 종류별로 하나씩만 남기고 나머지는 생략했습니다.
263
278
 
@@ -266,7 +281,8 @@ src/PayButton.tsx
266
281
  "designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
267
282
  "problems": [],
268
283
  "next": [
269
- "action이 replace인 2건은 found를 candidates의 값으로 바꾸세요.",
284
+ "action이 replace인 1건은 found를 candidates의 값으로 바꾸세요.",
285
+ "action이 migrate인 1건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못 하면 바꾸지 말고 사용자에게 물으세요.",
270
286
  "변경하기 전에 decisions의 2건을 사용자에게 물으세요. 사용 횟수와 후보, 확인이 필요한 이유를 함께 알려 주세요.",
271
287
  "고친 뒤 같은 명령을 다시 실행하세요."
272
288
  ],
@@ -337,11 +353,11 @@ src/PayButton.tsx
337
353
  | `problems` | 결과를 믿기 어렵게 만드는 설정 문제. 정상이면 빈 배열입니다. |
338
354
  | `violations[].found` | 위반한 코드 조각 |
339
355
  | `violations[].candidates` | 대신 쓸 클래스나 컴포넌트. 없으면 빈 배열입니다. |
340
- | `violations[].recommended` | 색을 쓰는 용도에 맞는 후보입니다. `text-` 클래스면 텍스트용 이름의 토큰, 테두리면 테두리용 이름의 토큰입니다. 맞는 후보가 정확히 하나일 때만 채우고, 추천일 뿐이라 `ask`는 그대로 `ask`입니다. `replace`면 그 후보입니다. |
341
- | `violations[].action` | 이 위반을 어떻게 다룰지입니다. `replace`: `found`를 하나뿐인 후보로 바꿔도 화면과 동작이 같습니다. `ask`: 사람이 정해야 합니다. 후보가 여러 개이거나, 토큰이 없는 색이거나, 테마마다 값이 다른 토큰이거나, 컴포넌트의 속성이 동적이거나 spread된 경우입니다. `repair`: 파일을 읽지 못했습니다. |
342
- | `decisions` | `ask`인 위반을 질문 단위로 묶은 것입니다. 색이나 태그와 후보가 같으면 하나로 묶습니다. 각 항목에 얼마나 나오는지(`uses`, `files`), 위치 최대 다섯 곳(`locations`), 후보(`candidates`), 모든 위치에서 추천이 같을 때의 추천(`recommended`), 사람이 정해야 하는 이유(`reasons`: `multiple-candidates`, `no-token`, `themed-token`, `dynamic-props`)가 있습니다. 많이 나오는 순서입니다. |
356
+ | `violations[].recommended` | 색을 쓰는 용도에 맞는 후보입니다. `text-` 클래스면 텍스트용 이름의 토큰, 테두리면 테두리용 이름의 토큰입니다. 맞는 후보가 정확히 하나일 때만 채우고, 추천일 뿐이라 `ask`는 그대로 `ask`입니다. `replace`와 `migrate`면 그 후보입니다. |
357
+ | `violations[].action` | 이 위반을 어떻게 다룰지입니다. `replace`: `found`를 하나뿐인 후보로 바꿔도 화면과 동작이 같습니다. 색 오류만 해당합니다. `migrate`: raw 태그를 옮길 디자인 시스템 컴포넌트가 하나뿐입니다. 컴포넌트가 같은 props를 넘기는지, 기본 스타일이 같은지는 도구가 알 수 없으므로 컴포넌트를 먼저 읽고 태그의 props를 옮기고 컴포넌트가 이미 주는 클래스는 지웁니다. 에이전트가 스스로 할 수 있는 일이라 훅은 `replace`처럼 다룹니다. `ask`: 사람이 정해야 합니다. 후보가 여러 개이거나, 토큰이 없는 색이거나, 테마마다 값이 다른 토큰이거나, 컴포넌트의 속성이 동적이거나 spread된 경우입니다. `repair`: 파일을 읽지 못했습니다. |
358
+ | `decisions` | `ask`인 위반을 질문 단위로 묶은 것입니다. 색이나 태그와 후보가 같으면 하나로 묶습니다. 각 항목에 얼마나 나오는지(`uses`, `files`), 위치 최대 다섯 곳(`locations`), 후보(`candidates`), 모든 위치에서 추천이 같을 때의 추천(`recommended`), 사람이 정해야 하는 이유(`reasons`: `multiple-candidates`, `no-token`, `themed-token`, `class-only-token`, `dynamic-props`)가 있습니다. 많이 나오는 순서입니다. |
343
359
  | `next` | 이 결과를 받은 에이전트가 할 일을 순서대로 적은 것 |
344
- | `unchecked` | 검사하지 못한 다른 문자열 속 hex 색의 개수(`hexColors`)와 파일 수(`files`). 하나라도 있으면 글 출력에 한 줄이 붙습니다. |
360
+ | `unchecked` | 검사하지 못한 다른 문자열 속 색의 개수(`colors`)와 파일 수(`files`). 하나라도 있으면 글 출력에 한 줄이 붙습니다. |
345
361
 
346
362
  | 종료 코드 | 의미 |
347
363
  | --- | --- |
@@ -464,7 +480,20 @@ Grok Build에는 `npx designsnitch install --agent grok`이 `PostToolUse`와 `St
464
480
 
465
481
  ### Tailwind 기본 팔레트
466
482
 
467
- designsnitch는 `bg-blue-500` 같은 기본 팔레트 클래스를 위반으로 잡지 않습니다. 프로젝트가 자기 토큰만 써야 한다면, Tailwind v4에서 기본 팔레트를 없앨 수 있습니다. 그러면 그런 클래스가 아예 동작하지 않습니다.
483
+ Tailwind 기본 팔레트(`bg-slate-100`, `text-indigo-600`)를 기준으로 쓰는 프로젝트가 많습니다. `"palette": "tailwind"`를 두면 기본 팔레트를 기준에 넣습니다.
484
+
485
+ ```json
486
+ { "tokens": "app/globals.css", "palette": "tailwind" }
487
+ ```
488
+
489
+ - 팔레트는 프로젝트에 설치된 `tailwindcss/theme.css`에서 읽습니다. 토큰 CSS 위치에서 찾으므로 언제나 설치된 버전과 맞습니다. Tailwind CSS v4(4.0 이상)가 필요합니다. v3이거나 tailwindcss를 찾지 못하면 검사를 멈추고 어느 쪽인지 알립니다. 4.0.0, 4.1.0, 4.2.0, 4.3.0, 4.3.5로 확인했습니다. 버전 사이에 값이 바뀐 색은 없고, 4.2.0에서 `mauve`, `olive`, `mist`, `taupe` 계열이 추가됐습니다.
490
+ - 팔레트 색과 값이 같은 hex는 오류이고, 팔레트 클래스가 후보입니다: `bg-[#62748e]` → `bg-slate-500`. Tailwind v4는 팔레트를 `oklch()`로 적어서, 비교할 때 hex로 바꿉니다. sRGB 밖의 팔레트 색은 같은 색을 내는 hex가 없으므로 같은 `oklch()` 값과만 맞춥니다.
491
+ - 프로젝트 토큰 CSS에 팔레트와 같은 이름의 토큰이 있으면 프로젝트 값을 씁니다. Tailwind 문서의 기본색 덮어쓰기 예시처럼 hex로 적어도, `oklch()`로 적어도 됩니다.
492
+ - Tailwind 문서에 나온 대로 프로젝트가 비운 네임스페이스는 뺍니다. `--color-*: initial`은 팔레트 전체를, `--color-lime-*: initial`은 그 계열을, `--*: initial`은 기본 테마 전체를 지웁니다.
493
+ - `tokens`의 `exclude`와 `prefer`는 팔레트 색에도 적용됩니다.
494
+ - 팔레트도 토큰으로 세므로, 자기 토큰이 없는 프로젝트도 "토큰 없음"으로 보지 않습니다.
495
+
496
+ `palette`가 없으면 기본 팔레트 클래스를 위반으로 잡지 않고, hex와 비교하지도 않습니다. 프로젝트가 자기 토큰만 써야 한다면, Tailwind v4에서 기본 팔레트를 없앨 수 있습니다. 그러면 그런 클래스가 아예 동작하지 않습니다.
468
497
 
469
498
  ```css
470
499
  @theme {
@@ -475,21 +504,27 @@ designsnitch는 `bg-blue-500` 같은 기본 팔레트 클래스를 위반으로
475
504
 
476
505
  ## 검사 범위
477
506
 
478
- - **JS와 TS에서 보는 곳:** 문자열과 템플릿 리터럴 안의 임의 값 색 클래스(`className`과 `cn()`, `clsx()`, `cva()`의 인자 포함)와, JSX `style` 객체에 문자열로 적은 hex 색입니다. 주석은 보지 않습니다. 테마 객체나 차트 옵션 같은 다른 문자열의 hex 색은 코드만 보고 용도를 알 수 없어 검사하지 않습니다. 대신 있다는 것을 알 수 있도록 `unchecked`에 개수를 세고, `designsnitch colors`로 목록을 볼 수 있습니다.
479
- - **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는 hex 색입니다. 토큰 CSS에서는 변수를 정의하는 선언(`--이름: ...`)을 토큰을 정의하는 곳으로 보고 건너뜁니다. 다른 CSS 파일에서는 변수 선언도 일반 선언처럼 검사합니다. CSS에서는 아직 색만 검사합니다.
480
- - **테마:** 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 그 토큰의 값으로 봅니다. hex 색을 그런 토큰으로 바꾸면 다른 테마에서 색이 바뀌므로 `ask`로 표시합니다.
507
+ - **JS와 TS에서 보는 곳:** 문자열과 템플릿 리터럴 안의 임의 값 색 클래스(`className`과 `cn()`, `clsx()`, `cva()`의 인자 포함)와, JSX `style` 객체에 문자열로 적은 색입니다. `a ? "#fff" : "#000"`이나 `x || "#fff"`처럼 고르는 식의 값도 봅니다. 주석은 보지 않습니다. 테마 객체나 차트 옵션 같은 다른 문자열의 색은 코드만 보고 용도를 알 수 없어 검사하지 않습니다. 대신 있다는 것을 알 수 있도록 `unchecked`에 개수를 세고, `designsnitch colors`로 목록을 볼 수 있습니다.
508
+ - **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는 색과 `@apply`의 임의 값 색 클래스입니다. 토큰 CSS에서는 변수를 정의하는 선언(`--이름: ...`)을 토큰을 정의하는 곳으로 보고 건너뜁니다. 다른 CSS 파일에서는 변수 선언도 일반 선언처럼 검사합니다. CSS에서는 아직 색만 검사합니다.
509
+ - **테마:** 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 그 토큰의 값으로 봅니다. 색을 그런 토큰으로 바꾸면 다른 테마에서 색이 바뀌므로 `ask`로 표시합니다.
481
510
  - **수정:** designsnitch는 후보를 알려줄 뿐, 후보가 하나여도 코드를 직접 고치지 않습니다.
482
511
 
483
512
  ### 아직 안 되는 것
484
513
 
485
- - hex가 아닌 색(`rgb()`, `hsl()`, `oklch()`)
486
- - Tailwind 기본 테마의 값. 프로젝트의 토큰 CSS에 적힌 값만 읽습니다.
487
- - Tailwind v3(`tailwind.config.js`)
514
+ 감지는 하지만 토큰과 맞추지는 못하는 것:
515
+
516
+ - 반투명한 색(`#3B82F680`, `rgb(0 0 0 / 50%)`)은 불투명한 색에 토큰이 있어도 토큰 없는 색으로 알립니다.
517
+ - Tailwind 플러그인이 더하는 색은 토큰으로 알지 못합니다. 그 색을 직접 쓰면 토큰 없는 색으로 알립니다.
518
+ - `hwb()`, `lab()`, `lch()`, `oklab()`, `color()` 값과 sRGB 밖의 `oklch()` 색은 같은 값으로 적은 토큰과만 맞춥니다. 같은 색을 내는 hex가 없기 때문입니다.
519
+ - 색 이름은 색 속성(`color`, `background`, `border` 등), 임의 값 클래스(`bg-[white]`), 값 전체가 색 이름인 변수 선언에서만 읽습니다. 다른 곳의 `red` 같은 단어는 색으로 보지 않습니다.
520
+
521
+ 검사하지 않는 것:
522
+
523
+ - 색 팔레트를 뺀 Tailwind 기본 테마의 값
488
524
  - 토큰이 없는 색에 가장 가까운 토큰 제시
489
- - 계산되는 인라인 스타일 값. 예: `color: active ? "#3B82F6" : "#fff"`
525
+ - JSX `style` 속성 밖의 스타일 객체. 예: `const style = { color: "#fff" }`
490
526
  - SCSS 같은 전처리기
491
527
  - 간격, 폰트 크기, radius. 이번 버전에서는 일부러 뺐습니다.
492
- - `@apply` 안의 클래스
493
528
  - 직접 만든 컴포넌트와 디자인 시스템 컴포넌트의 스타일 비교
494
529
  - Claude Code, Codex, Gemini CLI, Grok Build가 아닌 에이전트에 훅 설치하기
495
530
 
package/README.md CHANGED
@@ -21,9 +21,9 @@ It has four parts.
21
21
  | ESLint plugin | Blocks and warns. The same rules show up as errors and warnings in the editor and in the lint step. |
22
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. |
23
23
 
24
- It supports **React/Next.js projects that use Tailwind CSS v4**.
24
+ It supports **React/Next.js projects that use Tailwind CSS v4**. Tailwind v3 projects are checked too, with fewer candidates (see [Tailwind v3](#tailwind-v3)).
25
25
 
26
- > **Status:** MVP (0.2.x). Messages are in English by default and can be switched to Korean. See [Language](#language).
26
+ > **Status:** MVP (0.5.x). It checks colors and shared components for now. Spacing, font size and radius are not checked yet (see [Scope](#scope)). Messages are in English by default and can be switched to Korean. See [Language](#language).
27
27
 
28
28
  ## Getting started
29
29
 
@@ -94,10 +94,12 @@ Severity follows one rule.
94
94
 
95
95
  | Rule | Severity | What it catches |
96
96
  | --- | --- | --- |
97
- | `color-use-token` | Error | A hex color that has a token, written as an arbitrary value (`bg-[#3B82F6]`), in an inline style (`style={{ color: "#3B82F6" }}`) or in a CSS declaration (`color: #3B82F6`) |
98
- | `color-unknown` | Warning | A hex color with no matching token |
97
+ | `color-use-token` | Error | A color that has a token, written by hand as an arbitrary value (`bg-[#3B82F6]`), in an inline style (`style={{ color: "#3B82F6" }}`), in a CSS declaration (`color: #3B82F6`) or in `@apply` |
98
+ | `color-unknown` | Warning | A color written by hand with no matching token |
99
99
  | `use-ds-component` | Error | A raw tag such as `<button>` used outside the design system directory, when a shared component replaces it |
100
100
 
101
+ A color written by hand is a hex color, a color function with literal numbers (`rgb()`, `hsl()`, `oklch()`), or a color name such as `white`. Notation does not matter: `#3B82F6`, `rgb(59 130 246)` and `hsl(217 91% 60%)` are the same color to the check.
102
+
101
103
  Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in inline styles and CSS files. Tailwind v4 outputs a theme variable when the source uses it with `var()`, so `var(--token)` in an inline style renders the same color.
102
104
 
103
105
  ## Commands
@@ -170,7 +172,7 @@ Tailwind default palette
170
172
  | --- | --- |
171
173
  | `Hex colors` | Hex colors, most used first, with the number of uses and files. |
172
174
  | `bg 2`, `text 1` | Uses per Tailwind utility. `bg-[#3a11d8]` counts under `bg`. |
173
- | `string 1` | Strings that are a hex color on their own, such as inline styles and chart options. |
175
+ | `string 1` | Strings that are a color on their own, such as inline styles and chart options. |
174
176
  | `CSS 2` | Uses in CSS declarations. The JSON output breaks these down by property. |
175
177
  | `Tailwind default palette` | Colors from Tailwind's default palette used by name, such as `text-gray-700`. |
176
178
 
@@ -185,6 +187,7 @@ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose to
185
187
  | `tokens` | The CSS file that defines the tokens. Required. Either a path, or an object with `file` and the optional `exclude` and `prefer` (see below). |
186
188
  | `components.path` | The directory that holds the design system components. Raw tags are allowed inside it. |
187
189
  | `components.replaces` | Raw tags and the components that replace them. Use an array when several components replace one tag. Use `{ "component": ..., "when": { ... } }` when a component covers only some variants of the tag (see below). |
190
+ | `palette` | `"tailwind"` to use Tailwind's default palette as part of the standard (see [Tailwind's default palette](#tailwinds-default-palette)). |
188
191
  | `lang` | The language of the messages: `en` (default) or `ko`. |
189
192
 
190
193
  Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path. Paths in the config file are relative to the directory of the config file.
@@ -209,14 +212,14 @@ A shared component often covers only some variants of a tag. An `Input` componen
209
212
  ```
210
213
 
211
214
  - `<input type="file">` is not reported, because the component does not cover it.
212
- - `<input type="text">` and `<input>` are reported as errors that can be replaced.
215
+ - `<input type="text">` and `<input>` are reported as errors to move to the component (`migrate`).
213
216
  - `<input type={kind}>` and `<input {...props}>` are reported, but marked `ask`: the value is only known at runtime, or a spread may override it, so replacing is not known to be safe.
214
217
 
215
218
  This is what is read from the token CSS.
216
219
 
217
220
  | Variable | Used for | When missing |
218
221
  | --- | --- | --- |
219
- | `--color-*` | Colors. The value must be a hex color, or a `var()` that leads to one. | Every hex color becomes a warning |
222
+ | `--color-*` | Colors. The value must be a hex, `rgb()`, `hsl()` or `oklch()` color, or a `var()` that leads to one. | Every color written by hand becomes a warning |
220
223
 
221
224
  Both of these shapes work.
222
225
 
@@ -236,6 +239,18 @@ Both of these shapes work.
236
239
  }
237
240
  ```
238
241
 
242
+ Tokens are also read from where Tailwind itself reads them.
243
+
244
+ - **Imported CSS.** If the token CSS imports other CSS files (`@import "../brand/theme.css"`, or a package), their `@theme` tokens are read too.
245
+ - **A prefix.** With `@import "tailwindcss" prefix(tw)`, Tailwind names its CSS variables `--tw-color-*`, so `var()` candidates are written that way. Class candidates replace only the part after `tw:`.
246
+ - **A JavaScript config.** With `@config "./tailwind.config.js"`, colors in `theme.extend.colors` (and in presets) become tokens, and `theme.colors` replaces the default palette, as Tailwind v4 does. These colors exist only as classes: Tailwind makes no CSS variable for them. Writing one by hand in an inline style or a CSS declaration is still reported as an error, with no candidate, and a person decides what to do. Loading the config runs it, so what it requires must be installed. If it cannot be loaded, the result says so in `problems`.
247
+
248
+ ### Tailwind v3
249
+
250
+ A v3 project keeps its colors in `tailwind.config.js`, and its CSS starts with `@tailwind base`. Point `tokens` at the CSS file as usual: when it uses `@tailwind`, the `tailwind.config.js` (or `.cjs`, `.mjs`, `.ts`) next to `designsnitch.config.json` is read. You can also point `tokens` straight at the config file. `"palette": "tailwind"` reads the v3 palette from `tailwindcss/colors`.
251
+
252
+ v3 makes no CSS variables for its colors, so every token is class-only: arbitrary color classes get token classes as candidates, and colors written by hand in CSS declarations and inline styles are reported without a candidate.
253
+
239
254
  ## Language
240
255
 
241
256
  Messages are in English by default. To read them in Korean, set `"lang": "ko"` in `designsnitch.config.json`, set the environment variable `DESIGNSNITCH_LANG=ko`, or pass `--lang ko`. When more than one is given, `--lang` wins, then the config file, then the environment variable.
@@ -253,10 +268,10 @@ src/PayButton.tsx
253
268
  8:26 warning The color of bg-[#3B82F5] is not in the tokens. (color-unknown)
254
269
 
255
270
  2 errors, 1 warning (3 files checked)
256
- 2 can be replaced right away, 1 needs a person's decision (1 decision)
271
+ 1 can be replaced right away, 1 to move to a component, 1 needs a person's decision (1 decision)
257
272
  ```
258
273
 
259
- 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 `Note:` explains why. The last line says how many violations can be replaced right away, how many need a person's decision, and how many separate questions those come down to.
274
+ 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 `Note:` explains why. The last line says how many violations can be replaced right away, how many are tags to move to a component, how many need a person's decision, and how many separate questions those come down to.
260
275
 
261
276
  `--format json` prints the same result as structured data. This example has one violation of each kind, and leaves the rest out.
262
277
 
@@ -265,7 +280,8 @@ The first line shows how many tokens and components were read from the config. A
265
280
  "designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
266
281
  "problems": [],
267
282
  "next": [
268
- "action \"replace\" (2): replace found with the value in candidates.",
283
+ "action \"replace\" (1): replace found with the value in candidates.",
284
+ "action \"migrate\" (1): replace the tag with the component in candidates. Read that component first: add the import, pass on the props it accepts, and drop className values it already applies. If it cannot do what the tag did, ask the user instead.",
269
285
  "Before making changes, ask the user about the 2 entries in decisions. Include how often each comes up, the candidates, and the reasons for asking.",
270
286
  "After fixing, run the same command again."
271
287
  ],
@@ -336,11 +352,11 @@ The first line shows how many tokens and components were read from the config. A
336
352
  | `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
337
353
  | `violations[].found` | The offending piece of code |
338
354
  | `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
339
- | `violations[].recommended` | The candidate that fits how the color is used: a `text-` class gets the token named for text, a border gets the one named for borders. Only set when exactly one candidate fits, and only a suggestion: an `ask` stays an `ask`. For `replace`, it is the candidate. |
340
- | `violations[].action` | How to handle the violation. `replace`: replacing `found` with the only candidate keeps the screen and the behavior the same. `ask`: a person has to decide: several candidates, a color with no token, a token whose value differs between themes, or a component whose props are dynamic or spread. `repair`: the file could not be parsed. |
341
- | `decisions` | The `ask` violations grouped into questions: one per color or tag with the same candidates. Each has how often it comes up (`uses`, `files`), up to five `locations`, the `candidates`, a `recommended` candidate when every location agrees, and the `reasons` a person has to decide: `multiple-candidates`, `no-token`, `themed-token` or `dynamic-props`. Most used first. |
355
+ | `violations[].recommended` | The candidate that fits how the color is used: a `text-` class gets the token named for text, a border gets the one named for borders. Only set when exactly one candidate fits, and only a suggestion: an `ask` stays an `ask`. For `replace` and `migrate`, it is the candidate. |
356
+ | `violations[].action` | How to handle the violation. `replace`: replacing `found` with the only candidate keeps the screen and the behavior the same. Only color errors get this. `migrate`: a raw tag with exactly one design system component to move to. The tool cannot tell whether the component passes on the same props or renders the same default styles, so read the component first, then move the tag's props and drop classes the component already applies. The agent can do this itself, so the hook treats it like `replace`. `ask`: a person has to decide: several candidates, a color with no token, a token whose value differs between themes, or a component whose props are dynamic or spread. `repair`: the file could not be parsed. |
357
+ | `decisions` | The `ask` violations grouped into questions: one per color or tag with the same candidates. Each has how often it comes up (`uses`, `files`), up to five `locations`, the `candidates`, a `recommended` candidate when every location agrees, and the `reasons` a person has to decide: `multiple-candidates`, `no-token`, `themed-token`, `class-only-token` or `dynamic-props`. Most used first. |
342
358
  | `next` | What an agent should do with this result, in order |
343
- | `unchecked` | Hex colors in other strings that were not checked (`hexColors`), and how many files they are in (`files`). The text output adds a line when there are any. |
359
+ | `unchecked` | Colors in other strings that were not checked (`colors`), and how many files they are in (`files`). The text output adds a line when there are any. |
344
360
 
345
361
  | Exit code | Meaning |
346
362
  | --- | --- |
@@ -463,7 +479,20 @@ The command reads an optional JSON object from stdin (`tool_input.file_path`, `h
463
479
 
464
480
  ### Tailwind's default palette
465
481
 
466
- 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.
482
+ Many projects use Tailwind's default palette (`bg-slate-100`, `text-indigo-600`) as their standard. Set `"palette": "tailwind"` to make it part of the standard.
483
+
484
+ ```json
485
+ { "tokens": "app/globals.css", "palette": "tailwind" }
486
+ ```
487
+
488
+ - The palette is read from the `tailwindcss/theme.css` installed in the project, found from the token CSS, so it always matches the installed version. This needs Tailwind CSS v4 (4.0 or later). With v3, or when tailwindcss cannot be found, the check stops and says which. Tested against 4.0.0, 4.1.0, 4.2.0, 4.3.0 and 4.3.5: no color changed value between them, and 4.2.0 added the `mauve`, `olive`, `mist` and `taupe` scales.
489
+ - A hex color with the same value as a palette color is an error, with the palette class as its candidate: `bg-[#62748e]` → `bg-slate-500`. Tailwind v4 writes the palette in `oklch()`, and it is converted to hex for the comparison. Palette colors outside sRGB have no hex value that renders the same, so they match only the same `oklch()` value.
490
+ - A token in the project's token CSS with the same name as a palette color replaces it, in hex or in `oklch()`, as in Tailwind's own example of overriding a color.
491
+ - Namespaces the project clears are left out, as Tailwind documents: `--color-*: initial` removes the whole palette, `--color-lime-*: initial` removes one scale, and `--*: initial` removes the whole default theme.
492
+ - `exclude` and `prefer` in `tokens` apply to palette colors too.
493
+ - The palette counts as tokens, so a project with no tokens of its own is not reported as having none.
494
+
495
+ Without `palette`, designsnitch does not flag default palette classes, and does not compare hex colors with them. If the project should use only its own tokens, Tailwind v4 can remove the default palette, and then those classes stop working at all.
467
496
 
468
497
  ```css
469
498
  @theme {
@@ -474,21 +503,27 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
474
503
 
475
504
  ## Scope
476
505
 
477
- - **Where it looks in JS and TS:** arbitrary color classes in string literals and template literals, which covers `className` and the arguments of `cn()`, `clsx()` and `cva()`, and hex colors written as strings in a JSX `style` object. Comments are ignored. Hex colors in other strings, such as theme objects and chart options, are not checked: their purpose cannot be told from the code. The check counts them in `unchecked` so that you know they are there, and `designsnitch colors` lists them.
478
- - **Where it looks in CSS:** hex colors in declaration values, in `.css` files including CSS Modules. In the token CSS, declarations that define a variable (`--name: ...`) are skipped, since that is where tokens are defined. In every other CSS file they are checked like any other declaration. Only colors are checked in CSS for now.
479
- - **Themes:** when a token has different values per theme, all of them count as that token's value. Replacing a hex color with such a token changes the color in the other themes, so those errors are marked `ask`.
506
+ - **Where it looks in JS and TS:** arbitrary color classes in string literals and template literals, which covers `className` and the arguments of `cn()`, `clsx()` and `cva()`, and colors written as strings in a JSX `style` object, including the branches of `a ? "#fff" : "#000"` and `x || "#fff"`. Comments are ignored. Colors in other strings, such as theme objects and chart options, are not checked: their purpose cannot be told from the code. The check counts them in `unchecked` so that you know they are there, and `designsnitch colors` lists them.
507
+ - **Where it looks in CSS:** colors in declaration values and arbitrary color classes in `@apply`, in `.css` files including CSS Modules. In the token CSS, declarations that define a variable (`--name: ...`) are skipped, since that is where tokens are defined. In every other CSS file they are checked like any other declaration. Only colors are checked in CSS for now.
508
+ - **Themes:** when a token has different values per theme, all of them count as that token's value. Replacing a color with such a token changes the color in the other themes, so those errors are marked `ask`.
480
509
  - **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
481
510
 
482
511
  ### Not supported yet
483
512
 
484
- - Colors that are not hex (`rgb()`, `hsl()`, `oklch()`)
485
- - Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
486
- - Tailwind v3 (`tailwind.config.js`)
513
+ These are detected, but not matched to a token:
514
+
515
+ - Translucent colors (`#3B82F680`, `rgb(0 0 0 / 50%)`) are reported as colors with no token, even when the opaque color has one.
516
+ - Colors a Tailwind plugin adds are not known as tokens, so writing one by hand is reported as a color with no token.
517
+ - `hwb()`, `lab()`, `lch()`, `oklab()` and `color()` values, and `oklch()` colors outside sRGB, match only a token written with the same value: no hex color renders the same.
518
+ - Color names are read in color properties (`color`, `background`, `border`, ...), in arbitrary classes (`bg-[white]`), and as a whole custom property value. Elsewhere a word such as `red` is not taken for a color.
519
+
520
+ These are not checked:
521
+
522
+ - Values from Tailwind's default theme other than the color palette
487
523
  - The nearest token for a color that has none
488
- - Inline style values that are computed, such as `color: active ? "#3B82F6" : "#fff"`
524
+ - Style objects outside a JSX `style` attribute, such as `const style = { color: "#fff" }`
489
525
  - SCSS and other preprocessors
490
526
  - Spacing, font size and radius. They were left out of this version on purpose.
491
- - Classes inside `@apply`
492
527
  - Comparing a hand-made component's styles with the design system component
493
528
  - Installing the hook for agents other than Claude Code, Codex, Gemini CLI and Grok Build
494
529
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designsnitch",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Keep AI-written UI code manageable and consistent, even without a design system. CLI, agent skills, ESLint plugin and agent hook for React/Next.js with Tailwind CSS v4.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -71,15 +71,15 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
71
71
  - `action` says how to handle each violation. Section 3 covers each value.
72
72
  - `found` is the offending piece of code. `candidates` lists what to use instead: classes or components in JS and TS files, and `var(--token)` in inline styles and `.css` files.
73
73
  - `recommended` is the candidate whose token is named for how the color is used here, such as the text token for a `text-` class. It is a suggestion to put in front of the user, not permission to replace.
74
- - `decisions` groups every `ask` violation into questions: one per color or tag with the same candidates, most used first. Each has `uses`, `files`, up to five `locations`, the `candidates`, a `recommended` candidate when all locations agree, and `reasons` (`multiple-candidates`, `no-token`, `themed-token`, `dynamic-props`). Ask the user about decisions, not about single violations.
75
- - `unchecked` counts hex colors in other strings, such as theme objects and chart options, that the check could not judge. They are not violations. If the count is large and those strings feed the UI, mention it to the user: `npx designsnitch colors` lists them.
76
- - `designSystem` counts the tokens and components read from the config. `colorTokens` 0 means the project has no color tokens that can be read: follow the `designsnitch-palette` skill to establish them before touching any color.
74
+ - `decisions` groups every `ask` violation into questions: one per color or tag with the same candidates, most used first. Each has `uses`, `files`, up to five `locations`, the `candidates`, a `recommended` candidate when all locations agree, and `reasons` (`multiple-candidates`, `no-token`, `themed-token`, `class-only-token`, `dynamic-props`). Ask the user about decisions, not about single violations.
75
+ - `unchecked` counts colors in other strings, such as theme objects and chart options, that the check could not judge. They are not violations. If the count is large and those strings feed the UI, mention it to the user: `npx designsnitch colors` lists them.
76
+ - `designSystem` counts the tokens and components read from the config. `paletteColors` is the number of Tailwind default palette colors in the standard, when the config has `"palette": "tailwind"`. `colorTokens` 0 means the project has no color tokens that can be read: follow the `designsnitch-palette` skill to establish them before touching any color.
77
77
  - A non-empty `problems` means the config is broken and the results cannot be trusted. Tell the user before fixing anything.
78
78
 
79
79
  | `rule` | Severity | Meaning |
80
80
  | --- | --- | --- |
81
- | `color-use-token` | error | A hex color that has a token was written as an arbitrary value, in an inline style, or directly in a CSS declaration. |
82
- | `color-unknown` | warning | A hex color with no matching token. |
81
+ | `color-use-token` | error | A color that has a token was written by hand (hex, a color function such as `rgb()`, or a color name such as `white`): as an arbitrary value, in an inline style, in a CSS declaration or in `@apply`. |
82
+ | `color-unknown` | warning | A color written by hand with no matching token. |
83
83
  | `use-ds-component` | error | A raw tag was used outside the design system directory although a shared component replaces it. |
84
84
  | `parse-error` | error | The file could not be parsed. |
85
85
 
@@ -87,11 +87,12 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
87
87
 
88
88
  | `action` | What it means | What to do |
89
89
  | --- | --- | --- |
90
- | `replace` | An error whose only candidate keeps the screen and the behavior the same. | Replace `found` with the candidate. |
91
- | `ask` | A person has to decide: several candidates, a color that has no token, a token whose value differs between themes, or a component whose props are dynamic or spread. `message` says which. | Do not change it. Ask the user as described in section 4. |
90
+ | `replace` | A color error whose only candidate keeps the screen and the behavior the same. | Replace `found` with the candidate. |
91
+ | `migrate` | A raw tag with exactly one design system component to move to. Whether the component behaves like the tag is not known. | Move the tag to the component as described below. If the component cannot do what the tag did, such as a missing prop or a different element, do not force it: ask the user. |
92
+ | `ask` | A person has to decide: several candidates, a color that has no token, a token whose value differs between themes, a token that exists only as a class (no CSS variable to use in a style or a CSS declaration), or a component whose props are dynamic or spread. `message` says which. | Do not change it. Ask the user as described in section 4. |
92
93
  | `repair` | The file could not be parsed. | Fix the syntax error, then check again. |
93
94
 
94
- For `use-ds-component`, replacing means more than renaming the tag. Read the design system component file to learn its props, add the import, and remove className values that duplicate styles the component already has.
95
+ For `migrate`, replacing means more than renaming the tag. Read the design system component file to learn its props, add the import, pass on the tag's props the component accepts, and remove className values that duplicate styles the component already has. Check that event handlers such as `onClick` and attributes such as `type` still reach the rendered element.
95
96
 
96
97
  ## 4. Ask so the user can decide
97
98
 
@@ -69,7 +69,7 @@ Then work out what each color of its own is for. `utilities` and `properties` sh
69
69
  | `bg`, or `background` properties | Background or surface |
70
70
  | A mix, or mostly `literals` | A general color such as a brand or chart color. Open the examples to see. |
71
71
 
72
- For `palette`, note which default palette colors the project relies on. They already work as classes and designsnitch does not flag them. Whether they belong to the design system is the user's call, so include them in the proposal as a question.
72
+ For `palette`, note which default palette colors the project relies on. If they carry most of the color uses, the default palette is the project's standard already. Do not copy palette colors into new hex tokens: that changes nothing on screen and doubles the names. Propose `"palette": "tailwind"` in `designsnitch.config.json` instead, and limit new tokens to colors outside the palette. If the palette is a minor part, whether it belongs to the design system is the user's call, so include it in the proposal as a question.
73
73
 
74
74
  ## 3. Propose
75
75
 
@@ -107,9 +107,9 @@ After the user approves, add the tokens to the CSS file that imports Tailwind (`
107
107
  }
108
108
  ```
109
109
 
110
- Write the values as hex. designsnitch reads hex values and `var()` references to hex values, and nothing else.
110
+ Write the values as hex, the form the code already uses. designsnitch reads hex, `rgb()`, `hsl()` and `oklch()` values, and `var()` references to them.
111
111
 
112
- If the project uses Tailwind v3 (a `tailwind.config.js` and no `@theme`), stop and tell the user: designsnitch does not read v3 config yet.
112
+ If the project uses Tailwind v3 (a `tailwind.config.js` and no `@theme`), there is no `@theme` to write to. Propose the same tokens as entries of `theme.extend.colors` in `tailwind.config.js` instead, and add them after the user approves.
113
113
 
114
114
  ## 5. Point the config at the tokens
115
115
 
@@ -7,14 +7,15 @@ description: Set up designsnitch in a React/Next.js + Tailwind project. Finds th
7
7
 
8
8
  designsnitch needs to know where the project's design system lives. Read the codebase, write that down in `designsnitch.config.json`, and then make the ESLint plugin use it. The CLI and the plugin read the same file.
9
9
 
10
- Only create the file when it is missing. If it already exists and seems wrong, explain why and ask the user before changing it: this file is the standard the code is judged against.
10
+ Create the file when it is missing. This does not need the user's approval: it only records where the existing standard is. If it already exists and seems wrong, explain why and ask the user before changing it: this file is the standard the code is judged against.
11
11
 
12
12
  ## 0. Check that the project is supported, and install the package
13
13
 
14
- designsnitch supports React or Next.js projects that use Tailwind CSS v4. Look at `package.json` and the global CSS file.
14
+ designsnitch supports React or Next.js projects that use Tailwind CSS. Look at `package.json` and the global CSS file.
15
15
 
16
- - Tailwind v4 has `tailwindcss` version 4 in `package.json` and `@import "tailwindcss"` in a CSS file.
17
- - If the project uses Tailwind v3 (a `tailwind.config.js` with a `theme` section and no `@theme` in CSS), or does not use Tailwind or React at all, stop and tell the user that designsnitch does not support it yet.
16
+ - Tailwind v4 has `tailwindcss` version 4 in `package.json` and `@import "tailwindcss"` in a CSS file. This is the full case.
17
+ - Tailwind v3 has `tailwindcss` version 3, `@tailwind base` in a CSS file and its colors in `tailwind.config.js`. It is checked too: point `tokens` at the CSS file, and the `tailwind.config.js` in the same directory as `designsnitch.config.json` is read. Tell the user what is different: v3 has no CSS variables for its colors, so colors written by hand in CSS declarations and inline styles are reported without a candidate, and the `designsnitch-palette` skill, which writes `@theme` tokens, does not apply. New colors go into `tailwind.config.js`, with the user's approval.
18
+ - If the project does not use Tailwind or React at all, stop and tell the user that designsnitch does not support it yet.
18
19
 
19
20
  Then make sure the package is a dependency of the project. The commands below and the agent hook both run `npx designsnitch`, which should use the project's own copy.
20
21
 
@@ -26,9 +27,11 @@ npm install --save-dev designsnitch
26
27
 
27
28
  It is the CSS file with an `@theme` block or `--color-*` variables, usually `app/globals.css` or `src/app/globals.css`. If you cannot tell which CSS file is the right one, ask the user.
28
29
 
29
- designsnitch reads a variable as a color token only when its name starts with `--color-` and its value is a hex color or a `var()` that leads to one. Two cases need a decision before you go on.
30
+ designsnitch reads a variable as a color token only when its name starts with `--color-` and its value is a hex, `rgb()`, `hsl()` or `oklch()` color, or a `var()` that leads to one. It also reads `@theme` tokens from CSS files the token CSS imports, and colors from a JavaScript config the token CSS loads with `@config`. Point `tokens` at the CSS file that imports Tailwind, and the rest is found from there. Some cases need a decision before you go on.
30
31
 
31
- **The project has no color variables at all.** There are no color tokens yet. Follow the `designsnitch-palette` skill to create them from the colors the code already uses, then continue here.
32
+ **The project uses Tailwind's default palette as its colors.** Run `npx designsnitch colors --format json`. If most uses are in `palette` (classes such as `bg-slate-100`) and few are hex colors, the project already has a standard: the default palette. Do not turn palette colors into new hex tokens. Propose `"palette": "tailwind"` in the config instead, which makes the default palette part of the standard and flags hex colors that duplicate it. Tell the user what this means, and add it after they agree. Colors that are not in the palette can still get project tokens through the `designsnitch-palette` skill.
33
+
34
+ **The project has no color variables at all, and does not rely on the default palette.** There are no color tokens yet. Follow the `designsnitch-palette` skill to create them from the colors the code already uses, then continue here.
32
35
 
33
36
  **The project has color variables under other names**, such as `--ink` or `--brand` in `:root`. These are the project's tokens, but designsnitch cannot see them. Do not create a second set of tokens next to them. Propose to the user that the existing variables be exposed as tokens by referencing them from `@theme`:
34
37
 
@@ -94,7 +97,7 @@ npx designsnitch check --format json
94
97
 
95
98
  Look at `designSystem` and `problems` in the result.
96
99
 
97
- - `designSystem.colorTokens` should match the number of `--color-*` tokens in the CSS. A 0 means the path is wrong or the tokens are in a format that cannot be read (only hex values and `var()` references to hex values are read).
100
+ - `designSystem.colorTokens` should match the number of `--color-*` tokens in the CSS. A 0 means the path is wrong or the tokens are in a format that cannot be read (hex, `rgb()`, `hsl()` and `oklch()` values, and `var()` references to them are read). A non-empty `problems` about a Tailwind config means the JavaScript config could not be loaded: its dependencies may not be installed.
98
101
  - `designSystem.components` should match the number of components you listed.
99
102
  - `problems` should be empty.
100
103
  - Exit code 2 with a message about a missing path means a path in the config is wrong.