designsnitch 0.3.0 → 0.4.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
@@ -94,11 +94,11 @@ Codex, Gemini CLI, Grok Build는 새 프로젝트 훅을 승인하거나 프로
94
94
 
95
95
  | 규칙 | 등급 | 잡는 것 |
96
96
  | --- | --- | --- |
97
- | `color-use-token` | 오류 | 토큰이 있는 hex 색을 임의 값(`bg-[#3B82F6]`)이나 CSS 선언(`color: #3B82F6`)에 직접 씀 |
97
+ | `color-use-token` | 오류 | 토큰이 있는 hex 색을 임의 값(`bg-[#3B82F6]`), 인라인 스타일(`style={{ color: "#3B82F6" }}`), CSS 선언(`color: #3B82F6`)에 직접 씀 |
98
98
  | `color-unknown` | 경고 | 맞는 토큰이 없는 hex 색 |
99
99
  | `use-ds-component` | 오류 | 공용 컴포넌트가 대체하는 `<button>` 같은 raw 태그를 디자인 시스템 경로 밖에서 씀 |
100
100
 
101
- 오류에는 대신 쓸 것이 함께 나옵니다. JS와 TS 파일에서는 클래스나 컴포넌트이고, CSS 파일에서는 `var(--토큰)`입니다.
101
+ 오류에는 대신 쓸 것이 함께 나옵니다. JS와 TS 파일에서는 클래스나 컴포넌트이고, 인라인 스타일과 CSS 파일에서는 `var(--토큰)`입니다. Tailwind v4는 소스에서 `var()`로 쓴 테마 변수를 출력하므로, 인라인 스타일의 `var(--토큰)`도 같은 색으로 보입니다.
102
102
 
103
103
  ## 명령
104
104
 
@@ -183,12 +183,25 @@ Tailwind 기본 팔레트
183
183
 
184
184
  | 항목 | 설명 |
185
185
  | --- | --- |
186
- | `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. |
186
+ | `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. 경로를 적거나, `file`과 선택 항목 `exclude`, `prefer`를 담은 객체로 적습니다(아래 참고). |
187
187
  | `components.path` | 디자인 시스템 컴포넌트가 있는 경로입니다. 이 안에서는 raw 태그를 써도 됩니다. |
188
188
  | `components.replaces` | raw 태그와 그것을 대체하는 컴포넌트입니다. 한 태그를 대체하는 컴포넌트가 여러 개면 배열로 적습니다. 컴포넌트가 태그의 일부 변형만 맡으면 `{ "component": ..., "when": { ... } }`로 적습니다(아래 참고). |
189
189
  | `lang` | 메시지의 언어입니다. `en`(기본) 또는 `ko`입니다. |
190
190
 
191
- `components`를 생략하면 컴포넌트 검사를 하지 않습니다. 다른 경로의 설정 파일을 쓰려면 `--config <파일>`을 붙입니다.
191
+ `components`를 생략하면 컴포넌트 검사를 하지 않습니다. 다른 경로의 설정 파일을 쓰려면 `--config <파일>`을 붙입니다. 설정 파일 안의 경로는 설정 파일이 있는 디렉터리를 기준으로 풉니다.
192
+
193
+ 값이 같은 토큰이 여럿이면, 그 값을 쓴 hex 색은 모두 후보가 여러 개가 되고 하나하나 사람이 정해야 합니다. `tokens`를 객체로 적으면 이 판단을 설정에서 한 번에 내릴 수 있습니다.
194
+
195
+ ```json
196
+ "tokens": {
197
+ "file": "app/globals.css",
198
+ "exclude": ["--color-legacy-*"],
199
+ "prefer": ["--color-brand-"]
200
+ }
201
+ ```
202
+
203
+ - `exclude`는 기준에서 뺄 토큰입니다. 정확한 이름이나 `*`로 끝나는 접두어를 적습니다. 제외한 토큰만 가진 색은 토큰이 없는 색으로 봅니다. 다른 토큰이 제외한 토큰을 `var()`로 참조하는 것은 그대로 풉니다.
204
+ - `prefer`는 우선할 토큰 접두어를 순서대로 적습니다. 처음으로 맞는 접두어가 후보를 하나로 줄이면 그 후보만 남고, 바로 바꿀 수 있는 오류가 됩니다. 여러 개가 남으면 모두 두고 사람이 정합니다.
192
205
 
