@conscience-technology/ovenn 0.7.4 → 0.7.6
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.md +43 -4
- package/assets/components/AIMessage/AIMessage.module.css +10 -0
- package/assets/components/AIMessage/AIMessage.tsx +6 -2
- package/assets/components/AttachmentThumb/AttachmentThumb.tsx +1 -0
- package/assets/components/Breadcrumb/Breadcrumb.module.css +82 -23
- package/assets/components/Breadcrumb/Breadcrumb.tsx +44 -26
- package/assets/components/Breadcrumb/index.ts +1 -0
- package/assets/components/Button/Button.module.css +2 -4
- package/assets/components/Callout/Callout.module.css +44 -18
- package/assets/components/Callout/Callout.tsx +9 -4
- package/assets/components/Callout/index.ts +1 -1
- package/assets/components/Canvas/Canvas.module.css +13 -0
- package/assets/components/Canvas/Canvas.tsx +378 -94
- package/assets/components/Canvas/clipboard.ts +5 -1
- package/assets/components/Canvas/collision.ts +5 -1
- package/assets/components/Canvas/graph.ts +14 -5
- package/assets/components/Canvas/history.ts +11 -4
- package/assets/components/Canvas/index.ts +2 -1
- package/assets/components/Canvas/types.ts +36 -1
- package/assets/components/CanvasEdge/tokens.css +14 -1
- package/assets/components/CanvasNode/tokens.css +13 -10
- package/assets/components/ChatComposer/ChatComposer.tsx +1 -1
- package/assets/components/ChatInput/ChatInput.tsx +1 -1
- package/assets/components/ColorField/ColorField.module.css +6 -1
- package/assets/components/ColorPicker/ColorPicker.module.css +3 -0
- package/assets/components/CommandPalette/CommandPalette.module.css +114 -0
- package/assets/components/CommandPalette/CommandPalette.tsx +206 -21
- package/assets/components/CommandPalette/index.ts +1 -0
- package/assets/components/Drawer/Drawer.module.css +30 -0
- package/assets/components/Drawer/Drawer.tsx +75 -16
- package/assets/components/Drawer/index.ts +1 -0
- package/assets/components/FileIcon/FileIcon.tsx +1 -0
- package/assets/components/FileIcon/fileExtMap.ts +1 -0
- package/assets/components/Icon/Icon.tsx +3 -0
- package/assets/components/Input/Input.module.css +3 -3
- package/assets/components/Onboarding/OnboardingAxisPanel.tsx +1 -1
- package/assets/components/Onboarding/OnboardingPage.tsx +13 -11
- package/assets/components/Onboarding/actions.ts +9 -9
- package/assets/components/Select/Select.module.css +1 -1
- package/assets/components/SocialLoginButton/SocialLoginButton.module.css +198 -0
- package/assets/components/SocialLoginButton/SocialLoginButton.tsx +86 -0
- package/assets/components/SocialLoginButton/assets/amazon.svg +1 -0
- package/assets/components/SocialLoginButton/assets/apple.svg +3 -0
- package/assets/components/SocialLoginButton/assets/discord.svg +3 -0
- package/assets/components/SocialLoginButton/assets/facebook-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/facebook.png +0 -0
- package/assets/components/SocialLoginButton/assets/github.svg +3 -0
- package/assets/components/SocialLoginButton/assets/google-mark.png +0 -0
- package/assets/components/SocialLoginButton/assets/kakao.svg +3 -0
- package/assets/components/SocialLoginButton/assets/line-icon.png +0 -0
- package/assets/components/SocialLoginButton/assets/line-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/linkedin-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/linkedin.png +0 -0
- package/assets/components/SocialLoginButton/assets/microsoft.svg +6 -0
- package/assets/components/SocialLoginButton/assets/naver.png +0 -0
- package/assets/components/SocialLoginButton/assets/slack.svg +17 -0
- package/assets/components/SocialLoginButton/assets/spotify.svg +3 -0
- package/assets/components/SocialLoginButton/assets/twitch.svg +21 -0
- package/assets/components/SocialLoginButton/assets/wechat.png +0 -0
- package/assets/components/SocialLoginButton/assets/x.svg +3 -0
- package/assets/components/SocialLoginButton/index.ts +2 -0
- package/assets/components/SocialLoginButton/provider-tokens.css +30 -0
- package/assets/components/SocialLoginButton/providers.ts +23 -0
- package/assets/components/TableRowEdit/TableRowEdit.tsx +2 -2
- package/assets/components/ThemeController.tsx +2 -2
- package/assets/components/TimelineView/TimelineView.tsx +4 -2
- package/assets/components/Tooltip/Tooltip.module.css +1 -0
- package/assets/components/_data.ts +1 -1
- package/assets/components/_utils.css +1 -0
- package/assets/components/component-registry.json +30 -1
- package/assets/components/index.ts +1 -0
- package/assets/components/side-effect-css.d.ts +5 -0
- package/assets/components/themeBootScript.ts +7 -1
- package/assets/components/tokens.css +14 -6
- package/assets/prompts/ASSEMBLY.md +4 -0
- package/assets/prompts/CASCADE.md +2 -2
- package/assets/prompts/CATALOG.md +2 -1
- package/assets/prompts/PRINCIPLES.md +4 -8
- package/assets/prompts/RULES.md +19 -1
- package/assets/prompts/SLOTS.md +2 -4
- package/assets/prompts/WORKFLOW_DESIGN.md +0 -4
- package/assets/prompts/axes/icon.md +1 -1
- package/assets/prompts/axes/material.md +4 -4
- package/assets/prompts/axes/motion.md +1 -1
- package/assets/prompts/axes/shape.md +2 -2
- package/assets/prompts/axes/voice.md +1 -1
- package/assets/prompts/components/_variants.md +4 -4
- package/assets/prompts/components/accordion.md +4 -4
- package/assets/prompts/components/ai-message.md +6 -2
- package/assets/prompts/components/attachment-item.md +2 -2
- package/assets/prompts/components/breadcrumb.md +11 -5
- package/assets/prompts/components/button.md +3 -3
- package/assets/prompts/components/callout.md +8 -4
- package/assets/prompts/components/canvas-edge.md +1 -1
- package/assets/prompts/components/canvas-node.md +1 -1
- package/assets/prompts/components/canvas.md +24 -8
- package/assets/prompts/components/card.md +1 -2
- package/assets/prompts/components/chart-bar.md +1 -1
- package/assets/prompts/components/chat-input.md +1 -1
- package/assets/prompts/components/checkbox.md +5 -5
- package/assets/prompts/components/color-field.md +2 -2
- package/assets/prompts/components/command-palette.md +55 -47
- package/assets/prompts/components/context-menu.md +5 -5
- package/assets/prompts/components/date-picker.md +2 -2
- package/assets/prompts/components/drawer.md +17 -3
- package/assets/prompts/components/dropdown-menu.md +3 -3
- package/assets/prompts/components/event-list-item.md +4 -4
- package/assets/prompts/components/file-icon.md +2 -2
- package/assets/prompts/components/gallery-item.md +1 -1
- package/assets/prompts/components/hint.md +3 -3
- package/assets/prompts/components/kanban.md +2 -3
- package/assets/prompts/components/list-item.md +12 -12
- package/assets/prompts/components/menu-item.md +2 -2
- package/assets/prompts/components/message-table.md +4 -4
- package/assets/prompts/components/onboarding.md +3 -3
- package/assets/prompts/components/page-header.md +6 -7
- package/assets/prompts/components/quotation-bar.md +1 -1
- package/assets/prompts/components/select.md +1 -1
- package/assets/prompts/components/shortcut.md +3 -3
- package/assets/prompts/components/sidebar.md +5 -4
- package/assets/prompts/components/social-login-button.md +117 -0
- package/assets/prompts/components/stepper.md +1 -1
- package/assets/prompts/components/tab-strip.md +2 -2
- package/assets/prompts/components/table-row-edit.md +6 -6
- package/assets/prompts/components/table-row-select.md +1 -1
- package/assets/prompts/components/tabs.md +5 -2
- package/assets/prompts/components/textarea.md +1 -1
- package/assets/prompts/components/toast.md +3 -3
- package/assets/prompts/components/tooltip.md +3 -3
- package/assets/prompts/components/topbar.md +1 -1
- package/assets/prompts/design-examples/ai-chat-full-page.png +0 -0
- package/assets/prompts/design-examples/catalog.json +9 -9
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.module.css +37 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.tsx +113 -18
- package/assets/prompts/design-examples/sources/ai-chat-full-page/FullPageChat.tsx +2 -2
- package/assets/prompts/design-examples/sources/ai-chat-full-page/REFERENCE.md +3 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useChatDemo.ts +99 -51
- package/assets/prompts/primitives/scroll.md +1 -1
- package/assets/prompts/recipes/README.md +5 -6
- package/assets/prompts/recipes/meta-line.md +2 -2
- package/assets/prompts/recipes/page-header.md +2 -2
- package/assets/prompts/recipes/section-header.md +1 -1
- package/assets/prompts/themes/_SCHEMA.md +2 -2
- package/assets/prompts/tokens/material.md +5 -2
- package/assets/prompts/tokens/radius.md +1 -1
- package/assets/prompts/use-cases/chat-chat-input.md +382 -74
- package/assets/prompts/use-cases/data-list-item.md +38 -431
- package/assets/prompts/use-cases/feedback-drawer.md +112 -33
- package/assets/prompts/use-cases/overlay-command-palette.md +2004 -0
- package/assets/prompts/use-cases/structure-canvas.md +1016 -0
- package/assets/skills/ovenn-validate/SKILL.md +1 -1
- package/assets/skills/ovenn-validate/scripts/lib/component-usage.js +7 -1
- package/assets/skills/ovenn-validate/scripts/lib/engine.mjs +105 -0
- package/assets/skills/ovenn-validate/scripts/lib/engine.test.mjs +46 -0
- package/assets/skills/ovenn-validate/scripts/lib/source-utils.mjs +5 -3
- package/assets/skills/ovenn-validate/scripts/rules/doc-sync.mjs +28 -5
- package/assets/skills/ovenn-validate/scripts/rules/doc-sync.test.mjs +15 -0
- package/assets/skills/ovenn-validate/scripts/rules/ghost-tokens.mjs +7 -0
- package/assets/skills/ovenn-validate/scripts/rules/hardcoded.mjs +61 -30
- package/assets/skills/ovenn-validate/scripts/rules/memory-rules.mjs +7 -4
- package/assets/skills/ovenn-validate/scripts/rules/memory-rules.test.mjs +3 -0
- package/assets/skills/ovenn-validate/scripts/validate.mjs +8 -136
- package/assets/skills/ovenn-wireframe/SKILL.md +1 -1
- package/bin/ovenn.js +8 -0
- package/package.json +2 -2
- package/src/commands/check.js +70 -0
- package/src/commands/info.js +32 -7
- package/src/commands/init.js +26 -30
- package/src/commands/setup-checks.js +80 -0
- package/src/commands/update.js +90 -18
- package/src/data/ctds-releases.json +1 -0
- package/src/utils/assets.js +5 -0
- package/src/utils/component-usage.js +7 -1
- package/src/utils/design-workflow.js +6 -2
- package/src/utils/doctor.js +7 -1
- package/src/utils/legacy-ctds.js +169 -0
- package/src/utils/managed-assets.js +16 -3
- package/src/utils/route.js +17 -0
- package/src/utils/rules-context.js +91 -0
- package/src/utils/update-transaction.js +16 -3
- package/assets/prompts/FEEDBACK_PROCESS.md +0 -19
- package/assets/prompts/GUIDE.md +0 -307
- package/assets/prompts/MEMORY.md +0 -202
- package/assets/prompts/TEMPLATE_PREVIEWS.md +0 -21
- package/assets/prompts/components/README.md +0 -84
|
@@ -9,6 +9,6 @@ description: 선언된 프로젝트 토큰과 사용처 리터럴, 미선언 변
|
|
|
9
9
|
|
|
10
10
|
필요한 행동은 전체 `prompts/CATALOG.md`에서 찾고 해당 문서의 Do/Don't·Props와 실제 컴포넌트 코드를 확인한다. 클라이언트의 실행·캡처·독립 검수 기능이 없으면 원본의 검수 대기 계약을 따른다. 검사 통과를 화면 검수로 대신하지 않는다.
|
|
11
11
|
|
|
12
|
-
로컬 규칙 검사는 이 스킬의 `scripts/validate.mjs
|
|
12
|
+
로컬 규칙 검사는 `npx @conscience-technology/ovenn check [경로]`로 실행한다(서버 불필요, 위반 시 종료 코드 1, 기본 범위에서 `components/ovenn` 제외). 이 스킬의 `scripts/validate.mjs`도 같은 엔진이다. 정당한 예외는 `ovenn-validate-disable-next-line <규칙>` 또는 이유를 붙인 `ovenn-validate-disable-file <규칙> -- <이유>`로 표시한다. 결과는 자동 검사 증거이며 독립 시각 검수와 구분한다. `hard/*` 규칙은 `prompts/RULES.md`의 필수 규칙 중 정적으로 잡히는 것(em dash·구분 문자·IconButton 라벨·placeholder 전용 입력·상호작용 중첩은 error, filled 배경·액티브바는 review)이다.
|
|
13
13
|
|
|
14
14
|
조립 전 역할별 componentPlan과 실제 부품 사용 검증은 `prompts/ASSEMBLY.md`의 v2 계약을 따른다. MCP의 `check_component_usage` 또는 `ovenn info check-component-usage --local`로 확인한다.
|
|
@@ -10,8 +10,14 @@ const digest=value=>createHash('sha256').update(value).digest('hex');
|
|
|
10
10
|
export function componentExports(source){return [...new Set([...source.matchAll(/export\s*\{([^}]+)\}/g)].flatMap(match=>match[1].split(',').map(value=>value.trim()).filter(value=>value&&!value.startsWith('type ')).map(value=>value.split(/\s+as\s+/).at(-1))))];}
|
|
11
11
|
function exportFolder(registry,name,files={},base='components/') {return registry.find(entry=>entry.status!=='wip'&&(entry.folder===name||(entry.exports||componentExports(files[base+entry.folder+'/index.ts']||'')).includes(name)))?.folder;}
|
|
12
12
|
export function componentContract(text){const match=text.match(/<!-- component-contract -->\s*```json\s*([\s\S]*?)```/);return match?JSON.parse(match[1]):null;}
|
|
13
|
+
// The checks parse with TypeScript's JS compiler API. TypeScript 7's `typescript` package no longer exposes it,
|
|
14
|
+
// so a TS 7 project resolves it from @typescript/typescript6, the compatibility package Microsoft publishes for tools.
|
|
13
15
|
export function loadTypeScript(root=process.cwd()){
|
|
14
|
-
|
|
16
|
+
let native=null;
|
|
17
|
+
for(const base of [root,path.join(root,'web')])for(const name of ['typescript','@typescript/typescript6']){
|
|
18
|
+
try{const ts=createRequire(path.join(base,'package.json'))(name);if(typeof ts.createSourceFile==='function'&&typeof ts.preProcessFile==='function')return ts;native??=ts.version;}catch{}
|
|
19
|
+
}
|
|
20
|
+
if(native)throw new Error(`TypeScript ${native} has no JS compiler API, which this check needs. Install the compatibility package next to it: npm install -D @typescript/typescript6. No packages were installed automatically.`);
|
|
15
21
|
throw new Error('TypeScript parser is unavailable. Use a project with TypeScript installed; no packages were installed automatically.');
|
|
16
22
|
}
|
|
17
23
|
export function planSchema(){return {type:'object',additionalProperties:false,required:['version','scope','direction','roles'],properties:{version:{type:'string',enum:['2']},scope:{type:'string',enum:['page','partial','component']},direction:{type:'string',minLength:1},roles:{type:'array',minItems:1,items:{type:'object',additionalProperties:false,required:['id','purpose','component','components','strategy','source','originalHash','reason','requires','sourceFiles','evidence'],properties:{id:{type:'string'},purpose:{type:'string'},component:{type:'string'},components:{type:'array',items:{type:'string'}},strategy:{type:'string',enum:['reuse','compose','derived','custom','preserved']},source:{type:'string'},originalHash:{type:'string'},reason:{type:'string'},requires:{type:'array',items:{type:'string'}},sourceFiles:{type:'array',items:{type:'string'}},evidence:{type:'array',items:{type:'string'}}}}}}};}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// One validation engine for every entry point: `ovenn check`, this skill's validate.mjs and the MCP check_hardcoding tool.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { checkHardcoded } from '../rules/hardcoded.mjs';
|
|
5
|
+
import { checkGhostTokens, loadDeclaredTokens } from '../rules/ghost-tokens.mjs';
|
|
6
|
+
import { checkMemoryRules } from '../rules/memory-rules.mjs';
|
|
7
|
+
import { checkDocSync } from '../rules/doc-sync.mjs';
|
|
8
|
+
import { checkHardRules } from '../rules/hard-rules.mjs';
|
|
9
|
+
|
|
10
|
+
export const SOURCE_EXT = new Set(['.tsx', '.ts', '.jsx', '.js', '.mjs', '.css']);
|
|
11
|
+
const SKIP_DIRS = new Set(['node_modules', '.next', '.git', '.ovenn', '.turbo', '.vercel', 'out', 'dist', 'build', 'coverage']);
|
|
12
|
+
|
|
13
|
+
function globToRegex(glob) {
|
|
14
|
+
let re = '^';
|
|
15
|
+
for (let i = 0; i < glob.length; i++) {
|
|
16
|
+
const c = glob[i];
|
|
17
|
+
if (c === '*') {
|
|
18
|
+
if (glob[i + 1] === '*') { re += '.*'; i++; if (glob[i + 1] === '/') i++; } else re += '[^/]*';
|
|
19
|
+
} else if (c === '?') re += '[^/]';
|
|
20
|
+
else if ('.+^$(){}|[]\\'.includes(c)) re += '\\' + c;
|
|
21
|
+
else re += c;
|
|
22
|
+
}
|
|
23
|
+
return new RegExp(re + '$');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function walk(dir, out) {
|
|
27
|
+
let entries;
|
|
28
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
29
|
+
for (const e of entries) {
|
|
30
|
+
if (SKIP_DIRS.has(e.name) || e.isSymbolicLink()) continue;
|
|
31
|
+
const full = path.join(dir, e.name);
|
|
32
|
+
if (e.isDirectory()) walk(full, out); else if (e.isFile()) out.push(full);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Files, folders or globs relative to root. `exclude` holds root-relative folder prefixes left out of folder and glob matches. */
|
|
37
|
+
export function collectFiles(root, patterns, { exclude = [] } = {}) {
|
|
38
|
+
const matched = new Set(), all = [];
|
|
39
|
+
const excluded = (rel) => exclude.some((prefix) => rel === prefix || rel.startsWith(`${prefix}/`));
|
|
40
|
+
for (const pattern of patterns) {
|
|
41
|
+
const full = path.resolve(root, pattern);
|
|
42
|
+
const stat = fs.existsSync(full) ? fs.statSync(full) : null;
|
|
43
|
+
if (stat?.isFile()) { matched.add(full); continue; }
|
|
44
|
+
if (stat?.isDirectory()) {
|
|
45
|
+
const found = []; walk(full, found);
|
|
46
|
+
for (const f of found) if (!excluded(rel(root, f))) matched.add(f);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!all.length) walk(root, all);
|
|
50
|
+
const re = globToRegex(pattern.replace(/^\.\//, ''));
|
|
51
|
+
for (const f of all) if (re.test(rel(root, f)) && !excluded(rel(root, f))) matched.add(f);
|
|
52
|
+
}
|
|
53
|
+
return [...matched].sort();
|
|
54
|
+
}
|
|
55
|
+
const rel = (root, file) => path.relative(root, file).split(path.sep).join('/');
|
|
56
|
+
|
|
57
|
+
// `/* ovenn-validate-disable-file hardcoded/hex-color -- brand colours are the format signal */` turns rules off for a file;
|
|
58
|
+
// `ovenn-validate-disable-next-line <rules>` and the repository linter's `/* lint-hardcoded: ignore */` (same or previous line) for one line.
|
|
59
|
+
function suppressions(content) {
|
|
60
|
+
const file = new Set(), lines = new Map();
|
|
61
|
+
const add = (line, ids) => { const set = lines.get(line) ?? new Set(); for (const id of ids) set.add(id); lines.set(line, set); };
|
|
62
|
+
content.split('\n').forEach((text, index) => {
|
|
63
|
+
const whole = text.match(/ovenn-validate-disable-file\s+([\w\-/,*\s]+?)\s+--\s+\S/);
|
|
64
|
+
if (whole) for (const id of whole[1].split(/[\s,]+/).filter(Boolean)) file.add(id);
|
|
65
|
+
const next = text.match(/ovenn-validate-disable-next-line\s+([\w\-/,*\s]+)/);
|
|
66
|
+
if (next) add(index + 2, next[1].split(/[\s,]+/).filter(Boolean));
|
|
67
|
+
if (/lint-hardcoded:\s*ignore/.test(text)) { add(index + 1, ['hardcoded']); add(index + 2, ['hardcoded']); }
|
|
68
|
+
});
|
|
69
|
+
const matches = (set, ruleId) => set.has(ruleId) || set.has(ruleId.split('/')[0]) || set.has(`${ruleId.split('/')[0]}/*`);
|
|
70
|
+
return (line, ruleId) => matches(file, ruleId) || (lines.has(line) && matches(lines.get(line), ruleId));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Rules over one source text. Without `declared`, undeclared-token checks are skipped (no project to resolve against).
|
|
75
|
+
* @param {{ code: string, ext: string, rel?: string, declared?: Set<string> }} input
|
|
76
|
+
*/
|
|
77
|
+
export function validateSource({ code, ext, rel: name = `input${ext}`, declared }) {
|
|
78
|
+
const ctx = { file: name, rel: name, content: code, ext };
|
|
79
|
+
// Tests are not shipped UI; their fixtures deliberately contain literals.
|
|
80
|
+
if (!SOURCE_EXT.has(ext) || /\.test\.[cm]?[jt]sx?$/.test(name)) return [];
|
|
81
|
+
const suppressed = suppressions(code);
|
|
82
|
+
return [
|
|
83
|
+
...checkHardcoded(ctx), ...(declared ? checkGhostTokens(ctx, declared) : []), ...checkMemoryRules(ctx), ...checkHardRules(ctx),
|
|
84
|
+
].filter((v) => !suppressed(v.line, v.ruleId)).map((v) => ({ ...v, rel: name }));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Rules over project files; returns violations sorted by file and line. */
|
|
88
|
+
export function validateFiles(root, files, { docSync = true } = {}) {
|
|
89
|
+
const declared = loadDeclaredTokens(root);
|
|
90
|
+
const violations = [];
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
const ext = path.extname(file);
|
|
93
|
+
violations.push(...validateSource({ code: fs.readFileSync(file, 'utf8'), ext, rel: rel(root, file), declared }));
|
|
94
|
+
}
|
|
95
|
+
if (docSync) violations.push(...checkDocSync(files, root));
|
|
96
|
+
violations.sort((a, b) => a.rel.localeCompare(b.rel) || a.line - b.line);
|
|
97
|
+
const errors = violations.filter((v) => v.severity !== 'review');
|
|
98
|
+
return { files: files.length, violations, errors: errors.length, reviews: violations.length - errors.length };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function formatReport(report) {
|
|
102
|
+
if (!report.violations.length) return `0개 위반 (${report.files}개 파일 검사)\n`;
|
|
103
|
+
const lines = report.violations.map((v) => `${v.rel}:${v.line} — ${v.severity === 'review' ? 'REVIEW' : 'ERROR'} — ${v.ruleId} — ${v.message}${v.suggest ? `\n 제안: ${v.suggest}` : ''}`);
|
|
104
|
+
return `${lines.join('\n')}\n\n${report.errors}개 오류, ${report.reviews}개 검토 (${new Set(report.violations.map((v) => v.rel)).size}개 파일)\n`;
|
|
105
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { validateSource, validateFiles, collectFiles } from './engine.mjs';
|
|
7
|
+
|
|
8
|
+
const ids = (violations) => violations.map((v) => `${v.line}:${v.ruleId}`);
|
|
9
|
+
|
|
10
|
+
test('a custom property spanning lines is a definition, and lines after a comment keep their numbers', () => {
|
|
11
|
+
const css = '/* one\n two */\n:root {\n --ring:\n 0 0 0 2px oklch(0.6 0.1 250);\n}\n.x { color: #f00; }\n';
|
|
12
|
+
assert.deepEqual(ids(validateSource({ code: css, ext: '.css' })), ['7:hardcoded/hex-color']);
|
|
13
|
+
});
|
|
14
|
+
test('idioms are not design values: inherit, em, pills, mask stops, grid tracks', () => {
|
|
15
|
+
const css = '.a { font-family: inherit; width: 1em; border-radius: 999px; mask-image: linear-gradient(#000, transparent); grid-template-columns: 240px 1fr; }';
|
|
16
|
+
assert.deepEqual(validateSource({ code: css, ext: '.css' }), []);
|
|
17
|
+
});
|
|
18
|
+
test('bare numbers count as px only inside JSX style objects', () => {
|
|
19
|
+
const tsx = 'const box = { left: 2, top: 3 };\nexport const A = () => <div style={{ padding: 13, opacity: 1 }} />;\n';
|
|
20
|
+
assert.deepEqual(ids(validateSource({ code: tsx, ext: '.tsx' })), ['2:hardcoded/size']);
|
|
21
|
+
});
|
|
22
|
+
test('suppressions: next-line, the repository marker, and file-level only with a reason', () => {
|
|
23
|
+
assert.deepEqual(validateSource({ code: '/* ovenn-validate-disable-next-line hardcoded/hex-color */\n.a { color: #f00; }', ext: '.css' }), []);
|
|
24
|
+
assert.deepEqual(validateSource({ code: '.a { color: #f00; } /* lint-hardcoded: ignore */', ext: '.css' }), []);
|
|
25
|
+
assert.deepEqual(validateSource({ code: '/* ovenn-validate-disable-file hardcoded -- token layer */\n.a { color: #f00; }', ext: '.css' }), []);
|
|
26
|
+
assert.equal(validateSource({ code: '/* ovenn-validate-disable-file hardcoded */\n.a { color: #f00; }', ext: '.css' }).length, 1);
|
|
27
|
+
});
|
|
28
|
+
test('tokens set at runtime from TSX or completed at runtime are declared', (t) => {
|
|
29
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ovenn-engine-'));
|
|
30
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
31
|
+
fs.mkdirSync(path.join(root, 'components'));
|
|
32
|
+
fs.writeFileSync(path.join(root, 'components/Zoom.tsx'), 'export const Z = () => <div style={{ "--zoom": 2 } as never} />;\n');
|
|
33
|
+
fs.writeFileSync(path.join(root, 'components/zoom.module.css'), '.z { scale: var(--zoom); color: var(--chart-${1}); fill: var(--missing); }\n');
|
|
34
|
+
fs.writeFileSync(path.join(root, 'components/zoom.test.mjs'), "const c = '#f00';\n");
|
|
35
|
+
const report = validateFiles(root, collectFiles(root, ['components']), { docSync: false });
|
|
36
|
+
assert.deepEqual(report.violations.map((v) => `${v.rel}:${v.ruleId}:${v.message.split(': ')[1]}`), ['components/zoom.module.css:ghost-token/undeclared:--missing']);
|
|
37
|
+
});
|
|
38
|
+
test('folder matches leave out excluded prefixes, explicit files do not', (t) => {
|
|
39
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ovenn-engine-'));
|
|
40
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
41
|
+
fs.mkdirSync(path.join(root, 'components/ovenn'), { recursive: true });
|
|
42
|
+
fs.writeFileSync(path.join(root, 'components/ovenn/a.css'), '');
|
|
43
|
+
fs.writeFileSync(path.join(root, 'components/b.css'), '');
|
|
44
|
+
assert.deepEqual(collectFiles(root, ['components'], { exclude: ['components/ovenn'] }).map((f) => path.relative(root, f)), ['components/b.css']);
|
|
45
|
+
assert.equal(collectFiles(root, ['components/ovenn/a.css'], { exclude: ['components/ovenn'] }).length, 1);
|
|
46
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
// Blank out comments but keep every newline, so offsets and line numbers still point at the original source.
|
|
2
|
+
const blank = (text) => text.replace(/[^\n]/g, ' ');
|
|
1
3
|
export function stripComments(src, ext) {
|
|
2
|
-
if (ext === '.css') return src.replace(/\/\*[\s\S]*?\*\//g,
|
|
4
|
+
if (ext === '.css') return src.replace(/\/\*[\s\S]*?\*\//g, blank);
|
|
3
5
|
return src
|
|
4
|
-
.replace(/\/\*[\s\S]*?\*\//g,
|
|
5
|
-
.replace(/(^|[^:])\/\/[^\n]*/g, (m, p) => p +
|
|
6
|
+
.replace(/\/\*[\s\S]*?\*\//g, blank)
|
|
7
|
+
.replace(/(^|[^:])\/\/[^\n]*/g, (m, p) => p + blank(m.slice(p.length)));
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export function lineOf(src, idx) {
|
|
@@ -29,17 +29,21 @@ function extractEnumsFromMd(src) {
|
|
|
29
29
|
const propsBlock = src.match(/```tsx[\s\S]*?```/);
|
|
30
30
|
if (propsBlock) {
|
|
31
31
|
const code = propsBlock[0];
|
|
32
|
-
|
|
32
|
+
// `trailingSlot={<Avatar size="xs" />}`: attributes of an element passed inside a prop belong to that child.
|
|
33
|
+
const rootLines = code.split('\n').filter((line) => !/\{\s*<[A-Z]\w*[^>]*\b(?:variant|size)\s*=/.test(line));
|
|
34
|
+
const rootCode = rootLines.join('\n');
|
|
35
|
+
for (const m of rootCode.matchAll(/\bvariant\s*=\s*["']([^"']+)["']/g)) {
|
|
33
36
|
for (const v of m[1].split(/\s*\|\s*/)) enums.variant.add(v.trim());
|
|
34
37
|
}
|
|
35
|
-
for (const m of
|
|
38
|
+
for (const m of rootCode.matchAll(/\bsize\s*=\s*["']([^"']+)["']/g)) {
|
|
36
39
|
for (const v of m[1].split(/\s*\|\s*/)) enums.size.add(v.trim());
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
const variantTableRe = /\|\s*`?([a-zA-Z][a-zA-Z0-9_-]*)`?\s*\|/g;
|
|
40
43
|
const variantSectionMatch = src.match(/###\s*Variant[\s\S]*?(?=\n### |\n## |$)/);
|
|
41
44
|
if (variantSectionMatch) {
|
|
42
|
-
|
|
45
|
+
// Only the section's first table; a later "상태 조합" table lists states, not variants.
|
|
46
|
+
const tableRows = (variantSectionMatch[0].match(/(?:^\|[^\n]+\|\n?)+/m)?.[0] ?? '').match(/\|[^\n]+\|/g) || [];
|
|
43
47
|
for (const row of tableRows) {
|
|
44
48
|
const first = row.match(/\|\s*`([^`]+)`/);
|
|
45
49
|
if (first) enums.variant.add(first[1]);
|
|
@@ -47,7 +51,8 @@ function extractEnumsFromMd(src) {
|
|
|
47
51
|
}
|
|
48
52
|
const sizeSectionMatch = src.match(/###\s*Size[\s\S]*?(?=\n### |\n## |$)/);
|
|
49
53
|
if (sizeSectionMatch) {
|
|
50
|
-
|
|
54
|
+
// Only the section's first table; a later "상태 조합" table lists states, not sizes.
|
|
55
|
+
const tableRows = (sizeSectionMatch[0].match(/(?:^\|[^\n]+\|\n?)+/m)?.[0] ?? '').match(/\|[^\n]+\|/g) || [];
|
|
51
56
|
for (const row of tableRows) {
|
|
52
57
|
const first = row.match(/\|\s*`([^`]+)`/);
|
|
53
58
|
if (first) enums.size.add(first[1]);
|
|
@@ -56,6 +61,17 @@ function extractEnumsFromMd(src) {
|
|
|
56
61
|
return enums;
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
const escape = (x) => x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
65
|
+
// Written as code, in bold, or inside a quoted union such as "sm | md | lg".
|
|
66
|
+
function mentionedAsCode(doc, value) {
|
|
67
|
+
if (new RegExp(`[\`"']${escape(value)}[\`"']|\\*\\*${escape(value)}\\*\\*`).test(doc)) return true;
|
|
68
|
+
return [...doc.matchAll(/[`"']([^`"'\n]*\|[^`"'\n]*)[`"']/g)].some((m) => m[1].split('|').map((t) => t.trim()).includes(value));
|
|
69
|
+
}
|
|
70
|
+
function presentInCode(tsx, value) {
|
|
71
|
+
if (/^--|[<>{}]/.test(value)) return true;
|
|
72
|
+
return new RegExp(`["'\`]${escape(value)}["'\`]|\\b${escape(value)}\\??\\s*:`).test(tsx);
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
function diffSets(aSet, bSet) {
|
|
60
76
|
const onlyA = [...aSet].filter((x) => !bSet.has(x));
|
|
61
77
|
const onlyB = [...bSet].filter((x) => !aSet.has(x));
|
|
@@ -84,7 +100,10 @@ export function checkDocSync(files, repoRoot) {
|
|
|
84
100
|
if (docM) docsByName.set(docM[1], { file: f, rel });
|
|
85
101
|
}
|
|
86
102
|
|
|
103
|
+
const internal = new Set();
|
|
104
|
+
if (fs.existsSync(manifestPath)) for (const entry of JSON.parse(fs.readFileSync(manifestPath, 'utf8')).entries ?? []) if (entry.status === 'internal') internal.add(entry.folder);
|
|
87
105
|
for (const [name, meta] of componentsByName) {
|
|
106
|
+
if (internal.has(name)) continue;
|
|
88
107
|
const kebab = pascalToKebab(name);
|
|
89
108
|
const doc = docsByName.get(kebab);
|
|
90
109
|
const tsxSrc = fs.readFileSync(meta.file, 'utf8');
|
|
@@ -108,7 +127,11 @@ export function checkDocSync(files, repoRoot) {
|
|
|
108
127
|
for (const field of ['variant', 'size']) {
|
|
109
128
|
if (tsxEnums[field].size === 0 && docEnums[field].size === 0) continue;
|
|
110
129
|
if (tsxEnums[field].size === 0 || docEnums[field].size === 0) continue;
|
|
111
|
-
|
|
130
|
+
// The structured extraction only reads the first tsx block and the Variant/Size tables, so check the rest too:
|
|
131
|
+
// a code value written as code anywhere in the doc is documented; a doc value that is another prop's literal
|
|
132
|
+
// (tone, layout, status), a prop or state name, a token or a placeholder is not a missing variant.
|
|
133
|
+
const onlyA = [...tsxEnums[field]].filter((x) => !docEnums[field].has(x) && !mentionedAsCode(docSrc, x));
|
|
134
|
+
const onlyB = [...docEnums[field]].filter((x) => !tsxEnums[field].has(x) && !presentInCode(tsxSrc, x));
|
|
112
135
|
if (onlyA.length > 0) {
|
|
113
136
|
violations.push({
|
|
114
137
|
rel: docRel,
|
|
@@ -89,3 +89,18 @@ test('manifest maps adapter docs to a shared component folder', (t) => {
|
|
|
89
89
|
const v = checkDocSync([md], root);
|
|
90
90
|
assert.equal(v.some((x) => x.ruleId === 'doc-sync/missing-code'), false);
|
|
91
91
|
});
|
|
92
|
+
|
|
93
|
+
test('documented elsewhere in the doc, child-element props and state tables are not mismatches', (t) => {
|
|
94
|
+
const root = makeRepo(t);
|
|
95
|
+
const tsx = writeFile(root, 'web/components/Widget/Widget.tsx',
|
|
96
|
+
'export type WidgetVariant = "a" | "b" | "framed";\nexport type WidgetSize = "sm" | "md" | "lg";\nexport interface P { disabled?: boolean }');
|
|
97
|
+
const md = writeFile(root, 'prompts/components/widget.md',
|
|
98
|
+
'### Props 시그니처\n```tsx\n<Widget\n variant="a | b"\n size="sm | md"\n slot={<Avatar size="xs" />}\n/>\n```\n- **framed**: 테두리와 그림자\n\n접기 버튼은 `size="sm | md | lg"`.\n\n### Variant 매트릭스\n| variant | 용도 |\n|---|---|\n| `a` | 기본 |\n\n**상태 조합:**\n\n| 상태 | 반응 |\n|---|---|\n| `disabled` | 흐림 |');
|
|
99
|
+
assert.deepEqual(checkDocSync([tsx, md], root).filter((x) => x.ruleId.startsWith('doc-sync/')), []);
|
|
100
|
+
});
|
|
101
|
+
test('internal components need no prompt document', (t) => {
|
|
102
|
+
const root = makeRepo(t);
|
|
103
|
+
fs.writeFileSync(path.join(root, 'component-manifest.json'), JSON.stringify({ entries: [{ folder: 'Boundary', status: 'internal', prompts: [] }] }));
|
|
104
|
+
const tsx = writeFile(root, 'web/components/Boundary/Boundary.tsx', 'export function Boundary() { return null; }');
|
|
105
|
+
assert.deepEqual(checkDocSync([tsx], root), []);
|
|
106
|
+
});
|
|
@@ -4,6 +4,7 @@ import { stripComments, lineOf } from '../lib/source-utils.mjs';
|
|
|
4
4
|
|
|
5
5
|
const DECL_RE = /--([\w-]+)\s*:/g;
|
|
6
6
|
const USE_RE = /var\(\s*--([\w-]+)(\s*,)?/g;
|
|
7
|
+
const RUNTIME_DECL_RE = /["'`]--([\w-]+)["'`]\s*[:,\]]/g;
|
|
7
8
|
const RUNTIME_TOKENS = new Set(['tail']);
|
|
8
9
|
const RUNTIME_TOKEN_PATTERNS = [
|
|
9
10
|
/^(?:tab-indicator|at-ph|fi)-/,
|
|
@@ -20,6 +21,10 @@ function collectCssDeclarations(directory, tokens) {
|
|
|
20
21
|
else if (entry.isFile() && entry.name.endsWith('.css')) {
|
|
21
22
|
const src = fs.readFileSync(full, 'utf8');
|
|
22
23
|
for (const match of src.matchAll(DECL_RE)) tokens.add(match[1]);
|
|
24
|
+
} else if (entry.isFile() && /\.[jt]sx?$/.test(entry.name) && !/\.test\./.test(entry.name)) {
|
|
25
|
+
// Properties set at runtime: style={{ "--canvas-zoom": zoom }} and el.style.setProperty("--x", v).
|
|
26
|
+
const src = fs.readFileSync(full, 'utf8');
|
|
27
|
+
for (const match of src.matchAll(RUNTIME_DECL_RE)) tokens.add(match[1]);
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -51,8 +56,10 @@ export function checkGhostTokens(ctx, declared) {
|
|
|
51
56
|
|
|
52
57
|
for (const m of src.matchAll(USE_RE)) {
|
|
53
58
|
const name = m[1];
|
|
59
|
+
// `var(--chart-${key})`: the name is completed at runtime.
|
|
54
60
|
if (
|
|
55
61
|
m[2] ||
|
|
62
|
+
name.endsWith('-') ||
|
|
56
63
|
name.startsWith('radix-') ||
|
|
57
64
|
RUNTIME_TOKENS.has(name) ||
|
|
58
65
|
RUNTIME_TOKEN_PATTERNS.some((pattern) => pattern.test(name))
|
|
@@ -5,24 +5,33 @@ const RGB_RE = /\b(rgb|rgba|hsl|hsla|oklch|oklab|lab|lch)\s*\(/gi;
|
|
|
5
5
|
const SIZE_RE = /(?<![\w.-])(\d+(?:\.\d+)?)(px|rem|em)\b/g;
|
|
6
6
|
const TIME_RE = /(?<![\w.-])(\d+(?:\.\d+)?)(ms|s)\b/g;
|
|
7
7
|
const FONT_FAMILY_JSX_RE = /fontFamily\s*:\s*(["'`])([^"'`]+)\1/g;
|
|
8
|
+
const INLINE_SIZE_RE = /\b((?:padding|margin|gap|rowGap|columnGap|width|height|minWidth|minHeight|maxWidth|maxHeight|top|left|right|bottom|inset|fontSize|lineHeight|borderRadius|letterSpacing)(?:Top|Right|Bottom|Left|Inline|Block)?)\s*:\s*(\d+(?:\.\d+)?)\s*[,}]/g;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const CSS_WIDE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
|
|
11
|
+
// Same structural exclusions as the repository linter: grid tracks, the autofill inset trick and offscreen a11y hiding.
|
|
12
|
+
// Plus mask gradients, whose colours are alpha stops.
|
|
13
|
+
function isStructural(prop, value) {
|
|
14
|
+
return /^grid-(?:template-(?:columns|rows|areas)|area)$/.test(prop)
|
|
15
|
+
|| (prop === '-webkit-box-shadow' && /\binset\b/.test(value))
|
|
16
|
+
|| /translate\(\s*-?9999px/.test(value)
|
|
17
|
+
// Mask gradients use colours only as alpha stops (`#000` opaque, `transparent` clear).
|
|
18
|
+
|| /^(?:-webkit-)?mask(?:-image)?$/.test(prop);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Declarations of the whole stylesheet with their source offsets. A custom property may span several lines
|
|
22
|
+
// (`--ring:\n 0 0 0 2px oklch(...)`), so splitting line by line would misread its value as a plain use.
|
|
23
|
+
function declarations(src) {
|
|
10
24
|
const out = [];
|
|
11
|
-
let depth = 0;
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (c === '{' || c === '}') {
|
|
16
|
-
if (i > start) out.push({ text: line.slice(start, i), offset: start });
|
|
17
|
-
out.push({ text: c, offset: i });
|
|
18
|
-
start = i + 1;
|
|
19
|
-
} else if (c === ';' && depth === 0) {
|
|
20
|
-
out.push({ text: line.slice(start, i), offset: start });
|
|
21
|
-
start = i + 1;
|
|
22
|
-
} else if (c === '(') depth++;
|
|
25
|
+
let depth = 0, start = 0;
|
|
26
|
+
for (let i = 0; i <= src.length; i++) {
|
|
27
|
+
const c = src[i];
|
|
28
|
+
if (c === '(') depth++;
|
|
23
29
|
else if (c === ')') depth--;
|
|
30
|
+
else if (i === src.length || c === '{' || c === '}' || (c === ';' && depth === 0)) {
|
|
31
|
+
if (src.slice(start, i).trim()) out.push({ text: src.slice(start, i), offset: start });
|
|
32
|
+
start = i + 1;
|
|
33
|
+
}
|
|
24
34
|
}
|
|
25
|
-
if (start < line.length) out.push({ text: line.slice(start), offset: start });
|
|
26
35
|
return out;
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -30,27 +39,26 @@ function checkCss(ctx) {
|
|
|
30
39
|
const { content } = ctx;
|
|
31
40
|
const src = stripComments(content, '.css');
|
|
32
41
|
const violations = [];
|
|
33
|
-
const lines = src.split('\n');
|
|
34
|
-
|
|
35
|
-
for (let li = 0; li < lines.length; li++) {
|
|
36
|
-
const rawLine = lines[li];
|
|
37
|
-
const lineNo = li + 1;
|
|
38
|
-
const decls = splitDeclarations(rawLine);
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
for (const d of declarations(src)) {
|
|
44
|
+
{
|
|
41
45
|
const seg = d.text;
|
|
42
|
-
if (seg === '{' || seg === '}' || !seg.trim()) continue;
|
|
43
46
|
const colonIdx = seg.indexOf(':');
|
|
44
|
-
|
|
47
|
+
// A selector ending in a pseudo-class (`a:hover`) is not a declaration; only `prop: value` segments are.
|
|
48
|
+
if (colonIdx < 0 || !/^\s*[-\w]+\s*$/.test(seg.slice(0, colonIdx))) continue;
|
|
49
|
+
const hasColon = true;
|
|
50
|
+
const valueOffset = d.offset + (hasColon ? colonIdx + 1 : 0);
|
|
51
|
+
const lineAt = (m) => lineOf(src, valueOffset + m.index);
|
|
45
52
|
const propPart = hasColon ? seg.slice(0, colonIdx) : '';
|
|
46
53
|
const valuePart = hasColon ? seg.slice(colonIdx + 1) : seg;
|
|
47
54
|
const isCustomPropDecl = /--[\w-]+\s*$/.test(propPart.trim());
|
|
48
55
|
const propName = propPart.trim().toLowerCase();
|
|
56
|
+
if (isStructural(propName, valuePart)) continue;
|
|
49
57
|
|
|
50
58
|
if (!isCustomPropDecl) {
|
|
51
59
|
for (const m of valuePart.matchAll(HEX_RE)) {
|
|
52
60
|
violations.push({
|
|
53
|
-
line:
|
|
61
|
+
line: lineAt(m),
|
|
54
62
|
ruleId: 'hardcoded/hex-color',
|
|
55
63
|
message: `하드코딩된 hex 색상: ${m[0]}`,
|
|
56
64
|
suggest: 'var(--color-*) 토큰 사용',
|
|
@@ -58,7 +66,7 @@ function checkCss(ctx) {
|
|
|
58
66
|
}
|
|
59
67
|
for (const m of valuePart.matchAll(RGB_RE)) {
|
|
60
68
|
violations.push({
|
|
61
|
-
line:
|
|
69
|
+
line: lineAt(m),
|
|
62
70
|
ruleId: 'hardcoded/color-function',
|
|
63
71
|
message: `하드코딩된 색상 함수: ${m[1]}(...)`,
|
|
64
72
|
suggest: 'var(--color-*) 토큰 사용',
|
|
@@ -69,13 +77,14 @@ function checkCss(ctx) {
|
|
|
69
77
|
for (const m of valuePart.matchAll(SIZE_RE)) {
|
|
70
78
|
const num = parseFloat(m[1]);
|
|
71
79
|
const unit = m[2];
|
|
72
|
-
|
|
80
|
+
// 1px hairlines, font-relative em, and 999+ pill/offscreen values are idioms rather than design values.
|
|
81
|
+
if ((unit === 'px' && num === 1) || num === 0 || unit === 'em' || num >= 999) continue;
|
|
73
82
|
if (propName === 'border' || propName === 'border-width' || /^border-(top|right|bottom|left)(-width)?$/.test(propName)) {
|
|
74
83
|
if (num === 1 && unit === 'px') continue;
|
|
75
84
|
}
|
|
76
85
|
if (isCustomPropDecl) continue;
|
|
77
86
|
violations.push({
|
|
78
|
-
line:
|
|
87
|
+
line: lineAt(m),
|
|
79
88
|
ruleId: 'hardcoded/size',
|
|
80
89
|
message: `하드코딩된 크기: ${m[0]}`,
|
|
81
90
|
suggest: 'var(--space-*) / var(--size-*) / var(--radius-*) 토큰 사용',
|
|
@@ -86,7 +95,7 @@ function checkCss(ctx) {
|
|
|
86
95
|
if (isCustomPropDecl) continue;
|
|
87
96
|
if (propName === 'transition' || propName === 'animation' || propName.startsWith('transition-') || propName.startsWith('animation-')) {
|
|
88
97
|
violations.push({
|
|
89
|
-
line:
|
|
98
|
+
line: lineAt(m),
|
|
90
99
|
ruleId: 'hardcoded/time',
|
|
91
100
|
message: `하드코딩된 시간: ${m[0]}`,
|
|
92
101
|
suggest: 'var(--transition-*) / var(--duration-*) 토큰 사용',
|
|
@@ -96,9 +105,9 @@ function checkCss(ctx) {
|
|
|
96
105
|
|
|
97
106
|
if (propName === 'font-family' && !isCustomPropDecl) {
|
|
98
107
|
const value = valuePart.trim();
|
|
99
|
-
if (value && !/^var\(/.test(value)) {
|
|
108
|
+
if (value && !/^var\(/.test(value) && !CSS_WIDE.test(value)) {
|
|
100
109
|
violations.push({
|
|
101
|
-
line:
|
|
110
|
+
line: lineOf(src, valueOffset + valuePart.search(/\S/)),
|
|
102
111
|
ruleId: 'hardcoded/font-family',
|
|
103
112
|
message: `하드코딩된 폰트명: ${value}`,
|
|
104
113
|
suggest: 'var(--font-*) 토큰 사용',
|
|
@@ -111,6 +120,16 @@ function checkCss(ctx) {
|
|
|
111
120
|
return violations;
|
|
112
121
|
}
|
|
113
122
|
|
|
123
|
+
function styleObjects(src) {
|
|
124
|
+
const spans = [];
|
|
125
|
+
for (const m of src.matchAll(/style=\{\{/g)) {
|
|
126
|
+
let depth = 2, i = m.index + m[0].length;
|
|
127
|
+
for (; i < src.length && depth; i++) { if (src[i] === '{') depth++; else if (src[i] === '}') depth--; }
|
|
128
|
+
spans.push({ text: src.slice(m.index, i), offset: m.index });
|
|
129
|
+
}
|
|
130
|
+
return spans;
|
|
131
|
+
}
|
|
132
|
+
|
|
114
133
|
function checkJs(ctx) {
|
|
115
134
|
const { content, ext } = ctx;
|
|
116
135
|
const src = stripComments(content, ext);
|
|
@@ -126,6 +145,18 @@ function checkJs(ctx) {
|
|
|
126
145
|
});
|
|
127
146
|
}
|
|
128
147
|
|
|
148
|
+
// React reads a bare number on these style keys as px: `style={{ padding: 13 }}`. Only inside JSX style
|
|
149
|
+
// objects; the same keys elsewhere are geometry data (`{ left: 2, top: 3 }`), not styling.
|
|
150
|
+
for (const span of styleObjects(src)) for (const m of span.text.matchAll(INLINE_SIZE_RE)) {
|
|
151
|
+
if (Number(m[2]) <= 1) continue;
|
|
152
|
+
violations.push({
|
|
153
|
+
line: lineOf(src, span.offset + m.index),
|
|
154
|
+
ruleId: 'hardcoded/size',
|
|
155
|
+
message: `하드코딩된 크기: ${m[1]}: ${m[2]}`,
|
|
156
|
+
suggest: "style={{ padding: 'var(--space-*)' }} 또는 CSS Module 토큰",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
129
160
|
for (const m of src.matchAll(FONT_FAMILY_JSX_RE)) {
|
|
130
161
|
const line = lineOf(src, m.index);
|
|
131
162
|
violations.push({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { stripComments, lineOf, findBlocks } from '../lib/source-utils.mjs';
|
|
2
2
|
|
|
3
|
+
// Uppercase is a selectable aesthetic default (RULES §0 row 7), so it is surfaced for review, never an error.
|
|
3
4
|
function checkUppercase(src, ext) {
|
|
4
5
|
const violations = [];
|
|
5
6
|
if (ext !== '.css') return violations;
|
|
@@ -10,16 +11,18 @@ function checkUppercase(src, ext) {
|
|
|
10
11
|
violations.push({
|
|
11
12
|
line: lineOf(src, b.start + 1 + m.index),
|
|
12
13
|
ruleId: 'memory/uppercase',
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
severity: 'review',
|
|
15
|
+
message: 'uppercase + letter-spacing 조합: 기본값은 사용하지 않음',
|
|
16
|
+
suggest: '프로젝트가 의도한 선택인지 확인하고, 아니면 text-transform과 letter-spacing을 제거',
|
|
15
17
|
});
|
|
16
18
|
} else if (/text-transform\s*:\s*uppercase/i.test(b.body)) {
|
|
17
19
|
const m = b.body.match(/text-transform\s*:\s*uppercase/i);
|
|
18
20
|
violations.push({
|
|
19
21
|
line: lineOf(src, b.start + 1 + m.index),
|
|
20
22
|
ruleId: 'memory/uppercase',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
severity: 'review',
|
|
24
|
+
message: 'uppercase: 기본값은 사용하지 않음',
|
|
25
|
+
suggest: '프로젝트가 의도한 선택인지 확인하고, 아니면 text-transform: uppercase 제거',
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
}
|
|
@@ -11,6 +11,9 @@ test('uppercase + letter-spacing flagged', () => {
|
|
|
11
11
|
assert.ok(v.some((x) => x.ruleId === 'memory/uppercase'));
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
test('uppercase is a review item, not an error (selectable default)', () => {
|
|
15
|
+
assert.ok(run('.a { text-transform: uppercase; }').every((x) => x.ruleId !== 'memory/uppercase' || x.severity === 'review'));
|
|
16
|
+
});
|
|
14
17
|
test('uppercase alone flagged', () => {
|
|
15
18
|
const v = run('.a { text-transform: uppercase; }');
|
|
16
19
|
assert.ok(v.some((x) => x.ruleId === 'memory/uppercase'));
|