designsnitch 0.6.0 → 0.6.2
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 +3 -3
- package/README.md +3 -3
- package/package.json +1 -1
- package/skills/designsnitch-check/SKILL.md +11 -2
- package/skills/designsnitch-setup/SKILL.md +1 -0
- package/src/colors.js +2 -2
- package/src/core/classes.js +2 -2
- package/src/core/color.js +7 -1
- package/src/core/tokens.js +3 -1
- package/src/messages.js +2 -2
- package/src/rules/visit-style.js +6 -6
package/README.ko.md
CHANGED
|
@@ -288,7 +288,7 @@ src/PayButton.tsx
|
|
|
288
288
|
"problems": [],
|
|
289
289
|
"next": [
|
|
290
290
|
"action이 replace인 1건은 found를 candidates의 값으로 바꾸세요.",
|
|
291
|
-
"action이 migrate인 1건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못
|
|
291
|
+
"action이 migrate인 1건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못 하거나 모양이 달라지면, 컴포넌트를 고쳐서 맞추지 말고 태그를 그대로 둔 채 사용자에게 물으세요.",
|
|
292
292
|
"변경하기 전에 decisions의 2건을 사용자에게 물으세요. 사용 횟수와 후보, 확인이 필요한 이유를 함께 알려 주세요.",
|
|
293
293
|
"고친 뒤 같은 명령을 다시 실행하세요."
|
|
294
294
|
],
|
|
@@ -517,7 +517,7 @@ Tailwind 기본 팔레트(`bg-slate-100`, `text-indigo-600`)를 기준으로 쓰
|
|
|
517
517
|
## 검사 범위
|
|
518
518
|
|
|
519
519
|
- **JS와 TS에서 보는 곳:** 문자열과 템플릿 리터럴 안의 임의 값 색 클래스(`className`과 `cn()`, `clsx()`, `cva()`의 인자 포함)와, 색을 받는 자리에 문자열로 적은 색입니다. `a ? "#fff" : "#000"`이나 `x || "#fff"`처럼 고르는 식의 값도 봅니다. 주석은 보지 않습니다.
|
|
520
|
-
- **스타일:** JSX `style`
|
|
520
|
+
- **스타일:** JSX `style` 객체와 `CSSProperties` 타입의 객체입니다. 여기서는 `var(--토큰)`이 통하므로 다른 색과 똑같이 검사합니다. `cardStyle` 같은 변수 이름은 근거로 삼지 않습니다. 차트 설정 묶음일 수 있기 때문입니다.
|
|
521
521
|
- **그 밖의 색 속성:** 이름이 CSS 색 속성이거나 `Color`로 끝나는 속성과 JSX 속성입니다. 차트 옵션의 `backgroundColor`, SVG 요소의 `stroke` 같은 것입니다. 색은 알리고 `var(--토큰)`을 후보로 주지만 `ask`로 표시합니다. 캔버스처럼 `var()`가 통하지 않는 곳에 쓰일 수 있기 때문입니다.
|
|
522
522
|
- **나머지:** 다른 이름의 키(`{ primary: "#3B82F6" }`)와 배열 안의 색은 코드만 보고 용도를 알 수 없어 검사하지 않습니다. 대신 있다는 것을 알 수 있도록 `unchecked`에 개수를 세고, `designsnitch colors`로 목록을 볼 수 있습니다.
|
|
523
523
|
- **CSS에서 보는 곳:** `.css` 파일(CSS Modules 포함)의 선언 값에 있는 색과 `@apply`의 임의 값 색 클래스입니다. 토큰 CSS에서는 변수를 정의하는 선언(`--이름: ...`)을 토큰을 정의하는 곳으로 보고 건너뜁니다. 다른 CSS 파일에서는 변수 선언도 일반 선언처럼 검사합니다. CSS에서는 아직 색만 검사합니다.
|
|
@@ -528,7 +528,7 @@ Tailwind 기본 팔레트(`bg-slate-100`, `text-indigo-600`)를 기준으로 쓰
|
|
|
528
528
|
|
|
529
529
|
감지는 하지만 토큰과 맞추지는 못하는 것:
|
|
530
530
|
|
|
531
|
-
- 반투명한 색(`#3B82F680`, `rgb(0 0 0 / 50%)`)은 불투명한 색의 토큰에 불투명도를 붙인 후보를 받습니다. 클래스는 `bg-brand/50`, 스타일과 CSS 선언은 `color-mix(in srgb, var(--color-brand) 50%, transparent)`입니다. 불투명도를 정수 퍼센트로 반올림하므로 `ask`로 표시합니다.
|
|
531
|
+
- 반투명한 색(`#3B82F680`, `rgb(0 0 0 / 50%)`)은 불투명한 색의 토큰에 불투명도를 붙인 후보를 받습니다. 클래스는 `bg-brand/50`, 스타일과 CSS 선언은 `color-mix(in srgb, var(--color-brand) 50%, transparent)`입니다. 불투명도를 정수 퍼센트로 반올림하므로 `ask`로 표시합니다. `rgba(0, 0, 0, 0)`처럼 완전히 투명한 값은 색을 쓴 것이 아니므로 건너뜁니다.
|
|
532
532
|
- Tailwind 플러그인이 더하는 색은 토큰으로 알지 못합니다. 그 색을 직접 쓰면 토큰 없는 색으로 알립니다.
|
|
533
533
|
- `hwb()`, `lab()`, `lch()`, `oklab()`, `color()` 값과 sRGB 밖의 `oklch()` 색은 같은 값으로 적은 토큰과만 맞춥니다. 같은 색을 내는 hex가 없기 때문입니다.
|
|
534
534
|
- 색 이름은 색 속성(`color`, `background`, `border` 등), 임의 값 클래스(`bg-[white]`), 값 전체가 색 이름인 변수 선언에서만 읽습니다. 다른 곳의 `red` 같은 단어는 색으로 보지 않습니다.
|
package/README.md
CHANGED
|
@@ -287,7 +287,7 @@ The first line shows how many tokens and components were read from the config. A
|
|
|
287
287
|
"problems": [],
|
|
288
288
|
"next": [
|
|
289
289
|
"action \"replace\" (1): replace found with the value in candidates.",
|
|
290
|
-
"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
|
|
290
|
+
"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 or would change how it looks, do not change the component to make it fit: leave the tag and ask the user.",
|
|
291
291
|
"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.",
|
|
292
292
|
"After fixing, run the same command again."
|
|
293
293
|
],
|
|
@@ -516,7 +516,7 @@ Without `palette`, designsnitch does not flag default palette classes, and does
|
|
|
516
516
|
## Scope
|
|
517
517
|
|
|
518
518
|
- **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 where a color is expected, including the branches of `a ? "#fff" : "#000"` and `x || "#fff"`. Comments are ignored.
|
|
519
|
-
- **Styles:** a JSX `style` object
|
|
519
|
+
- **Styles:** a JSX `style` object and an object typed `CSSProperties`. `var(--token)` works there, so these are checked like any other color. A variable name such as `cardStyle` is not taken as proof: it may hold chart settings.
|
|
520
520
|
- **Other color properties:** a property or JSX attribute whose name is a CSS color property or ends in `Color`, such as `backgroundColor` in chart options or `stroke` on an SVG element. The color is reported, with `var(--token)` as a candidate, but marked `ask`: the tool cannot tell whether `var()` works where the value ends up, for example on a canvas.
|
|
521
521
|
- **Everything else:** colors under other keys (`{ primary: "#3B82F6" }`) and in arrays are not checked, because 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.
|
|
522
522
|
- **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.
|
|
@@ -527,7 +527,7 @@ Without `palette`, designsnitch does not flag default palette classes, and does
|
|
|
527
527
|
|
|
528
528
|
These are detected, but not matched to a token:
|
|
529
529
|
|
|
530
|
-
- Translucent colors (`#3B82F680`, `rgb(0 0 0 / 50%)`) get the token of the opaque color with an opacity: `bg-brand/50` for a class, `color-mix(in srgb, var(--color-brand) 50%, transparent)` for a style or a CSS declaration. The opacity is rounded to a whole percent, so these are marked `ask`.
|
|
530
|
+
- Translucent colors (`#3B82F680`, `rgb(0 0 0 / 50%)`) get the token of the opaque color with an opacity: `bg-brand/50` for a class, `color-mix(in srgb, var(--color-brand) 50%, transparent)` for a style or a CSS declaration. The opacity is rounded to a whole percent, so these are marked `ask`. Fully transparent values such as `rgba(0, 0, 0, 0)` are not colors in use and are skipped.
|
|
531
531
|
- Colors a Tailwind plugin adds are not known as tokens, so writing one by hand is reported as a color with no token.
|
|
532
532
|
- `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.
|
|
533
533
|
- 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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsnitch",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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",
|
|
@@ -88,12 +88,20 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
|
|
|
88
88
|
| `action` | What it means | What to do |
|
|
89
89
|
| --- | --- | --- |
|
|
90
90
|
| `replace` | A color error whose only candidate keeps the screen and the behavior the same. | Replace `found` with the candidate. |
|
|
91
|
-
| `migrate` | A raw tag with exactly one design system component to move to. Whether the component behaves like the tag is not known. | Read the component, then move the tag to it as described below. If the component
|
|
91
|
+
| `migrate` | A raw tag with exactly one design system component to move to. Whether the component behaves like the tag is not known. | Read the component, then move the tag to it as described below. If the component does not cover this use, leave the tag and ask the user as described below. The hook does not force this one. |
|
|
92
92
|
| `ask` | A person has to decide: several candidates, a color that has no token, a token whose value differs between themes, a translucent color (the candidate rounds its opacity), a color in a property that is not a style (such as chart options, where `var()` may not work: read how the value is used before replacing), a token that exists only as a class (no CSS variable to use in a style or a CSS declaration), or a component whose props are dynamic or spread. `message` says which. | Do not change it. Ask the user as described in section 4. |
|
|
93
93
|
| `repair` | The file could not be parsed. | Fix the syntax error, then check again. |
|
|
94
94
|
|
|
95
95
|
For `migrate`, replacing means more than renaming the tag. Read the design system component file to learn its props, add the import, pass on the tag's props the component accepts, and remove className values that duplicate styles the component already has. Check that event handlers such as `onClick` and attributes such as `type` still reach the rendered element.
|
|
96
96
|
|
|
97
|
+
Often the component does not cover the use: it cannot pass on something the tag needs, or moving to it would change how the element looks, such as a text-sized `Button` for a small square icon button. Then there are three ways out, and choosing between them is the user's call, because two of them change the standard.
|
|
98
|
+
|
|
99
|
+
- Extend the component: a new variant, size or prop. This changes a shared component that other screens use.
|
|
100
|
+
- Narrow the rule: a `when` condition in `designsnitch.config.json`, so that this kind of tag is no longer expected to use the component.
|
|
101
|
+
- Keep this tag as an exception, with a disable comment that says why.
|
|
102
|
+
|
|
103
|
+
Leave the tag as it is, and ask. Say what the component lacks, show the place, and recommend one of the three. Do not add a variant to a design system component on your own to make the check pass, even when the result would look the same.
|
|
104
|
+
|
|
97
105
|
## 4. Ask so the user can decide
|
|
98
106
|
|
|
99
107
|
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:
|
|
@@ -127,6 +135,7 @@ Report what you fixed and what you left, separately. For what you left, use the
|
|
|
127
135
|
|
|
128
136
|
## What not to do
|
|
129
137
|
|
|
130
|
-
- Do not edit `designsnitch.config.json
|
|
138
|
+
- Do not edit `designsnitch.config.json`, the token CSS or the design system components to make the check pass. They are the standard the code is judged against. If one of them seems wrong or incomplete, explain why and ask the user.
|
|
131
139
|
- Do not add `eslint-disable` or `designsnitch-disable-next-line` comments, lower a rule's severity, or turn a rule off to make the check pass. If an exception seems necessary, ask the user.
|
|
132
140
|
- Do not pick one of several candidates on your own.
|
|
141
|
+
- Do not change how the tokens are declared, such as turning `@theme` into `@theme static`, to make a `var(--token)` candidate work. Tailwind outputs a theme variable as soon as a class, a style or a CSS file uses it. A variable missing from the compiled CSS before the replacement is expected.
|
|
@@ -128,3 +128,4 @@ If you were unsure about a choice, say so and give the alternative. For example,
|
|
|
128
128
|
- Do not change an existing config file without asking.
|
|
129
129
|
- Do not start fixing violations as part of setup.
|
|
130
130
|
- Do not list a component as a replacement for a tag without reading it.
|
|
131
|
+
- Do not change a design system component so that more tags fit it. Propose it to the user instead.
|
package/src/colors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { findArbitraryColors, findPaletteClasses } from "./core/classes.js";
|
|
4
|
-
import { colorLabel, isColorProperty, isNamedColor,
|
|
4
|
+
import { colorLabel, isColorProperty, isNamedColor, isVisibleColor } from "./core/color.js";
|
|
5
5
|
import { findCssColors } from "./core/css.js";
|
|
6
6
|
import { createEngine } from "./engine.js";
|
|
7
7
|
import { splitPaths } from "./files.js";
|
|
@@ -37,7 +37,7 @@ const collectRule = {
|
|
|
37
37
|
// 문자열 전체가 색인 경우. 예: style={{ color: "#3B82F6" }}
|
|
38
38
|
// 색 이름은 인라인 스타일의 색 속성에서만 색으로 센다. 다른 곳에서는 그냥 단어일 수 있다.
|
|
39
39
|
const isColor = (value) =>
|
|
40
|
-
|
|
40
|
+
isVisibleColor(value) && (!isNamedColor(value) || isColorProperty(inlineStyleProperty(node) ?? ""));
|
|
41
41
|
if (typeof node.value === "string" && isColor(node.value)) {
|
|
42
42
|
report(node.loc, { kind: "hex", key: colorLabel(node.value), utility: null });
|
|
43
43
|
return;
|
package/src/core/classes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isVisibleColor } from "./color.js";
|
|
2
2
|
|
|
3
3
|
// 예: bg-[#3B82F6], ring-offset-[#fff], text-[rgb(59,130,246)], bg-[oklch(62.3%_0.214_259.815)], bg-[white]
|
|
4
4
|
const ARBITRARY_COLOR =
|
|
@@ -11,7 +11,7 @@ const ARBITRARY_COLOR =
|
|
|
11
11
|
*/
|
|
12
12
|
export function findArbitraryColors(text) {
|
|
13
13
|
return [...text.matchAll(ARBITRARY_COLOR)]
|
|
14
|
-
.filter((match) =>
|
|
14
|
+
.filter((match) => isVisibleColor(match[2]))
|
|
15
15
|
.map((match) => ({
|
|
16
16
|
index: match.index,
|
|
17
17
|
text: match[0],
|
package/src/core/color.js
CHANGED
|
@@ -57,6 +57,12 @@ export function parseColor(value) {
|
|
|
57
57
|
return { key: `#${rgb.map(toByte).join("")}`, alpha, opaque: alpha >= 1 };
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/** 색으로 읽히고 완전히 투명하지 않은 값인지. rgba(0, 0, 0, 0) 은 색을 쓴 것이 아니다. */
|
|
61
|
+
export function isVisibleColor(value) {
|
|
62
|
+
const color = parseColor(value);
|
|
63
|
+
return color !== null && color.alpha > 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
/**
|
|
61
67
|
* 색을 세거나 묶을 때 쓰는 이름. 표기가 달라도 같은 색이면 같은 이름이 된다.
|
|
62
68
|
* 불투명한 색은 normalizeColor 와 같고, 반투명한 색은 #rrggbbaa 다. 색이 아니면 소문자로만 맞춘다.
|
|
@@ -89,7 +95,7 @@ export function normalizeColor(value) {
|
|
|
89
95
|
export function findColorValues(text, { named = false } = {}) {
|
|
90
96
|
const matches = [...text.matchAll(COLOR_VALUE), ...(named ? text.matchAll(NAMED_VALUE) : [])];
|
|
91
97
|
return matches
|
|
92
|
-
.filter((match) =>
|
|
98
|
+
.filter((match) => isVisibleColor(match[0]))
|
|
93
99
|
.sort((a, b) => a.index - b.index)
|
|
94
100
|
.map((match) => ({ index: match.index, text: match[0], value: match[0] }));
|
|
95
101
|
}
|
package/src/core/tokens.js
CHANGED
|
@@ -124,7 +124,9 @@ export function tokenVar(name, prefix) {
|
|
|
124
124
|
export function lookupColor(colors, value) {
|
|
125
125
|
const color = parseColor(value);
|
|
126
126
|
if (!color) return { names: [], opacity: null };
|
|
127
|
-
|
|
127
|
+
// 0 은 아니지만 반올림하면 0% 가 되는 값은 1% 로 본다. 0% 는 완전히 투명하다는 다른 뜻이다.
|
|
128
|
+
const opacity = color.opaque ? null : Math.max(1, Math.round(color.alpha * 100));
|
|
129
|
+
return { names: colors.get(color.key) ?? [], opacity };
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
/** 토큰을 CSS 값으로 쓰는 표기. 불투명도가 있으면 투명과 섞는다. */
|
package/src/messages.js
CHANGED
|
@@ -104,7 +104,7 @@ const en = {
|
|
|
104
104
|
nextRepair: (n) => `action "repair" (${n}): fix the syntax error in that file first.`,
|
|
105
105
|
nextReplace: (n) => `action "replace" (${n}): replace found with the value in candidates.`,
|
|
106
106
|
nextMigrate: (n) =>
|
|
107
|
-
`action "migrate" (${n}): 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
|
|
107
|
+
`action "migrate" (${n}): 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 or would change how it looks, do not change the component to make it fit: leave the tag and ask the user.`,
|
|
108
108
|
nextAsk: (n) =>
|
|
109
109
|
`Before making changes, ask the user about the ${count(n, "entry", "entries")} in decisions. Include how often each comes up, the candidates, and the reasons for asking.`,
|
|
110
110
|
hookNextAsk: (n) =>
|
|
@@ -256,7 +256,7 @@ const ko = {
|
|
|
256
256
|
nextRepair: (n) => `action이 repair인 ${n}건은 그 파일의 문법 오류부터 고치세요.`,
|
|
257
257
|
nextReplace: (n) => `action이 replace인 ${n}건은 found를 candidates의 값으로 바꾸세요.`,
|
|
258
258
|
nextMigrate: (n) =>
|
|
259
|
-
`action이 migrate인 ${n}건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못
|
|
259
|
+
`action이 migrate인 ${n}건은 태그를 candidates의 컴포넌트로 바꾸세요. 먼저 그 컴포넌트를 읽고, import를 더하고, 컴포넌트가 받는 props를 넘기고, 컴포넌트가 이미 주는 className은 지우세요. 태그가 하던 일을 컴포넌트가 못 하거나 모양이 달라지면, 컴포넌트를 고쳐서 맞추지 말고 태그를 그대로 둔 채 사용자에게 물으세요.`,
|
|
260
260
|
nextAsk: (n) =>
|
|
261
261
|
`변경하기 전에 decisions의 ${n}건을 사용자에게 물으세요. 사용 횟수와 후보, 확인이 필요한 이유를 함께 알려 주세요.`,
|
|
262
262
|
hookNextAsk: (n) =>
|
package/src/rules/visit-style.js
CHANGED
|
@@ -2,13 +2,13 @@ import { findColorValues, isColorProperty } from "../core/color.js";
|
|
|
2
2
|
|
|
3
3
|
// 색을 받는 이름. CSS 의 색 속성이거나 Color 로 끝난다. 예: backgroundColor, stroke, pointHoverBackgroundColor
|
|
4
4
|
const isColorKey = (name) => isColorProperty(name) || /color$/i.test(name);
|
|
5
|
-
const STYLE_NAME = /styles?$/i;
|
|
6
5
|
const STYLE_TYPE = /CSSProperties/;
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* 노드가 색을 값으로 받는 자리에 있는지 본다.
|
|
10
|
-
* - style: 스타일로 쓰이는 객체의 값. JSX 의 style
|
|
11
|
-
* 여기서는 var(--토큰) 이 통한다.
|
|
9
|
+
* - style: 스타일로 쓰이는 객체의 값. JSX 의 style 속성과 CSSProperties 타입의 객체.
|
|
10
|
+
* 여기서는 var(--토큰) 이 통한다. 변수 이름(cardStyle, VARIANT_STYLES)은 근거로 삼지 않는다.
|
|
11
|
+
* 이름만 그럴 뿐 차트 설정 묶음일 수 있고, 그러면 var() 로 바꾸는 것이 안전하지 않다.
|
|
12
12
|
* - data: 그 밖에 색을 받는 이름의 속성이나 JSX 속성. 예: 차트 옵션의 backgroundColor, <Line stroke="...">.
|
|
13
13
|
* 색인 것은 분명하지만 var() 가 통하는지는 알 수 없다.
|
|
14
14
|
* @param {import("estree").Node & { parent?: any }} node 문자열이나 템플릿 리터럴
|
|
@@ -42,14 +42,14 @@ export function colorContext(node, sourceCode) {
|
|
|
42
42
|
return { property: name, kind: style ? "style" : "data" };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** 객체가 스타일로 쓰이는지. JSX 의 style 속성이면 "jsx",
|
|
45
|
+
/** 객체가 스타일로 쓰이는지. JSX 의 style 속성이면 "jsx", CSSProperties 타입이면 "typed", 아니면 null. */
|
|
46
46
|
function styleObjectKind(object, sourceCode) {
|
|
47
47
|
const typed = (annotation) => Boolean(annotation && sourceCode && STYLE_TYPE.test(sourceCode.getText(annotation)));
|
|
48
48
|
for (let node = object; node; node = node.parent) {
|
|
49
49
|
const parent = node.parent;
|
|
50
50
|
if (!parent) return null;
|
|
51
51
|
if (parent.type === "TSAsExpression" || parent.type === "TSSatisfiesExpression") {
|
|
52
|
-
if (typed(parent.typeAnnotation)) return "
|
|
52
|
+
if (typed(parent.typeAnnotation)) return "typed";
|
|
53
53
|
} else if (parent.type === "JSXExpressionContainer") {
|
|
54
54
|
const attribute = parent.parent;
|
|
55
55
|
return attribute?.type === "JSXAttribute" && attribute.name?.name === "style" ? "jsx" : null;
|
|
@@ -59,7 +59,7 @@ function styleObjectKind(object, sourceCode) {
|
|
|
59
59
|
} else if (parent.type === "VariableDeclarator" && parent.init === node) {
|
|
60
60
|
const { id } = parent;
|
|
61
61
|
if (id.type !== "Identifier") return null;
|
|
62
|
-
return
|
|
62
|
+
return typed(id.typeAnnotation) ? "typed" : null;
|
|
63
63
|
} else {
|
|
64
64
|
return null;
|
|
65
65
|
}
|