designsnitch 0.3.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 +128 -33
- package/README.md +128 -33
- package/package.json +1 -1
- package/skills/designsnitch-check/SKILL.md +38 -13
- package/skills/designsnitch-eslint/SKILL.md +2 -0
- package/skills/designsnitch-palette/SKILL.md +11 -9
- package/skills/designsnitch-setup/SKILL.md +23 -8
- package/src/check.js +175 -35
- package/src/cli.js +2 -2
- package/src/colors.js +17 -12
- package/src/config.js +26 -3
- package/src/core/classes.js +13 -9
- package/src/core/color.js +133 -9
- package/src/core/css.js +42 -13
- package/src/core/named-colors.js +35 -0
- package/src/core/oklch.js +58 -0
- package/src/core/tokens.js +74 -6
- package/src/format.js +5 -3
- package/src/hook.js +1 -5
- package/src/messages.js +60 -12
- package/src/rules/color-unknown.js +8 -9
- package/src/rules/color-use-token.js +32 -14
- package/src/rules/load-tokens.js +203 -14
- package/src/rules/tailwind-config.js +77 -0
- package/src/rules/unchecked-colors.js +26 -0
- package/src/rules/use-ds-component.js +2 -2
- package/src/rules/visit-style.js +71 -0
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.
|
|
26
|
+
> **상태:** MVP(0.5.x). 지금은 색과 공용 컴포넌트를 검사합니다. 간격, 폰트 크기, radius는 아직 검사하지 않습니다([검사 범위](#검사-범위) 참고). 메시지는 기본이 영어이고 한국어로 바꿀 수 있습니다. 이 문서의 출력 예시는 한국어로 설정했을 때의 모습입니다. [언어](#언어)를 보세요.
|
|
27
27
|
|
|
28
28
|
## 시작하기
|
|
29
29
|
|
|
@@ -94,11 +94,13 @@ Codex, Gemini CLI, Grok Build는 새 프로젝트 훅을 승인하거나 프로
|
|
|
94
94
|
|
|
95
95
|
| 규칙 | 등급 | 잡는 것 |
|
|
96
96
|
| --- | --- | --- |
|
|
97
|
-
| `color-use-token` | 오류 | 토큰이 있는
|
|
98
|
-
| `color-unknown` | 경고 | 맞는 토큰이
|
|
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
|
-
|
|
101
|
+
직접 쓴 색이란 hex, 숫자를 그대로 적은 색 함수(`rgb()`, `hsl()`, `oklch()`), `white` 같은 색 이름입니다. 표기는 상관없습니다. `#3B82F6`, `rgb(59 130 246)`, `hsl(217 91% 60%)`는 검사에서 같은 색입니다.
|
|
102
|
+
|
|
103
|
+
오류에는 대신 쓸 것이 함께 나옵니다. JS와 TS 파일에서는 클래스나 컴포넌트이고, 인라인 스타일과 CSS 파일에서는 `var(--토큰)`입니다. Tailwind v4는 소스에서 `var()`로 쓴 테마 변수를 출력하므로, 인라인 스타일의 `var(--토큰)`도 같은 색으로 보입니다.
|
|
102
104
|
|
|
103
105
|
## 명령
|
|
104
106
|
|
|
@@ -171,7 +173,7 @@ Tailwind 기본 팔레트
|
|
|
171
173
|
| --- | --- |
|
|
172
174
|
| `hex 색` | hex 색을 많이 쓰인 순서로 보여줍니다. 쓰인 횟수와 파일 수가 함께 나옵니다. |
|
|
173
175
|
| `bg 2`, `text 1` | Tailwind 유틸리티별 사용 횟수입니다. `bg-[#3a11d8]`은 `bg`로 셉니다. |
|
|
174
|
-
| `문자열 1` | 문자열 전체가
|
|
176
|
+
| `문자열 1` | 문자열 전체가 색인 경우입니다. 인라인 스타일이나 차트 옵션이 여기에 들어갑니다. |
|
|
175
177
|
| `CSS 2` | CSS 선언에서 쓴 횟수입니다. JSON 출력에는 속성별로 나뉘어 들어갑니다. |
|
|
176
178
|
| `Tailwind 기본 팔레트` | `text-gray-700`처럼 Tailwind 기본 팔레트의 색을 이름으로 쓴 경우입니다. |
|
|
177
179
|
|
|
@@ -183,12 +185,26 @@ Tailwind 기본 팔레트
|
|
|
183
185
|
|
|
184
186
|
| 항목 | 설명 |
|
|
185
187
|
| --- | --- |
|
|
186
|
-
| `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. |
|
|
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
|
-
`components`를 생략하면 컴포넌트 검사를 하지 않습니다. 다른 경로의 설정 파일을 쓰려면 `--config <파일>`을 붙입니다.
|
|
194
|
+
`components`를 생략하면 컴포넌트 검사를 하지 않습니다. 다른 경로의 설정 파일을 쓰려면 `--config <파일>`을 붙입니다. 설정 파일 안의 경로는 설정 파일이 있는 디렉터리를 기준으로 풉니다.
|
|
195
|
+
|
|
196
|
+
값이 같은 토큰이 여럿이면, 그 값을 쓴 hex 색은 모두 후보가 여러 개가 되고 하나하나 사람이 정해야 합니다. `tokens`를 객체로 적으면 이 판단을 설정에서 한 번에 내릴 수 있습니다.
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
"tokens": {
|
|
200
|
+
"file": "app/globals.css",
|
|
201
|
+
"exclude": ["--color-legacy-*"],
|
|
202
|
+
"prefer": ["--color-brand-"]
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
- `exclude`는 기준에서 뺄 토큰입니다. 정확한 이름이나 `*`로 끝나는 접두어를 적습니다. 제외한 토큰만 가진 색은 토큰이 없는 색으로 봅니다. 다른 토큰이 제외한 토큰을 `var()`로 참조하는 것은 그대로 풉니다.
|
|
207
|
+
- `prefer`는 우선할 토큰 접두어를 순서대로 적습니다. 처음으로 맞는 접두어가 후보를 하나로 줄이면 그 후보만 남고, 바로 바꿀 수 있는 오류가 됩니다. 여러 개가 남으면 모두 두고 사람이 정합니다.
|
|
192
208
|
|
|
193
209
|
공용 컴포넌트가 태그의 일부 변형만 맡는 경우가 많습니다. `Input` 컴포넌트는 텍스트 입력은 맡아도 `<input type="file">`은 맡지 않을 수 있습니다. `when`에 컴포넌트가 맡는 속성 값을 적습니다. `null`은 그 속성이 없다는 뜻입니다.
|
|
194
210
|
|
|
@@ -197,14 +213,14 @@ Tailwind 기본 팔레트
|
|
|
197
213
|
```
|
|
198
214
|
|
|
199
215
|
- `<input type="file">`은 컴포넌트가 맡지 않으므로 보고하지 않습니다.
|
|
200
|
-
- `<input type="text">`와 `<input>`은
|
|
216
|
+
- `<input type="text">`와 `<input>`은 컴포넌트로 옮길 오류(`migrate`)로 보고합니다.
|
|
201
217
|
- `<input type={kind}>`와 `<input {...props}>`는 보고하되 `ask`로 표시합니다. 값을 실행할 때에야 알 수 있거나 spread가 값을 덮어쓸 수 있어서, 바꿔도 안전한지 알 수 없기 때문입니다.
|
|
202
218
|
|
|
203
219
|
토큰 CSS에서 읽는 것은 다음과 같습니다.
|
|
204
220
|
|
|
205
221
|
| 변수 | 쓰임 | 없을 때 |
|
|
206
222
|
| --- | --- | --- |
|
|
207
|
-
| `--color-*` | 색. 값이 hex
|
|
223
|
+
| `--color-*` | 색. 값이 hex, `rgb()`, `hsl()`, `oklch()` 색이거나, `var()`를 따라가면 그런 값이 나와야 합니다. | 직접 쓴 색이 모두 경고가 됩니다 |
|
|
208
224
|
|
|
209
225
|
아래 두 형태를 모두 읽습니다.
|
|
210
226
|
|
|
@@ -224,6 +240,18 @@ Tailwind 기본 팔레트
|
|
|
224
240
|
}
|
|
225
241
|
```
|
|
226
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
|
+
|
|
227
255
|
## 언어
|
|
228
256
|
|
|
229
257
|
메시지는 기본이 영어입니다. 한국어로 보려면 `designsnitch.config.json`에 `"lang": "ko"`를 적거나, 환경 변수 `DESIGNSNITCH_LANG=ko`를 설정하거나, `--lang ko`를 붙입니다. 여러 개를 함께 주면 `--lang`, 설정 파일, 환경 변수 순으로 우선합니다.
|
|
@@ -241,36 +269,79 @@ src/PayButton.tsx
|
|
|
241
269
|
8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
|
|
242
270
|
|
|
243
271
|
오류 2개, 경고 1개 (파일 3개 검사)
|
|
244
|
-
바로 바꿀 수 있는 것
|
|
272
|
+
바로 바꿀 수 있는 것 1건, 컴포넌트로 옮길 것 1건, 사람이 정해야 하는 것 1건 (결정 1개)
|
|
245
273
|
```
|
|
246
274
|
|
|
247
|
-
첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는
|
|
275
|
+
첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는 위반, 컴포넌트로 옮길 태그, 사람이 정해야 하는 위반이 각각 몇 건이고, 사람이 정할 것이 질문 몇 개로 묶이는지 알려줍니다.
|
|
248
276
|
|
|
249
|
-
`--format json`은 같은 결과를 구조화해서 출력합니다.
|
|
277
|
+
`--format json`은 같은 결과를 구조화해서 출력합니다. 아래 예시는 위반을 종류별로 하나씩만 남기고 나머지는 생략했습니다.
|
|
250
278
|
|
|
251
279
|
```json
|
|
252
280
|
{
|
|
253
|
-
"designSystem": { "colorTokens":
|
|
281
|
+
"designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
|
|
254
282
|
"problems": [],
|
|
255
283
|
"next": [
|
|
256
|
-
"action이 replace인
|
|
257
|
-
"action이
|
|
284
|
+
"action이 replace인 1건은 found를 candidates의 값으로 바꾸세요.",
|
|
285
|
+
"action이 migrate인 1건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못 하면 바꾸지 말고 사용자에게 물으세요.",
|
|
286
|
+
"변경하기 전에 decisions의 2건을 사용자에게 물으세요. 사용 횟수와 후보, 확인이 필요한 이유를 함께 알려 주세요.",
|
|
258
287
|
"고친 뒤 같은 명령을 다시 실행하세요."
|
|
259
288
|
],
|
|
260
|
-
"summary": { "files":
|
|
289
|
+
"summary": { "files": 1, "errors": 4, "warnings": 1 },
|
|
261
290
|
"violations": [
|
|
262
291
|
{
|
|
263
292
|
"file": "src/PayButton.tsx",
|
|
264
|
-
"line":
|
|
265
|
-
"column":
|
|
266
|
-
"endLine":
|
|
267
|
-
"endColumn":
|
|
293
|
+
"line": 3,
|
|
294
|
+
"column": 24,
|
|
295
|
+
"endLine": 3,
|
|
296
|
+
"endColumn": 36,
|
|
268
297
|
"rule": "color-use-token",
|
|
269
298
|
"severity": "error",
|
|
270
|
-
"message": "bg-[#3B82F6]의 색은 토큰 --color-
|
|
299
|
+
"message": "bg-[#3B82F6]의 색은 토큰 --color-brand-500의 값입니다. 대신 사용: bg-brand-500",
|
|
271
300
|
"found": "bg-[#3B82F6]",
|
|
272
|
-
"candidates": ["bg-
|
|
301
|
+
"candidates": ["bg-brand-500"],
|
|
302
|
+
"recommended": "bg-brand-500",
|
|
273
303
|
"action": "replace"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"file": "src/PayButton.tsx",
|
|
307
|
+
"line": 3,
|
|
308
|
+
"column": 37,
|
|
309
|
+
"endLine": 3,
|
|
310
|
+
"endColumn": 51,
|
|
311
|
+
"rule": "color-use-token",
|
|
312
|
+
"severity": "error",
|
|
313
|
+
"message": "text-[#484646]의 색은 토큰 --color-text-primary, --color-neutral-30의 값입니다. 대신 사용: text-text-primary, text-neutral-30",
|
|
314
|
+
"found": "text-[#484646]",
|
|
315
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
316
|
+
"recommended": "text-text-primary",
|
|
317
|
+
"action": "ask"
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
"decisions": [
|
|
321
|
+
{
|
|
322
|
+
"id": "decision-1",
|
|
323
|
+
"rule": "color-use-token",
|
|
324
|
+
"subject": "#484646",
|
|
325
|
+
"uses": 2,
|
|
326
|
+
"files": 1,
|
|
327
|
+
"locations": [
|
|
328
|
+
{ "file": "src/PayButton.tsx", "line": 3, "column": 37 },
|
|
329
|
+
{ "file": "src/PayButton.tsx", "line": 4, "column": 24 }
|
|
330
|
+
],
|
|
331
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
332
|
+
"recommended": "text-text-primary",
|
|
333
|
+
"reasons": ["multiple-candidates"]
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"id": "decision-2",
|
|
337
|
+
"rule": "color-unknown",
|
|
338
|
+
"subject": "#3b82f5",
|
|
339
|
+
"uses": 1,
|
|
340
|
+
"files": 1,
|
|
341
|
+
"locations": [{ "file": "src/PayButton.tsx", "line": 4, "column": 39 }],
|
|
342
|
+
"candidates": [],
|
|
343
|
+
"recommended": null,
|
|
344
|
+
"reasons": ["no-token"]
|
|
274
345
|
}
|
|
275
346
|
]
|
|
276
347
|
}
|
|
@@ -282,8 +353,11 @@ src/PayButton.tsx
|
|
|
282
353
|
| `problems` | 결과를 믿기 어렵게 만드는 설정 문제. 정상이면 빈 배열입니다. |
|
|
283
354
|
| `violations[].found` | 위반한 코드 조각 |
|
|
284
355
|
| `violations[].candidates` | 대신 쓸 클래스나 컴포넌트. 없으면 빈 배열입니다. |
|
|
285
|
-
| `violations[].
|
|
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`)가 있습니다. 많이 나오는 순서입니다. |
|
|
286
359
|
| `next` | 이 결과를 받은 에이전트가 할 일을 순서대로 적은 것 |
|
|
360
|
+
| `unchecked` | 검사하지 못한 다른 문자열 속 색의 개수(`colors`)와 파일 수(`files`). 하나라도 있으면 글 출력에 한 줄이 붙습니다. |
|
|
287
361
|
|
|
288
362
|
| 종료 코드 | 의미 |
|
|
289
363
|
| --- | --- |
|
|
@@ -353,6 +427,8 @@ export default [
|
|
|
353
427
|
];
|
|
354
428
|
```
|
|
355
429
|
|
|
430
|
+
설정 안의 경로는 ESLint의 작업 디렉터리를 기준으로 풉니다. 모노레포처럼 `designsnitch.config.json`이 `eslint.config.js` 옆에 있지 않으면 경로의 기준 디렉터리를 더합니다: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`.
|
|
431
|
+
|
|
356
432
|
같은 규칙 묶음을 `designsnitch.configs.recommended`로도 쓸 수 있습니다. 이미 위반이 많은 프로젝트에 넣으면 오류 등급 규칙 때문에 기존 lint 단계가 실패하므로, 먼저 `designsnitch check`로 개수를 확인하세요. 대체 후보는 ESLint의 제안으로 보고되어 에디터에서 빠른 수정으로 나타납니다. CSS 파일은 ESLint가 아니라 CLI에서만 검사합니다.
|
|
357
433
|
|
|
358
434
|
## 위반을 막는 방법
|
|
@@ -404,7 +480,20 @@ Grok Build에는 `npx designsnitch install --agent grok`이 `PostToolUse`와 `St
|
|
|
404
480
|
|
|
405
481
|
### Tailwind 기본 팔레트
|
|
406
482
|
|
|
407
|
-
|
|
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에서 기본 팔레트를 없앨 수 있습니다. 그러면 그런 클래스가 아예 동작하지 않습니다.
|
|
408
497
|
|
|
409
498
|
```css
|
|
410
499
|
@theme {
|
|
@@ -415,21 +504,27 @@ designsnitch는 `bg-blue-500` 같은 기본 팔레트 클래스를 위반으로
|
|
|
415
504
|
|
|
416
505
|
## 검사 범위
|
|
417
506
|
|
|
418
|
-
- **JS와 TS에서 보는 곳:** 문자열과 템플릿
|
|
419
|
-
- **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는
|
|
420
|
-
- **테마:** 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 그 토큰의 값으로 봅니다.
|
|
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`로 표시합니다.
|
|
421
510
|
- **수정:** designsnitch는 후보를 알려줄 뿐, 후보가 하나여도 코드를 직접 고치지 않습니다.
|
|
422
511
|
|
|
423
512
|
### 아직 안 되는 것
|
|
424
513
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
-
|
|
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 기본 테마의 값
|
|
428
524
|
- 토큰이 없는 색에 가장 가까운 토큰 제시
|
|
429
|
-
-
|
|
525
|
+
- JSX `style` 속성 밖의 스타일 객체. 예: `const style = { color: "#fff" }`
|
|
430
526
|
- SCSS 같은 전처리기
|
|
431
527
|
- 간격, 폰트 크기, radius. 이번 버전에서는 일부러 뺐습니다.
|
|
432
|
-
- `@apply` 안의 클래스
|
|
433
528
|
- 직접 만든 컴포넌트와 디자인 시스템 컴포넌트의 스타일 비교
|
|
434
529
|
- Claude Code, Codex, Gemini CLI, Grok Build가 아닌 에이전트에 훅 설치하기
|
|
435
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.
|
|
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,11 +94,13 @@ Severity follows one rule.
|
|
|
94
94
|
|
|
95
95
|
| Rule | Severity | What it catches |
|
|
96
96
|
| --- | --- | --- |
|
|
97
|
-
| `color-use-token` | Error | A
|
|
98
|
-
| `color-unknown` | Warning | A
|
|
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
|
-
|
|
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
|
+
|
|
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
|
|
104
106
|
|
|
@@ -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
|
|
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
|
|
|
@@ -182,12 +184,26 @@ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose to
|
|
|
182
184
|
|
|
183
185
|
| Field | Description |
|
|
184
186
|
| --- | --- |
|
|
185
|
-
| `tokens` | The CSS file that defines the tokens. Required. |
|
|
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
|
-
Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
|
|
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.
|
|
194
|
+
|
|
195
|
+
When several tokens share one value, every hex color with that value has several candidates, and each one needs a person's decision. The object form of `tokens` settles this once, in the config.
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
"tokens": {
|
|
199
|
+
"file": "app/globals.css",
|
|
200
|
+
"exclude": ["--color-legacy-*"],
|
|
201
|
+
"prefer": ["--color-brand-"]
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
- `exclude` drops tokens from the standard: exact names, or a prefix ending in `*`. A color that only an excluded token has counts as a color with no token. Other tokens can still refer to an excluded one with `var()`.
|
|
206
|
+
- `prefer` lists token prefixes in order. When the first prefix that matches leaves exactly one candidate, that candidate is the only one, and the error can be replaced right away. When it leaves several, they are all kept and a person decides.
|
|
191
207
|
|
|
192
208
|
A shared component often covers only some variants of a tag. An `Input` component may cover text fields but not `<input type="file">`. `when` lists the attribute values the component covers. `null` means the attribute is absent.
|
|
193
209
|
|
|
@@ -196,14 +212,14 @@ A shared component often covers only some variants of a tag. An `Input` componen
|
|
|
196
212
|
```
|
|
197
213
|
|
|
198
214
|
- `<input type="file">` is not reported, because the component does not cover it.
|
|
199
|
-
- `<input type="text">` and `<input>` are reported as errors
|
|
215
|
+
- `<input type="text">` and `<input>` are reported as errors to move to the component (`migrate`).
|
|
200
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.
|
|
201
217
|
|
|
202
218
|
This is what is read from the token CSS.
|
|
203
219
|
|
|
204
220
|
| Variable | Used for | When missing |
|
|
205
221
|
| --- | --- | --- |
|
|
206
|
-
| `--color-*` | Colors. The value must be a hex color, or a `var()` that leads to one. | Every
|
|
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 |
|
|
207
223
|
|
|
208
224
|
Both of these shapes work.
|
|
209
225
|
|
|
@@ -223,6 +239,18 @@ Both of these shapes work.
|
|
|
223
239
|
}
|
|
224
240
|
```
|
|
225
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
|
+
|
|
226
254
|
## Language
|
|
227
255
|
|
|
228
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.
|
|
@@ -240,36 +268,79 @@ src/PayButton.tsx
|
|
|
240
268
|
8:26 warning The color of bg-[#3B82F5] is not in the tokens. (color-unknown)
|
|
241
269
|
|
|
242
270
|
2 errors, 1 warning (3 files checked)
|
|
243
|
-
|
|
271
|
+
1 can be replaced right away, 1 to move to a component, 1 needs a person's decision (1 decision)
|
|
244
272
|
```
|
|
245
273
|
|
|
246
|
-
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
|
|
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.
|
|
247
275
|
|
|
248
|
-
`--format json` prints the same result as structured data.
|
|
276
|
+
`--format json` prints the same result as structured data. This example has one violation of each kind, and leaves the rest out.
|
|
249
277
|
|
|
250
278
|
```json
|
|
251
279
|
{
|
|
252
|
-
"designSystem": { "colorTokens":
|
|
280
|
+
"designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
|
|
253
281
|
"problems": [],
|
|
254
282
|
"next": [
|
|
255
|
-
"action \"replace\" (
|
|
256
|
-
"action \"
|
|
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.",
|
|
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.",
|
|
257
286
|
"After fixing, run the same command again."
|
|
258
287
|
],
|
|
259
|
-
"summary": { "files":
|
|
288
|
+
"summary": { "files": 1, "errors": 4, "warnings": 1 },
|
|
260
289
|
"violations": [
|
|
261
290
|
{
|
|
262
291
|
"file": "src/PayButton.tsx",
|
|
263
|
-
"line":
|
|
264
|
-
"column":
|
|
265
|
-
"endLine":
|
|
266
|
-
"endColumn":
|
|
292
|
+
"line": 3,
|
|
293
|
+
"column": 24,
|
|
294
|
+
"endLine": 3,
|
|
295
|
+
"endColumn": 36,
|
|
267
296
|
"rule": "color-use-token",
|
|
268
297
|
"severity": "error",
|
|
269
|
-
"message": "bg-[#3B82F6] has the same color as --color-
|
|
298
|
+
"message": "bg-[#3B82F6] has the same color as --color-brand-500. Use instead: bg-brand-500",
|
|
270
299
|
"found": "bg-[#3B82F6]",
|
|
271
|
-
"candidates": ["bg-
|
|
300
|
+
"candidates": ["bg-brand-500"],
|
|
301
|
+
"recommended": "bg-brand-500",
|
|
272
302
|
"action": "replace"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"file": "src/PayButton.tsx",
|
|
306
|
+
"line": 3,
|
|
307
|
+
"column": 37,
|
|
308
|
+
"endLine": 3,
|
|
309
|
+
"endColumn": 51,
|
|
310
|
+
"rule": "color-use-token",
|
|
311
|
+
"severity": "error",
|
|
312
|
+
"message": "text-[#484646] has the same color as --color-text-primary, --color-neutral-30. Use instead: text-text-primary, text-neutral-30",
|
|
313
|
+
"found": "text-[#484646]",
|
|
314
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
315
|
+
"recommended": "text-text-primary",
|
|
316
|
+
"action": "ask"
|
|
317
|
+
}
|
|
318
|
+
],
|
|
319
|
+
"decisions": [
|
|
320
|
+
{
|
|
321
|
+
"id": "decision-1",
|
|
322
|
+
"rule": "color-use-token",
|
|
323
|
+
"subject": "#484646",
|
|
324
|
+
"uses": 2,
|
|
325
|
+
"files": 1,
|
|
326
|
+
"locations": [
|
|
327
|
+
{ "file": "src/PayButton.tsx", "line": 3, "column": 37 },
|
|
328
|
+
{ "file": "src/PayButton.tsx", "line": 4, "column": 24 }
|
|
329
|
+
],
|
|
330
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
331
|
+
"recommended": "text-text-primary",
|
|
332
|
+
"reasons": ["multiple-candidates"]
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"id": "decision-2",
|
|
336
|
+
"rule": "color-unknown",
|
|
337
|
+
"subject": "#3b82f5",
|
|
338
|
+
"uses": 1,
|
|
339
|
+
"files": 1,
|
|
340
|
+
"locations": [{ "file": "src/PayButton.tsx", "line": 4, "column": 39 }],
|
|
341
|
+
"candidates": [],
|
|
342
|
+
"recommended": null,
|
|
343
|
+
"reasons": ["no-token"]
|
|
273
344
|
}
|
|
274
345
|
]
|
|
275
346
|
}
|
|
@@ -281,8 +352,11 @@ The first line shows how many tokens and components were read from the config. A
|
|
|
281
352
|
| `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
|
|
282
353
|
| `violations[].found` | The offending piece of code |
|
|
283
354
|
| `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
|
|
284
|
-
| `violations[].
|
|
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. |
|
|
285
358
|
| `next` | What an agent should do with this result, in order |
|
|
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. |
|
|
286
360
|
|
|
287
361
|
| Exit code | Meaning |
|
|
288
362
|
| --- | --- |
|
|
@@ -352,6 +426,8 @@ export default [
|
|
|
352
426
|
];
|
|
353
427
|
```
|
|
354
428
|
|
|
429
|
+
Paths in the settings are resolved from ESLint's working directory. If `designsnitch.config.json` is not next to `eslint.config.js`, as in a monorepo, add the directory the paths are relative to: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`.
|
|
430
|
+
|
|
355
431
|
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.
|
|
356
432
|
|
|
357
433
|
## Blocking violations
|
|
@@ -403,7 +479,20 @@ The command reads an optional JSON object from stdin (`tool_input.file_path`, `h
|
|
|
403
479
|
|
|
404
480
|
### Tailwind's default palette
|
|
405
481
|
|
|
406
|
-
|
|
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.
|
|
407
496
|
|
|
408
497
|
```css
|
|
409
498
|
@theme {
|
|
@@ -414,21 +503,27 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
|
|
|
414
503
|
|
|
415
504
|
## Scope
|
|
416
505
|
|
|
417
|
-
- **Where it looks in JS and TS:** string literals and template literals
|
|
418
|
-
- **Where it looks in CSS:**
|
|
419
|
-
- **Themes:** when a token has different values per theme, all of them count as that token's value. Replacing a
|
|
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`.
|
|
420
509
|
- **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
|
|
421
510
|
|
|
422
511
|
### Not supported yet
|
|
423
512
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
-
|
|
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
|
|
427
523
|
- The nearest token for a color that has none
|
|
428
|
-
-
|
|
524
|
+
- Style objects outside a JSX `style` attribute, such as `const style = { color: "#fff" }`
|
|
429
525
|
- SCSS and other preprocessors
|
|
430
526
|
- Spacing, font size and radius. They were left out of this version on purpose.
|
|
431
|
-
- Classes inside `@apply`
|
|
432
527
|
- Comparing a hand-made component's styles with the design system component
|
|
433
528
|
- Installing the hook for agents other than Claude Code, Codex, Gemini CLI and Grok Build
|
|
434
529
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsnitch",
|
|
3
|
-
"version": "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",
|