193
206
  공용 컴포넌트가 태그의 일부 변형만 맡는 경우가 많습니다. `Input` 컴포넌트는 텍스트 입력은 맡아도 `<input type="file">`은 맡지 않을 수 있습니다. `when`에 컴포넌트가 맡는 속성 값을 적습니다. `null`은 그 속성이 없다는 뜻입니다.
194
207
 
@@ -241,36 +254,78 @@ src/PayButton.tsx
241
254
  8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
242
255
 
243
256
  오류 2개, 경고 1개 (파일 3개 검사)
244
- 바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건
257
+ 바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건 (결정 1개)
245
258
  ```
246
259
 
247
- 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는 위반과 사람이 정해야 하는 위반이 각각 몇 건인지 알려줍니다.
260
+ 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 이유를 알려줍니다. 마지막 줄은 바로 바꿀 수 있는 위반과 사람이 정해야 하는 위반이 각각 몇 건이고, 사람이 정할 것이 질문 몇 개로 묶이는지 알려줍니다.
248
261
 
249
- `--format json`은 같은 결과를 구조화해서 출력합니다.
262
+ `--format json`은 같은 결과를 구조화해서 출력합니다. 아래 예시는 위반을 종류별로 하나씩만 남기고 나머지는 생략했습니다.
250
263
 
251
264
  ```json
252
265
  {
253
- "designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
266
+ "designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
254
267
  "problems": [],
255
268
  "next": [
256
269
  "action이 replace인 2건은 found를 candidates의 값으로 바꾸세요.",
257
- "action이 ask인 1건은 바꾸지 말고 사용자에게 물으세요. ...",
270
+ "변경하기 전에 decisions의 2건을 사용자에게 물으세요. 사용 횟수와 후보, 확인이 필요한 이유를 함께 알려 주세요.",
258
271
  "고친 뒤 같은 명령을 다시 실행하세요."
259
272
  ],
260
- "summary": { "files": 3, "errors": 2, "warnings": 1 },
273
+ "summary": { "files": 1, "errors": 4, "warnings": 1 },
261
274
  "violations": [
262
275
  {
263
276
  "file": "src/PayButton.tsx",
264
- "line": 7,
265
- "column": 55,
266
- "endLine": 7,
267
- "endColumn": 67,
277
+ "line": 3,
278
+ "column": 24,
279
+ "endLine": 3,
280
+ "endColumn": 36,
268
281
  "rule": "color-use-token",
269
282
  "severity": "error",
270
- "message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
283
+ "message": "bg-[#3B82F6]의 색은 토큰 --color-brand-500의 값입니다. 대신 사용: bg-brand-500",
271
284
  "found": "bg-[#3B82F6]",
272
- "candidates": ["bg-primary-500"],
285
+ "candidates": ["bg-brand-500"],
286
+ "recommended": "bg-brand-500",
273
287
  "action": "replace"
288
+ },
289
+ {
290
+ "file": "src/PayButton.tsx",
291
+ "line": 3,
292
+ "column": 37,
293
+ "endLine": 3,
294
+ "endColumn": 51,
295
+ "rule": "color-use-token",
296
+ "severity": "error",
297
+ "message": "text-[#484646]의 색은 토큰 --color-text-primary, --color-neutral-30의 값입니다. 대신 사용: text-text-primary, text-neutral-30",
298
+ "found": "text-[#484646]",
299
+ "candidates": ["text-text-primary", "text-neutral-30"],
300
+ "recommended": "text-text-primary",
301
+ "action": "ask"
302
+ }
303
+ ],
304
+ "decisions": [
305
+ {
306
+ "id": "decision-1",
307
+ "rule": "color-use-token",
308
+ "subject": "#484646",
309
+ "uses": 2,
310
+ "files": 1,
311
+ "locations": [
312
+ { "file": "src/PayButton.tsx", "line": 3, "column": 37 },
313
+ { "file": "src/PayButton.tsx", "line": 4, "column": 24 }
314
+ ],
315
+ "candidates": ["text-text-primary", "text-neutral-30"],
316
+ "recommended": "text-text-primary",
317
+ "reasons": ["multiple-candidates"]
318
+ },
319
+ {
320
+ "id": "decision-2",
321
+ "rule": "color-unknown",
322
+ "subject": "#3b82f5",
323
+ "uses": 1,
324
+ "files": 1,
325
+ "locations": [{ "file": "src/PayButton.tsx", "line": 4, "column": 39 }],
326
+ "candidates": [],
327
+ "recommended": null,
328
+ "reasons": ["no-token"]
274
329
  }
275
330
  ]
276
331
  }
