designsnitch 0.6.2 → 0.6.3
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 +19 -19
- package/README.md +19 -19
- package/package.json +1 -1
- package/src/messages.js +2 -2
- package/src/rules/color-unknown.js +2 -1
- package/src/rules/color-use-token.js +2 -1
- package/src/rules/load-tokens.js +14 -0
package/README.ko.md
CHANGED
|
@@ -2,24 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.md) | 한국어
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**모든 개발자가 좋은 디자인 시스템이 있는 환경에서 일하지는 않습니다.**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
디자인 시스템이 아예 없는 프로젝트가 있고, 있어도 이름뿐인 프로젝트가 있습니다. 디자이너가 없는 팀, 마감에 쫓겨 화면부터 만든 서비스, 토큰 파일은 있는데 아무도 따르지 않는 코드가 그렇습니다. 잘 갖춰진 디자인 시스템을 전제로 한 도구는 이런 프로젝트에서 쓸 수 없습니다.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
AI 에이전트가 코드를 쓰면 이 문제는 더 빨리 커집니다. 에이전트는 그럴듯한 화면을 금방 만들지만, 기준이 없으면 화면마다 따로 고릅니다.
|
|
10
|
+
|
|
11
|
+
- 같은 파란색이 어떤 화면에서는 `#3B82F6`이고 다른 화면에서는 `#3B82F5`입니다.
|
|
12
|
+
- 색 하나가 백 군데에 직접 적혀 있어서, 브랜드 색을 바꾸거나 다크 모드를 넣으려면 전부 찾아야 합니다.
|
|
13
|
+
- 공용 버튼이 있는데도 화면마다 `<button>`으로 버튼을 새로 만들어서 조금씩 다릅니다.
|
|
14
|
+
|
|
15
|
+
그 결과 코드는 관리하기 어려워지고, 서비스는 일관되게 유지하기 어려워집니다. 기준이 없으니 새 코드를 무엇에 비춰 검사할지도 없습니다.
|
|
16
|
+
|
|
17
|
+
**designsnitch의 목표는 이런 프로젝트에서도 AI가 쓴 UI 코드를 관리할 수 있고 일관되게 유지하는 것입니다.** 디자이너나 Figma 파일 없이, 코드 안에서 세 가지를 합니다.
|
|
18
|
+
|
|
19
|
+
1. **기준을 세웁니다.** 코드가 이미 쓰고 있는 색을 모아서 토큰으로 정리할 수 있게 합니다. 없는 기준을 새로 만들지 않고, 지금 쓰는 것에서 출발합니다.
|
|
20
|
+
2. **기준을 지킵니다.** 새 코드가 그 기준을 따르는지 확인하고, 무엇으로 바꾸면 되는지 알려줍니다. 에이전트가 코드를 쓰는 동안 막습니다.
|
|
11
21
|
3. **정리합니다.** 이미 흩어진 코드를 기준에 맞게 되돌리는 일을 돕습니다.
|
|
12
22
|
|
|
13
|
-
무엇을 기준으로 삼을지는 개발자가 정합니다. 도구는
|
|
23
|
+
무엇을 기준으로 삼을지는 개발자가 정합니다. 도구는 대신 정하지 않습니다. 어디에 몇 번 쓰였는지, 바꾸면 화면이 달라지는지 같은 판단에 필요한 것을 가져와서 묻습니다.
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
## 구성
|
|
16
26
|
|
|
17
27
|
| 부분 | 목적 |
|
|
18
28
|
| --- | --- |
|
|
19
29
|
| CLI | AI 에이전트가 쓰는 도구입니다. 쓰이는 색을 모으고, 코드를 검사하고, 위반마다 무엇을 하면 되는지 알려줍니다. |
|
|
20
30
|
| 에이전트 스킬 | AI 에이전트에게 프로젝트를 어떻게 설정하고, 언제 CLI를 실행하고, 무엇을 고치고, 무엇을 사람에게 물을지 알려줍니다. |
|
|
21
31
|
| ESLint 플러그인 | 막고 경고합니다. 같은 규칙이 에디터와 lint 단계에서 오류와 경고로 나옵니다. |
|
|
22
|
-
| 에이전트 훅 | 코드를 쓰는 동안 막습니다. 에이전트는 파일을 고칠 때마다 오류를 전달받고,
|
|
32
|
+
| 에이전트 훅 | 코드를 쓰는 동안 막습니다. 에이전트는 파일을 고칠 때마다 새로 생긴 오류를 전달받고, 바로 바꿀 수 있는 오류가 남아 있으면 작업을 끝내지 못합니다. |
|
|
23
33
|
|
|
24
34
|
**Tailwind CSS v4를 쓰는 React/Next.js 프로젝트**를 지원합니다. Tailwind v3 프로젝트도 검사하지만 후보가 적습니다([Tailwind v3](#tailwind-v3) 참고).
|
|
25
35
|
|
|
@@ -67,22 +77,12 @@ Codex, Gemini CLI, Grok Build는 새 프로젝트 훅을 승인하거나 프로
|
|
|
67
77
|
|
|
68
78
|
그 뒤로는 이렇게 됩니다.
|
|
69
79
|
|
|
70
|
-
- 에이전트는 파일을 고칠 때마다 오류를 전달받고,
|
|
80
|
+
- 에이전트는 파일을 고칠 때마다 새로 생긴 오류를 전달받고, 바로 바꿀 수 있는 오류가 남아 있으면 작업을 끝내지 못합니다. 세션 전부터 있던 오류는 세지 않습니다.
|
|
71
81
|
- 오류가 있으면 lint 단계가 실패하고, 에디터에도 표시됩니다.
|
|
72
82
|
- `npx designsnitch check`로 코드의 현재 상태를 언제든 볼 수 있습니다.
|
|
73
83
|
|
|
74
84
|
에이전트 없이 하려면 [직접 설정하기](#직접-설정하기)를 보세요.
|
|
75
85
|
|
|
76
|
-
## 왜 필요한가
|
|
77
|
-
|
|
78
|
-
기준이 없으면 화면마다 따로 고르게 됩니다. AI 에이전트는 그 선택을 빠르고 그럴듯하게 하고, 그것이 쌓입니다.
|
|
79
|
-
|
|
80
|
-
- 같은 파란색이 어떤 화면에서는 `#3B82F6`이고 다른 화면에서는 `#3B82F5`입니다.
|
|
81
|
-
- 색 하나가 백 군데에 직접 적혀 있어서, 브랜드 색을 바꾸거나 다크 모드를 넣으려면 전부 찾아야 합니다.
|
|
82
|
-
- 화면마다 `<button>`으로 버튼을 새로 만들어서 조금씩 다르고, 어떤 것은 focus 스타일이 없습니다.
|
|
83
|
-
|
|
84
|
-
그 결과 코드는 관리하기 어려워지고, 서비스는 일관되게 유지하기 어려워집니다. 그리고 기준이 없으면 새 코드를 무엇에 비춰 검사할지도 없습니다. designsnitch는 코드가 이미 하고 있는 것에서 기준을 세우게 돕고, 새 코드가 그 기준을 따르게 합니다.
|
|
85
|
-
|
|
86
86
|
## 무엇을 잡는가
|
|
87
87
|
|
|
88
88
|
등급은 한 가지 기준을 따릅니다.
|
|
@@ -256,7 +256,7 @@ Tailwind 기본 팔레트
|
|
|
256
256
|
|
|
257
257
|
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`에서 읽습니다.
|
|
258
258
|
|
|
259
|
-
v3는 색에 CSS 변수를 만들지 않으므로 모든 토큰이 클래스 전용입니다. 임의 값 색 클래스에는 토큰 클래스를 후보로 내고, CSS 선언과 인라인 스타일에 직접 쓴 색은 후보 없이 알립니다.
|
|
259
|
+
v3는 색에 CSS 변수를 만들지 않으므로 모든 토큰이 클래스 전용입니다. 임의 값 색 클래스에는 토큰 클래스를 후보로 내고, CSS 선언과 인라인 스타일에 직접 쓴 색은 후보 없이 알립니다. Tailwind v3가 처리하는 CSS 파일에서는 `theme("colors.brand.500")`이 토큰의 값을 주므로, 그것으로 해결할 수 있습니다.
|
|
260
260
|
|
|
261
261
|
## 언어
|
|
262
262
|
|
package/README.md
CHANGED
|
@@ -2,24 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
English | [Korean](./README.ko.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Not every developer gets to work with a good design system.**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Some projects have no design system at all, and some have one in name only: a team with no designer, a product whose screens were built against a deadline, a token file that nobody follows. Tools that assume a well-kept design system have nothing to work with there.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
AI agents make this grow faster. An agent produces a plausible screen in minutes, and with no standard to follow, every screen makes its own choices.
|
|
10
|
+
|
|
11
|
+
- The same blue is `#3B82F6` on one screen and `#3B82F5` on another.
|
|
12
|
+
- A color is written by hand in a hundred places, so changing the brand color or adding dark mode means finding every one of them.
|
|
13
|
+
- A shared button exists, and each screen still builds its own from `<button>`, each a little different.
|
|
14
|
+
|
|
15
|
+
The result is a codebase that is hard to manage and a product that is hard to keep consistent. And with no standard, there is nothing to check new code against.
|
|
16
|
+
|
|
17
|
+
**The goal of designsnitch is to keep AI-written UI code manageable and consistent in exactly these projects.** It works inside the code, with no designer or Figma file required, and does three things.
|
|
18
|
+
|
|
19
|
+
1. **Establish a standard.** It collects the colors the code already uses so you can turn them into tokens. It starts from what is there instead of inventing a standard.
|
|
20
|
+
2. **Keep to it.** It checks new code against that standard and tells you what to use instead. It blocks while the agent is writing.
|
|
11
21
|
3. **Clean up.** It helps bring code that has already drifted back to the standard.
|
|
12
22
|
|
|
13
|
-
Deciding what the standard is stays with the developer. The tool
|
|
23
|
+
Deciding what the standard is stays with the developer. The tool does not decide for you. It brings what the decision needs, such as how often a color is used and whether a change would alter the screen, and asks.
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
## What is in it
|
|
16
26
|
|
|
17
27
|
| Part | What it is for |
|
|
18
28
|
| --- | --- |
|
|
19
29
|
| CLI | A tool for the AI agent. It collects the colors in use, checks code, and says what to do with each violation. |
|
|
20
30
|
| Agent skills | Tell an AI agent how to set the project up, when to run the CLI, what to fix, and what to ask a person about. |
|
|
21
31
|
| ESLint plugin | Blocks and warns. The same rules show up as errors and warnings in the editor and in the lint step. |
|
|
22
|
-
| Agent hook | Blocks while the code is being written. The agent is told about errors after each edit and cannot finish while errors it can
|
|
32
|
+
| Agent hook | Blocks while the code is being written. The agent is told about new errors after each edit and cannot finish while errors it can replace right away remain. |
|
|
23
33
|
|
|
24
34
|
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
35
|
|
|
@@ -67,22 +77,12 @@ The agent follows the `designsnitch-setup` skill and does the rest.
|
|
|
67
77
|
|
|
68
78
|
From then on:
|
|
69
79
|
|
|
70
|
-
- The agent is told about errors right after it edits a file, and cannot finish while errors it can
|
|
80
|
+
- The agent is told about new errors right after it edits a file, and cannot finish while errors it can replace right away remain. Errors that were there before the session do not count.
|
|
71
81
|
- Errors fail the lint step, and show up in the editor.
|
|
72
82
|
- `npx designsnitch check` reports where the code stands at any time.
|
|
73
83
|
|
|
74
84
|
To do any of this without an agent, see [Setting up by hand](#setting-up-by-hand).
|
|
75
85
|
|
|
76
|
-
## Why
|
|
77
|
-
|
|
78
|
-
When there is no standard, every screen makes its own choices. An AI agent makes them quickly and plausibly, and they add up.
|
|
79
|
-
|
|
80
|
-
- The same blue is `#3B82F6` on one screen and `#3B82F5` on another.
|
|
81
|
-
- A color is written by hand in a hundred places, so changing the brand color or adding dark mode means finding every one of them.
|
|
82
|
-
- Each screen builds its own button from `<button>`, each a little different, some without a focus style.
|
|
83
|
-
|
|
84
|
-
The result is a codebase that is hard to manage and a product that is hard to keep consistent. And with no standard, there is nothing to check new code against. designsnitch helps you set a standard from what the code already does, and then holds new code to it.
|
|
85
|
-
|
|
86
86
|
## What it catches
|
|
87
87
|
|
|
88
88
|
Severity follows one rule.
|
|
@@ -255,7 +255,7 @@ Tokens are also read from where Tailwind itself reads them.
|
|
|
255
255
|
|
|
256
256
|
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`.
|
|
257
257
|
|
|
258
|
-
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.
|
|
258
|
+
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. In a CSS file that Tailwind v3 processes, `theme("colors.brand.500")` gives the token's value, so that is one way to resolve those.
|
|
259
259
|
|
|
260
260
|
## Language
|
|
261
261
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsnitch",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
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",
|
package/src/messages.js
CHANGED
|
@@ -38,7 +38,7 @@ const en = {
|
|
|
38
38
|
useTokenData: ({ found, tokens, candidates }) =>
|
|
39
39
|
`${found} has the same color as ${tokens}. It is not in a style, so check that var() works where this value is used. Candidate: ${candidates}`,
|
|
40
40
|
useTokenClassOnly: ({ found, tokens }) =>
|
|
41
|
-
`${found} has the same color as ${tokens}, but
|
|
41
|
+
`${found} has the same color as ${tokens}, but Tailwind makes no CSS variable for that token, so there is no var() to use here.`,
|
|
42
42
|
unknownColor: ({ found }) => `The color of ${found} is not in the tokens.`,
|
|
43
43
|
unknownCssColor: ({ value }) => `The color ${value} is not in the tokens.`,
|
|
44
44
|
useComponent: ({ tag, component, path }) =>
|
|
@@ -193,7 +193,7 @@ const ko = {
|
|
|
193
193
|
useTokenData: ({ found, tokens, candidates }) =>
|
|
194
194
|
`${found}의 색은 토큰 ${tokens}의 값입니다. 스타일이 아닌 자리라서, 이 값을 쓰는 곳에서 var()가 통하는지 확인해야 합니다. 후보: ${candidates}`,
|
|
195
195
|
useTokenClassOnly: ({ found, tokens }) =>
|
|
196
|
-
`${found}의 색은 토큰 ${tokens}의 값이지만, 이
|
|
196
|
+
`${found}의 색은 토큰 ${tokens}의 값이지만, Tailwind가 이 토큰의 CSS 변수를 만들지 않아서 여기에 쓸 var()가 없습니다.`,
|
|
197
197
|
unknownColor: ({ found }) => `${found}의 색은 토큰에 없습니다.`,
|
|
198
198
|
unknownCssColor: ({ value }) => `${value}의 색은 토큰에 없습니다.`,
|
|
199
199
|
useComponent: ({ tag, component, path }) =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findArbitraryColors } from "../core/classes.js";
|
|
2
2
|
import { lookupColor } from "../core/tokens.js";
|
|
3
|
-
import { loadTokens } from "./load-tokens.js";
|
|
3
|
+
import { definesTokens, loadTokens } from "./load-tokens.js";
|
|
4
4
|
import { ruleMessages, TEXT } from "./suggest.js";
|
|
5
5
|
import { visitStrings } from "./visit-strings.js";
|
|
6
6
|
import { mergeVisitors, visitInlineStyleColors } from "./visit-style.js";
|
|
@@ -21,6 +21,7 @@ export default {
|
|
|
21
21
|
// 토큰 설정 문제는 color-use-token 에서만 보고한다.
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
|
+
if (definesTokens(tokens, context.filename)) return {};
|
|
24
25
|
const m = ruleMessages(context);
|
|
25
26
|
const { colors } = tokens;
|
|
26
27
|
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
tokenValue,
|
|
8
8
|
utilityColorPrefixes,
|
|
9
9
|
} from "../core/tokens.js";
|
|
10
|
-
import { loadTokens } from "./load-tokens.js";
|
|
10
|
+
import { definesTokens, loadTokens } from "./load-tokens.js";
|
|
11
11
|
import { ruleMessages, suggestClasses, TEXT } from "./suggest.js";
|
|
12
12
|
import { visitStrings } from "./visit-strings.js";
|
|
13
13
|
import { mergeVisitors, visitInlineStyleColors } from "./visit-style.js";
|
|
@@ -40,6 +40,7 @@ export default {
|
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
if (definesTokens(tokens, context.filename)) return {};
|
|
43
44
|
const m = ruleMessages(context);
|
|
44
45
|
const { colors, themed, prefer, classOnly } = tokens;
|
|
45
46
|
|
package/src/rules/load-tokens.js
CHANGED
|
@@ -19,6 +19,20 @@ import { flattenColors, loadConfigColors } from "./tailwind-config.js";
|
|
|
19
19
|
* @property {string[]} problems 토큰을 다 읽지 못하게 만든 문제. 예: 불러오지 못한 JavaScript 설정
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 이 파일이 토큰을 정의하는 JavaScript 설정인지. 그 안의 색은 토큰의 값이지 직접 쓴 색이 아니다.
|
|
24
|
+
* @param {Tokens} tokens
|
|
25
|
+
* @param {string} filename 절대 경로
|
|
26
|
+
*/
|
|
27
|
+
export function definesTokens(tokens, filename) {
|
|
28
|
+
if (tokens.files.has(filename)) return true;
|
|
29
|
+
try {
|
|
30
|
+
return tokens.files.has(fs.realpathSync(filename));
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
/** @typedef {ReturnType<typeof parseColorTokenData> & Pick<Tokens, "files" | "prefix" | "classOnly" | "problems">} ProjectTokens */
|
|
23
37
|
|
|
24
38
|
/** @type {Map<string, { deps: [string, number][], tokens: ProjectTokens }>} */
|