@@ -282,8 +337,11 @@ src/PayButton.tsx
282
337
  | `problems` | 결과를 믿기 어렵게 만드는 설정 문제. 정상이면 빈 배열입니다. |
283
338
  | `violations[].found` | 위반한 코드 조각 |
284
339
  | `violations[].candidates` | 대신 쓸 클래스나 컴포넌트. 없으면 빈 배열입니다. |
340
+ | `violations[].recommended` | 색을 쓰는 용도에 맞는 후보입니다. `text-` 클래스면 텍스트용 이름의 토큰, 테두리면 테두리용 이름의 토큰입니다. 맞는 후보가 정확히 하나일 때만 채우고, 추천일 뿐이라 `ask`는 그대로 `ask`입니다. `replace`면 그 후보입니다. |
285
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`)가 있습니다. 많이 나오는 순서입니다. |
286
343
  | `next` | 이 결과를 받은 에이전트가 할 일을 순서대로 적은 것 |
344
+ | `unchecked` | 검사하지 못한 다른 문자열 속 hex 색의 개수(`hexColors`)와 파일 수(`files`). 하나라도 있으면 글 출력에 한 줄이 붙습니다. |
287
345
 
288
346
  | 종료 코드 | 의미 |
289
347
  | --- | --- |
@@ -353,6 +411,8 @@ export default [
353
411
  ];
354
412
  ```
355
413
 
414
+ 설정 안의 경로는 ESLint의 작업 디렉터리를 기준으로 풉니다. 모노레포처럼 `designsnitch.config.json`이 `eslint.config.js` 옆에 있지 않으면 경로의 기준 디렉터리를 더합니다: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`.
415
+
356
416
  같은 규칙 묶음을 `designsnitch.configs.recommended`로도 쓸 수 있습니다. 이미 위반이 많은 프로젝트에 넣으면 오류 등급 규칙 때문에 기존 lint 단계가 실패하므로, 먼저 `designsnitch check`로 개수를 확인하세요. 대체 후보는 ESLint의 제안으로 보고되어 에디터에서 빠른 수정으로 나타납니다. CSS 파일은 ESLint가 아니라 CLI에서만 검사합니다.
357
417
 
358
418
  ## 위반을 막는 방법
@@ -415,8 +475,8 @@ designsnitch는 `bg-blue-500` 같은 기본 팔레트 클래스를 위반으로
415
475
 
416
476
  ## 검사 범위
417
477
 
418
- - **JS와 TS에서 보는 곳:** 문자열과 템플릿 리터럴입니다. `className`과 `cn()`, `clsx()`, `cva()`의 인자가 여기에 들어갑니다. 주석은 보지 않습니다.
419
- - **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는 hex 색입니다. 변수를 정의하는 선언(`--이름: ...`)은 토큰을 정의하는 곳이므로 건너뜁니다. CSS에서는 아직 색만 검사합니다.
478
+ - **JS와 TS에서 보는 곳:** 문자열과 템플릿 리터럴 안의 임의 값 색 클래스(`className`과 `cn()`, `clsx()`, `cva()`의 인자 포함)와, JSX `style` 객체에 문자열로 적은 hex 색입니다. 주석은 보지 않습니다. 테마 객체나 차트 옵션 같은 다른 문자열의 hex 색은 코드만 보고 용도를 알 수 없어 검사하지 않습니다. 대신 있다는 것을 알 수 있도록 `unchecked`에 개수를 세고, `designsnitch colors`로 목록을 볼 수 있습니다.
479
+ - **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는 hex 색입니다. 토큰 CSS에서는 변수를 정의하는 선언(`--이름: ...`)을 토큰을 정의하는 곳으로 보고 건너뜁니다. 다른 CSS 파일에서는 변수 선언도 일반 선언처럼 검사합니다. CSS에서는 아직 색만 검사합니다.
420
480
  - **테마:** 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 그 토큰의 값으로 봅니다. hex 색을 그런 토큰으로 바꾸면 다른 테마에서 색이 바뀌므로 `ask`로 표시합니다.
421
481
  - **수정:** designsnitch는 후보를 알려줄 뿐, 후보가 하나여도 코드를 직접 고치지 않습니다.
422
482
 
@@ -426,7 +486,7 @@ designsnitch는 `bg-blue-500` 같은 기본 팔레트 클래스를 위반으로
426
486
  - Tailwind 기본 테마의 값. 프로젝트의 토큰 CSS에 적힌 값만 읽습니다.
427
487
  - Tailwind v3(`tailwind.config.js`)
428
488
  - 토큰이 없는 색에 가장 가까운 토큰 제시
429
- - 인라인 스타일
489
+ - 계산되는 인라인 스타일 값. 예: `color: active ? "#3B82F6" : "#fff"`
430
490
  - SCSS 같은 전처리기
431
491
  - 간격, 폰트 크기, radius. 이번 버전에서는 일부러 뺐습니다.
432
492
  - `@apply` 안의 클래스
package/README.md CHANGED
@@ -94,11 +94,11 @@ 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]`) or in a CSS declaration (`color: #3B82F6`) |
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
98
  | `color-unknown` | Warning | A hex color 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
- Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in CSS files.
101
+ 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
102
 
103
103
  ## Commands
104
104
 
@@ -182,12 +182,25 @@ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose to
182
182
 
183
183
  | Field | Description |
184
184
  | --- | --- |
185
- | `tokens` | The CSS file that defines the tokens. Required. |
185
+ | `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
186
  | `components.path` | The directory that holds the design system components. Raw tags are allowed inside it. |
187
187
  | `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). |
188
188
  | `lang` | The language of the messages: `en` (default) or `ko`. |
189
189
 
190
- Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
190
+ 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.
191
+
192
+ 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.
193
+
194
+ ```json
195
+ "tokens": {
196
+ "file": "app/globals.css",
197
+ "exclude": ["--color-legacy-*"],
198
+ "prefer": ["--color-brand-"]
199
+ }
200
+ ```
201
+
202
+ - `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()`.
203
+ - `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
204
 
192
205
  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
206
 
@@ -240,36 +253,78 @@ src/PayButton.tsx
240
253
  8:26 warning The color of bg-[#3B82F5] is not in the tokens. (color-unknown)
241
254
 
242
255
  2 errors, 1 warning (3 files checked)
243
- 2 can be replaced right away, 1 needs a person's decision
256
+ 2 can be replaced right away, 1 needs a person's decision (1 decision)
244
257
  ```
245
258
 
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 and how many need a person's decision.
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.
247
260
 
248
- `--format json` prints the same result as structured data.
261
+ `--format json` prints the same result as structured data. This example has one violation of each kind, and leaves the rest out.
249
262
 
250
263
  ```json
251
264
  {
252
- "designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
265
+ "designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
253
266
  "problems": [],
254
267
  "next": [
255
268
  "action \"replace\" (2): replace found with the value in candidates.",
256
- "action \"ask\" (1): do not change these. Ask the user, and include how often and for what each color is used, which `designsnitch colors` shows.",
269
+ "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
270
  "After fixing, run the same command again."
258
271
  ],
259
- "summary": { "files": 3, "errors": 2, "warnings": 1 },
272
+ "summary": { "files": 1, "errors": 4, "warnings": 1 },
260
273
  "violations": [
261
274
  {
262
275
  "file": "src/PayButton.tsx",
263
- "line": 7,
264
- "column": 55,
265
- "endLine": 7,
266
- "endColumn": 67,
276
+ "line": 3,
277
+ "column": 24,
278
+ "endLine": 3,
279
+ "endColumn": 36,
267
280
  "rule": "color-use-token",
268
281
  "severity": "error",
269
- "message": "bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500",
282
+ "message": "bg-[#3B82F6] has the same color as --color-brand-500. Use instead: bg-brand-500",
270
283
  "found": "bg-[#3B82F6]",
271
- "candidates": ["bg-primary-500"],
284
+ "candidates": ["bg-brand-500"],
285
+ "recommended": "bg-brand-500",
272
286
  "action": "replace"
287
+ },
288
+ {
289
+ "file": "src/PayButton.tsx",
290
+ "line": 3,
291
+ "column": 37,
292
+ "endLine": 3,
293
+ "endColumn": 51,
294
+ "rule": "color-use-token",
295
+ "severity": "error",
296
+ "message": "text-[#484646] has the same color as --color-text-primary, --color-neutral-30. Use instead: text-text-primary, text-neutral-30",
297
+ "found": "text-[#484646]",
298
+ "candidates": ["text-text-primary", "text-neutral-30"],
299
+ "recommended": "text-text-primary",
300
+ "action": "ask"
301
+ }
302
+ ],
303
+ "decisions": [
304
+ {
305
+ "id": "decision-1",
306
+ "rule": "color-use-token",
307
+ "subject": "#484646",
308
+ "uses": 2,
309
+ "files": 1,
310
+ "locations": [
311
+ { "file": "src/PayButton.tsx", "line": 3, "column": 37 },
312
+ { "file": "src/PayButton.tsx", "line": 4, "column": 24 }
313
+ ],
314
+ "candidates": ["text-text-primary", "text-neutral-30"],
315
+ "recommended": "text-text-primary",
316
+ "reasons": ["multiple-candidates"]
317
+ },
318
+ {
319
+ "id": "decision-2",
320
+ "rule": "color-unknown",
321
+ "subject": "#3b82f5",
322
+ "uses": 1,
323
+ "files": 1,
324
+ "locations": [{ "file": "src/PayButton.tsx", "line": 4, "column": 39 }],
325
+ "candidates": [],
326
+ "recommended": null,
327
+ "reasons": ["no-token"]
273
328
  }
274
329
  ]
275
330
  }
@@ -281,8 +336,11 @@ The first line shows how many tokens and components were read from the config. A
281
336
  | `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
282
337
  | `violations[].found` | The offending piece of code |
283
338
  | `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. |
284
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. |
285
342
  | `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. |
286
344
 
287
345
  | Exit code | Meaning |
288
346
  | --- | --- |
@@ -352,6 +410,8 @@ export default [
352
410
  ];
353
411
  ```
354
412
 
413
+ 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" } }`.
414
+
355
415
  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
416
 
357
417
  ## Blocking violations
@@ -414,8 +474,8 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
414
474
 
415
475
  ## Scope
416
476
 
417
- - **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.
418
- - **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.
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.
419
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`.
420
480
  - **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
421
481
 
@@ -425,7 +485,7 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
425
485
  - Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
426
486
  - Tailwind v3 (`tailwind.config.js`)
427
487
  - The nearest token for a color that has none
428
- - Inline styles
488
+ - Inline style values that are computed, such as `color: active ? "#3B82F6" : "#fff"`
429
489
  - SCSS and other preprocessors
430
490
  - Spacing, font size and radius. They were left out of this version on purpose.
431
491
  - Classes inside `@apply`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designsnitch",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",
@@ -28,10 +28,10 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
28
28
  "problems": [],
29
29
  "next": [
30
30
  "action \"replace\" (1): replace found with the value in candidates.",
31
- "action \"ask\" (1): do not change these. Ask the user, and include how often and for what each color is used, which `designsnitch colors` shows.",
31
+ "Before making changes, ask the user about the 1 entry in decisions. Include how often each comes up, the candidates, and the reasons for asking.",
32
32
  "After fixing, run the same command again."
33
33
  ],
34
- "summary": { "files": 1, "errors": 2, "warnings": 0 },
34
+ "summary": { "files": 2, "errors": 3, "warnings": 0 },
35
35
  "violations": [
36
36
  {
37
37
  "file": "src/features/checkout/PayButton.tsx",
@@ -44,21 +44,41 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
44
44
  "message": "bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500",
45
45
  "found": "bg-[#3B82F6]",
46
46
  "candidates": ["bg-primary-500"],
47
+ "recommended": "bg-primary-500",
47
48
  "action": "replace"
48
49
  }
50
+ ],
51
+ "decisions": [
52
+ {
53
+ "id": "decision-1",
54
+ "rule": "color-use-token",
55
+ "subject": "#484646",
56
+ "uses": 2,
57
+ "files": 2,
58
+ "locations": [
59
+ { "file": "src/features/checkout/PayButton.tsx", "line": 9, "column": 14 },
60
+ { "file": "src/features/checkout/Summary.tsx", "line": 4, "column": 20 }
61
+ ],
62
+ "candidates": ["text-text-primary", "text-neutral-30"],
63
+ "recommended": "text-text-primary",
64
+ "reasons": ["multiple-candidates"]
65
+ }
49
66
  ]
50
67
  }
51
68
  ```
52
69
 
53
70
  - `next` lists what to do, in order. `next` and `message` are sentences, in English or in Korean depending on the project's `lang` setting. The fields below carry the same information, so you never need to parse them.
54
71
  - `action` says how to handle each violation. Section 3 covers each value.
55
- - `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 `.css` files.
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
+ - `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.
56
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.
57
77
  - A non-empty `problems` means the config is broken and the results cannot be trusted. Tell the user before fixing anything.
58
78
 
59
79
  | `rule` | Severity | Meaning |
60
80
  | --- | --- | --- |
61
- | `color-use-token` | error | A hex color that has a token was written as an arbitrary value, or directly in a CSS declaration. |
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. |
62
82
  | `color-unknown` | warning | A hex color with no matching token. |
63
83
  | `use-ds-component` | error | A raw tag was used outside the design system directory although a shared component replaces it. |
64
84
  | `parse-error` | error | The file could not be parsed. |
@@ -75,14 +95,18 @@ For `use-ds-component`, replacing means more than renaming the tag. Read the des
75
95
 
76
96
  ## 4. Ask so the user can decide
77
97
 
78
- Deciding is the user's job. Your job is to make the decision easy. Do not hand over a bare list of violations. For each decision, give:
98
+ Deciding is the user's job. Your job is to make the decision easy. Do not hand over a bare list of violations. Take the questions from `decisions`, most used first. For each one, give:
79
99
 
80
100
  1. **What has to be decided**, in one sentence.
81
- 2. **The facts.** Run `npx designsnitch colors --format json` and report how often the color is used, in how many files, and for what (text, background, border). Open one or two of the locations if the use is unclear.
101
+ 2. **The facts.** `uses`, `files` and `locations` say how often and where. For a color, run `npx designsnitch colors --format json` to see what it is used for (text, background, border) and which tokens are close to it. Open one or two of the locations if the use is unclear.
82
102
  3. **What each choice changes.** Say whether the screen will look different, and how many places would be edited.
83
- 4. **Your recommendation and why.**
103
+ 4. **Your recommendation and why.** Start from `recommended` when it is set, and say why it fits.
104
+
105
+ `decisions` already groups the same question. Thirty uses of one unknown color are one decision, not thirty.
106
+
107
+ If many decisions are the same choice between two token families, for example `--color-brand-500` and `--color-blue-500` every time, the config can settle it once. Tell the user that `prefer` in the `tokens` setting of `designsnitch.config.json` would pick the family, and ask before changing the config.
84
108
 
85
- Group decisions that are the same question. Thirty uses of one unknown color are one decision, not thirty.
109
+ If most decisions are `no-token`, the project is missing tokens rather than making mistakes. Suggest the `designsnitch-palette` skill instead of asking about each color.
86
110
 
87
111
  An example for an error with several candidates:
88
112
 
@@ -99,6 +99,8 @@ export default [
99
99
  ];
100
100
  ```
101
101
 
102
+ Paths in `designsnitch.config.json` are relative to the config file. ESLint resolves them from its own working directory, so this works when both files sit in the project root. If the config file is somewhere else, as in a monorepo where ESLint runs from the repository root, add the directory the paths are relative to: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`. The same applies to 3A.
103
+
102
104
  If `package.json` has `"type": "module"`, name the file `eslint.config.js`. Otherwise name it `eslint.config.mjs`.
103
105
 
104
106
  Add a lint script if the project has none.
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: designsnitch-palette
3
- description: Create color tokens for a React/Next.js + Tailwind project that has none, based on the colors its code already uses. Use when a project has no color tokens or palette, when `designsnitch check` reports that no color token could be read, or when the user asks to derive a color palette or color tokens from existing code.
3
+ description: Create color tokens for a React/Next.js + Tailwind project that has none or too few, based on the colors its code already uses. Use when a project has no color tokens or palette, when `designsnitch check` reports that no color token could be read, when most colors in the code have no token (many color-unknown warnings), or when the user asks to derive a color palette or color tokens from existing code.
4
4
  ---
5
5
 
6
6
  # designsnitch-palette
7
7
 
8
- Some projects have no color tokens: colors are written straight into the code as `bg-[#3B82F6]`, `text-gray-700` or `style={{ color: "#3B82F6" }}`. designsnitch has nothing to check such code against. This skill turns the colors the code already uses into a set of tokens.
8
+ Some projects have no color tokens: colors are written straight into the code as `bg-[#3B82F6]`, `text-gray-700` or `style={{ color: "#3B82F6" }}`. designsnitch has nothing to check such code against. Others have a few tokens, while most colors in the code have none, and every one of those is a warning. This skill turns the colors the code already uses into a set of tokens, or fills the gaps next to the tokens that exist.
9
9
 
10
10
  The CLI collects the colors. You analyze them and propose tokens. The user decides. Nothing is written before the user approves, because the tokens become the standard all UI code is judged against.
11
11
 
@@ -46,7 +46,7 @@ This works without a config file. Pass paths to limit it to part of the project.
46
46
  - `colors` are hex colors, most used first. `utilities` counts uses per Tailwind utility (`bg-[#484646]` counts under `bg`). `literals` counts strings that are a hex color on their own, such as inline styles and chart options. `properties` counts uses per CSS property in `.css` files.
47
47
  - `palette` are colors from Tailwind's default palette used by name, such as `text-gray-700`.
48
48
  - `examples` gives a few locations, each in a different file. Open them when you need to see how a color is used.
49
- - If a config file exists, each color also has `tokens`: the tokens that already have this value. Colors with a non-empty `tokens` are already covered. Work on the rest.
49
+ - If a config file exists, each color also has `tokens`: the tokens that already have this value. Colors with a non-empty `tokens` are already covered. Work on the rest. A color one step away from an existing token is a near duplicate of that token (see below), not a new color.
50
50
 
51
51
  ## 2. Analyze
52
52
 
@@ -58,6 +58,8 @@ Go through `colors` from the top and sort each color into one of these.
58
58
 
59
59
  **The long tail.** It is used once or twice. Do not give it a token by default. List these for the user.
60
60
 
61
+ **A scattered palette.** Sometimes most colors are long tail: dozens of grays, each used once or twice and each a little different, such as `#929b93`, `#8e978f` and `#919a92`. This is common in code an AI wrote one screen at a time. Proposing tokens only for the few colors used most covers almost nothing. Group the colors instead: put colors that look the same at a glance in one group, and treat each group as one color with the summed uses. If an existing token sits in a group, the group belongs to that token. Then sort the groups as above. Tell the user that merging a group changes what is rendered by a small amount, show the spread of each group (its lightest and darkest value), and let them decide group by group.
62
+
61
63
  Then work out what each color of its own is for. `utilities` and `properties` show this.
62
64
 
63
65
  | Mostly used with | Likely role |
@@ -80,14 +82,14 @@ Show the user a proposal before writing anything.
80
82
 
81
83
  Naming:
82
84
 
83
- - If the project already has CSS variables or a naming habit, follow it.
85
+ - If the project already has tokens, CSS variables or a naming habit, follow it. New tokens sit next to the existing ones and use the same pattern.
84
86
  - Otherwise name a color by its role when it has a clear one (`--color-text-primary`, `--color-border-default`, `--color-surface`), and by a scale when it is a general color (`--color-primary-500`, `--color-neutral-200`).
85
87
  - Every token starts with `--color-`. Tailwind turns `--color-text-primary` into classes such as `text-text-primary` and `bg-text-primary`.
86
88
  - Do not reuse a name from Tailwind's default palette, such as `--color-blue-500`, unless the user wants to override that color.
87
89
 
88
90
  With the table, tell the user:
89
91
 
90
- - How much the proposed tokens cover: the share of all uses, for example "12 tokens cover 81% of uses".
92
+ - How much the proposed tokens cover: the share of all uses, for example "12 tokens cover 81% of uses". If the share is small, say why, and check whether the colors are scattered (see above) before handing over a proposal that covers little.
91
93
  - The near duplicates you want to merge, each with both values and their use counts.
92
94
  - The long tail you left out.
93
95
  - The default palette colors in use, and the question of whether to keep them.
@@ -130,7 +132,7 @@ Tell the user what the first check found. Every place that writes a tokenized co
130
132
  Two kinds of use stay as they are:
131
133
 
132
134
  - Near duplicates the user chose to merge still have their old value in the code. They show up as `color-unknown` warnings. Replacing them changes what is rendered, so do it only for the merges the user approved.
133
- - Hex colors in string literals and default palette classes are not flagged by the check yet.
135
+ - Hex colors in strings other than classes and inline styles, such as theme objects, and default palette classes are not flagged by the check. The check counts the former in `unchecked`.
134
136
 
135
137
  ## What not to do
136
138
 
@@ -53,6 +53,8 @@ Read the files in that directory and find the components whose root element is a
53
53
 
54
54
  Leave out components that only happen to contain a raw tag deep inside, such as a modal that has a close button. List the components a developer should reach for instead of writing the tag.
55
55
 
56
+ Open each component before you list it, and check that it fits the ordinary uses of the tag. A component built for one look or one kind of content does not replace the tag in general. An `IconButton` that sizes and styles itself for a single icon is not what a text button should become, and listing it tells every `<button>` with text to switch to it. If the component can only replace some uses, and `when` cannot tell those uses apart by an attribute value, leave it out and tell the user why. Listing a wrong replacement is worse than listing none: it turns correct code into errors.
57
+
56
58
  Check which variants of the tag each component covers. An `Input` built for text fields does not replace `<input type="file">`, `<input type="range">` or a checkbox. When a component covers only some variants, write it with `when`, listing the attribute values it covers (`null` means the attribute is absent). Read the component's props and its root element to decide. If you cannot tell, leave `when` out and tell the user which variants you were unsure about.
57
59
 
58
60
  ```json
@@ -74,7 +76,13 @@ Check which variants of the tag each component covers. An `Input` built for text
74
76
  }
75
77
  ```
76
78
 
77
- Paths are relative to the project root.
79
+ Paths are relative to the directory of the config file. Put the file in the project root unless the user asks otherwise.
80
+
81
+ If two or more tokens share one value, every hex color with that value will need a person's decision. When it is clear which family should win, for example a project whose semantic tokens (`--color-brand-*`) are built on raw scale tokens (`--color-blue-*`), suggest the object form of `tokens` to the user. `prefer` picks a token family when several match, and `exclude` drops tokens that should not be used at all, such as a legacy set. Only add them after the user agrees.
82
+
83
+ ```json
84
+ "tokens": { "file": "./src/app/globals.css", "prefer": ["--color-brand-"], "exclude": ["--color-legacy-*"] }
85
+ ```
78
86
 
79
87
  Messages are in English by default. If the user works in Korean, add `"lang": "ko"` to the file so that the CLI, the ESLint plugin and the hook speak Korean.
80
88
 
@@ -90,9 +98,12 @@ Look at `designSystem` and `problems` in the result.
90
98
  - `designSystem.components` should match the number of components you listed.
91
99
  - `problems` should be empty.
92
100
  - Exit code 2 with a message about a missing path means a path in the config is wrong.
101
+ - Every `use-ds-component` error should point to a component that really fits that place. Open two or three of them. If a component keeps being suggested where it does not belong, go back to step 3.
93
102
 
94
103
  Fix the config until these hold. Ignore the violations for now: fixing them is the job of the `designsnitch-check` skill.
95
104
 
105
+ Then look at how many colors have no token. Run `npx designsnitch colors --format json` and count the colors whose `tokens` is empty, and their uses. If the tokens cover only a small part of the colors in use, for example a handful of tokens against dozens of colors with no token, the project does not really have a palette yet. Do not leave this as a pile of warnings. Follow the `designsnitch-palette` skill: it proposes tokens for the colors that have none, next to the ones that exist.
106
+
96
107
  ## 6. Wire the ESLint plugin
97
108
 
98
109
  Follow the `designsnitch-eslint` skill now. It puts the rules into the project's ESLint, and installs ESLint if the project has none. Setup is not finished until this is done: the config file alone does not block anything.
@@ -113,3 +124,4 @@ If you were unsure about a choice, say so and give the alternative. For example,
113
124
  - Do not edit the token CSS without the user's agreement.
114
125
  - Do not change an existing config file without asking.
115
126
  - Do not start fixing violations as part of setup.
127
+ - Do not list a component as a replacement for a tag without reading it.