openuispec 0.2.18 → 0.2.20
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 +2 -10
- package/dist/check/audit.js +392 -0
- package/dist/check/index.js +216 -0
- package/dist/cli/configure-target.js +391 -0
- package/dist/cli/index.js +510 -0
- package/dist/cli/init.js +1047 -0
- package/dist/drift/index.js +903 -0
- package/dist/mcp-server/index.js +886 -0
- package/dist/mcp-server/preview-render.js +1761 -0
- package/dist/mcp-server/preview.js +233 -0
- package/dist/mcp-server/screenshot-android.js +458 -0
- package/dist/mcp-server/screenshot-ios.js +639 -0
- package/dist/mcp-server/screenshot-shared.js +180 -0
- package/dist/mcp-server/screenshot.js +459 -0
- package/dist/prepare/index.js +1216 -0
- package/dist/runtime/package-paths.js +33 -0
- package/dist/schema/semantic-lint.js +564 -0
- package/dist/schema/validate.js +689 -0
- package/dist/status/index.js +194 -0
- package/docs/images/how-it-works.svg +56 -0
- package/docs/images/workflows.svg +76 -0
- package/package.json +12 -13
- package/check/audit.ts +0 -426
- package/check/index.ts +0 -320
- package/cli/configure-target.ts +0 -523
- package/cli/index.ts +0 -537
- package/cli/init.ts +0 -1253
- package/docs/images/how-it-works-dark.png +0 -0
- package/docs/images/how-it-works-light.png +0 -0
- package/docs/images/workflows-dark.png +0 -0
- package/docs/images/workflows-light.png +0 -0
- package/drift/index.ts +0 -1165
- package/mcp-server/index.ts +0 -1041
- package/mcp-server/preview-render.ts +0 -1922
- package/mcp-server/preview.ts +0 -292
- package/mcp-server/screenshot-android.ts +0 -621
- package/mcp-server/screenshot-ios.ts +0 -753
- package/mcp-server/screenshot-shared.ts +0 -237
- package/mcp-server/screenshot.ts +0 -563
- package/prepare/index.ts +0 -1530
- package/schema/semantic-lint.ts +0 -692
- package/schema/validate.ts +0 -870
- package/scripts/regenerate-previews.ts +0 -136
- package/scripts/take-all-screenshots.ts +0 -507
- package/status/index.ts +0 -275
package/check/audit.ts
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Design quality audit for OpenUISpec projects.
|
|
3
|
-
*
|
|
4
|
-
* Checks token patterns and contract completeness to produce a numeric quality score.
|
|
5
|
-
* Score formula: max(0, 100 - errors × 10 - warnings × 3)
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* openuispec check --target web --audit
|
|
9
|
-
* openuispec check --target ios --audit --min-score 70
|
|
10
|
-
* openuispec check --target web --audit --format json
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
14
|
-
import { join, resolve } from "node:path";
|
|
15
|
-
import YAML from "yaml";
|
|
16
|
-
|
|
17
|
-
export interface AuditFinding {
|
|
18
|
-
domain: string;
|
|
19
|
-
rule: string;
|
|
20
|
-
severity: "error" | "warning";
|
|
21
|
-
message: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface AuditResult {
|
|
25
|
-
score: number;
|
|
26
|
-
errors: number;
|
|
27
|
-
warnings: number;
|
|
28
|
-
findings: AuditFinding[];
|
|
29
|
-
passed: boolean;
|
|
30
|
-
threshold: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const AI_DEFAULT_FONTS = new Set(["Inter", "Roboto", "Arial", "Open Sans"]);
|
|
34
|
-
const REQUIRED_TOKEN_FILES = [
|
|
35
|
-
"color.yaml",
|
|
36
|
-
"typography.yaml",
|
|
37
|
-
"spacing.yaml",
|
|
38
|
-
"elevation.yaml",
|
|
39
|
-
"motion.yaml",
|
|
40
|
-
"layout.yaml",
|
|
41
|
-
"themes.yaml",
|
|
42
|
-
"icons.yaml",
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
function readYaml(path: string): any {
|
|
46
|
-
try {
|
|
47
|
-
return YAML.parse(readFileSync(path, "utf-8"));
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function readYamlForAudit(path: string, domain: string, findings: AuditFinding[]): any {
|
|
54
|
-
try {
|
|
55
|
-
return YAML.parse(readFileSync(path, "utf-8"));
|
|
56
|
-
} catch (err: any) {
|
|
57
|
-
if (err?.code === "ENOENT") return null;
|
|
58
|
-
findings.push({
|
|
59
|
-
domain,
|
|
60
|
-
rule: "unreadable_file",
|
|
61
|
-
severity: "error",
|
|
62
|
-
message: `Could not parse "${path}". Fix malformed YAML before relying on this audit.`,
|
|
63
|
-
});
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function checkRequiredTokenFiles(tokensDir: string, findings: AuditFinding[]): void {
|
|
69
|
-
for (const filename of REQUIRED_TOKEN_FILES) {
|
|
70
|
-
if (!existsSync(join(tokensDir, filename))) {
|
|
71
|
-
findings.push({
|
|
72
|
-
domain: "tokens",
|
|
73
|
-
rule: "missing_file",
|
|
74
|
-
severity: "error",
|
|
75
|
-
message: `Required token file "${filename}" is missing.`,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function checkTypography(tokensDir: string, findings: AuditFinding[]): void {
|
|
82
|
-
const doc = readYamlForAudit(join(tokensDir, "typography.yaml"), "typography", findings);
|
|
83
|
-
if (!doc?.typography) return;
|
|
84
|
-
|
|
85
|
-
// Font diversity: primary must NOT be a common AI default
|
|
86
|
-
const primaryFont = doc.typography.font_family?.primary?.value;
|
|
87
|
-
if (typeof primaryFont === "string" && AI_DEFAULT_FONTS.has(primaryFont)) {
|
|
88
|
-
findings.push({
|
|
89
|
-
domain: "typography",
|
|
90
|
-
rule: "font_diversity",
|
|
91
|
-
severity: "error",
|
|
92
|
-
message: `Primary font "${primaryFont}" is an AI-default choice. Use a distinctive brand font.`,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Scale usage: at least 4 distinct scale levels defined
|
|
97
|
-
const scaleKeys = Object.keys(doc.typography.scale ?? {});
|
|
98
|
-
if (scaleKeys.length > 0 && scaleKeys.length < 4) {
|
|
99
|
-
findings.push({
|
|
100
|
-
domain: "typography",
|
|
101
|
-
rule: "scale_usage",
|
|
102
|
-
severity: "warning",
|
|
103
|
-
message: `Only ${scaleKeys.length} type scale level(s) defined. Use ≥4 distinct levels for clear hierarchy.`,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Weight hierarchy: at least 2 distinct weights
|
|
108
|
-
if (doc.typography.scale) {
|
|
109
|
-
const weights = new Set<number>();
|
|
110
|
-
for (const level of Object.values(doc.typography.scale)) {
|
|
111
|
-
if (typeof (level as any)?.weight === "number") {
|
|
112
|
-
weights.add((level as any).weight);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (weights.size > 0 && weights.size < 2) {
|
|
116
|
-
findings.push({
|
|
117
|
-
domain: "typography",
|
|
118
|
-
rule: "weight_hierarchy",
|
|
119
|
-
severity: "warning",
|
|
120
|
-
message: "Only 1 distinct font weight used across the type scale. Use ≥2 weights (e.g. 400 + 700) for clear hierarchy.",
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function checkColor(tokensDir: string, findings: AuditFinding[]): void {
|
|
127
|
-
const doc = readYamlForAudit(join(tokensDir, "color.yaml"), "color", findings);
|
|
128
|
-
if (!doc?.color) return;
|
|
129
|
-
|
|
130
|
-
// Pure black/white check
|
|
131
|
-
function scanForPure(obj: any, path: string): void {
|
|
132
|
-
if (typeof obj !== "object" || obj === null) return;
|
|
133
|
-
if (typeof obj.reference === "string") {
|
|
134
|
-
const ref = obj.reference.toUpperCase();
|
|
135
|
-
if (ref === "#000000" || ref === "#000") {
|
|
136
|
-
findings.push({
|
|
137
|
-
domain: "color",
|
|
138
|
-
rule: "pure_black",
|
|
139
|
-
severity: "error",
|
|
140
|
-
message: `Token at ${path} uses pure black (#000000). Use a near-black with hue instead.`,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
if (ref === "#FFFFFF" || ref === "#FFF") {
|
|
144
|
-
findings.push({
|
|
145
|
-
domain: "color",
|
|
146
|
-
rule: "pure_white",
|
|
147
|
-
severity: "error",
|
|
148
|
-
message: `Token at ${path} uses pure white (#FFFFFF). Use a slightly tinted white instead.`,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
153
|
-
if (key !== "reference" && typeof value === "object") {
|
|
154
|
-
scanForPure(value, `${path}.${key}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
scanForPure(doc.color, "color");
|
|
159
|
-
|
|
160
|
-
// Semantic color completeness: success, warning, danger, info
|
|
161
|
-
if (doc.color.semantic) {
|
|
162
|
-
const required = ["success", "warning", "danger", "info"];
|
|
163
|
-
const defined = Object.keys(doc.color.semantic);
|
|
164
|
-
for (const name of required) {
|
|
165
|
-
if (!defined.includes(name)) {
|
|
166
|
-
findings.push({
|
|
167
|
-
domain: "color",
|
|
168
|
-
rule: "semantic_completeness",
|
|
169
|
-
severity: "warning",
|
|
170
|
-
message: `Semantic color "${name}" is missing. Define all four (success, warning, danger, info) for complete state coverage.`,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Theme coverage: check themes.yaml for both light + dark
|
|
177
|
-
{
|
|
178
|
-
const themes = readYamlForAudit(join(tokensDir, "themes.yaml"), "color", findings);
|
|
179
|
-
if (!themes?.themes) return;
|
|
180
|
-
const themeKeys = Object.keys(themes.themes);
|
|
181
|
-
const hasLight = themeKeys.some((k) => k.includes("light"));
|
|
182
|
-
const hasDark = themeKeys.some((k) => k.includes("dark"));
|
|
183
|
-
if (!hasLight || !hasDark) {
|
|
184
|
-
findings.push({
|
|
185
|
-
domain: "color",
|
|
186
|
-
rule: "theme_coverage",
|
|
187
|
-
severity: "warning",
|
|
188
|
-
message: "Both light and dark themes should be defined in tokens/themes.yaml.",
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function checkSpacing(tokensDir: string, findings: AuditFinding[]): void {
|
|
195
|
-
const doc = readYamlForAudit(join(tokensDir, "spacing.yaml"), "spacing", findings);
|
|
196
|
-
if (!doc?.spacing) return;
|
|
197
|
-
|
|
198
|
-
// Scale usage: at least 4 distinct values
|
|
199
|
-
const scale = doc.spacing.scale ?? {};
|
|
200
|
-
const scaleCount = Object.keys(scale).length;
|
|
201
|
-
if (scaleCount > 0 && scaleCount < 4) {
|
|
202
|
-
findings.push({
|
|
203
|
-
domain: "spacing",
|
|
204
|
-
rule: "scale_usage",
|
|
205
|
-
severity: "warning",
|
|
206
|
-
message: `Only ${scaleCount} spacing scale value(s) defined. Define ≥4 for meaningful spatial rhythm.`,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Alias usage: page_margin and card_padding should exist
|
|
211
|
-
const aliases = doc.spacing.aliases ?? {};
|
|
212
|
-
const aliasKeys = Object.keys(aliases).map((k) => k.toLowerCase());
|
|
213
|
-
if (!aliasKeys.some((k) => k.includes("page_margin") || k.includes("page"))) {
|
|
214
|
-
findings.push({
|
|
215
|
-
domain: "spacing",
|
|
216
|
-
rule: "alias_page_margin",
|
|
217
|
-
severity: "warning",
|
|
218
|
-
message: "No page_margin alias found in spacing tokens. Define it for consistent screen padding.",
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
if (!aliasKeys.some((k) => k.includes("card_padding") || k.includes("card"))) {
|
|
222
|
-
findings.push({
|
|
223
|
-
domain: "spacing",
|
|
224
|
-
rule: "alias_card_padding",
|
|
225
|
-
severity: "warning",
|
|
226
|
-
message: "No card_padding alias found in spacing tokens. Define it for consistent card spacing.",
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function checkMotion(tokensDir: string, findings: AuditFinding[]): void {
|
|
232
|
-
const doc = readYamlForAudit(join(tokensDir, "motion.yaml"), "motion", findings);
|
|
233
|
-
if (!doc?.motion) return;
|
|
234
|
-
|
|
235
|
-
// Duration variety: at least 2 distinct durations
|
|
236
|
-
const durations = doc.motion.duration ?? {};
|
|
237
|
-
const distinctDurations = new Set(Object.values(durations));
|
|
238
|
-
if (Object.keys(durations).length > 0 && distinctDurations.size < 2) {
|
|
239
|
-
findings.push({
|
|
240
|
-
domain: "motion",
|
|
241
|
-
rule: "duration_variety",
|
|
242
|
-
severity: "warning",
|
|
243
|
-
message: "Only 1 distinct duration value found. Use ≥2 distinct durations (e.g. quick + normal).",
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Reduced motion: must be defined
|
|
248
|
-
if (!doc.motion.reduced_motion) {
|
|
249
|
-
findings.push({
|
|
250
|
-
domain: "motion",
|
|
251
|
-
rule: "reduced_motion",
|
|
252
|
-
severity: "error",
|
|
253
|
-
message: "motion.reduced_motion is not defined. Must specify policy for prefers-reduced-motion.",
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Easing quality: enter + exit curves, at least one cubic-bezier
|
|
258
|
-
if (doc.motion.easing) {
|
|
259
|
-
const easings = doc.motion.easing;
|
|
260
|
-
const keys = Object.keys(easings);
|
|
261
|
-
if (!keys.includes("enter") || !keys.includes("exit")) {
|
|
262
|
-
findings.push({
|
|
263
|
-
domain: "motion",
|
|
264
|
-
rule: "easing_quality",
|
|
265
|
-
severity: "warning",
|
|
266
|
-
message: "Motion easing should define at least 'enter' and 'exit' curves for asymmetric transitions.",
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
const hasCubicBezier = Object.values(easings).some(
|
|
270
|
-
(v) => typeof v === "string" && v.includes("cubic-bezier"),
|
|
271
|
-
);
|
|
272
|
-
if (!hasCubicBezier) {
|
|
273
|
-
findings.push({
|
|
274
|
-
domain: "motion",
|
|
275
|
-
rule: "easing_quality",
|
|
276
|
-
severity: "warning",
|
|
277
|
-
message: "All easing curves are generic keywords. Use at least one cubic-bezier() for nuanced motion.",
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function checkElevationProgression(tokensDir: string, findings: AuditFinding[]): void {
|
|
284
|
-
const doc = readYamlForAudit(join(tokensDir, "elevation.yaml"), "elevation", findings);
|
|
285
|
-
if (!doc?.elevation) return;
|
|
286
|
-
const levels = Object.keys(doc.elevation).filter((k) => k !== "none");
|
|
287
|
-
if (levels.length < 2) {
|
|
288
|
-
findings.push({
|
|
289
|
-
domain: "elevation",
|
|
290
|
-
rule: "level_count",
|
|
291
|
-
severity: "warning",
|
|
292
|
-
message: `Only ${levels.length} non-none elevation level(s) defined. Define ≥2 (e.g. sm, md, lg) for meaningful depth hierarchy.`,
|
|
293
|
-
});
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const androidValues: number[] = [];
|
|
297
|
-
for (const level of levels) {
|
|
298
|
-
const val = doc.elevation[level]?.platform?.android?.elevation;
|
|
299
|
-
if (typeof val === "number") androidValues.push(val);
|
|
300
|
-
}
|
|
301
|
-
if (androidValues.length >= 2) {
|
|
302
|
-
for (let i = 1; i < androidValues.length; i++) {
|
|
303
|
-
if (androidValues[i] <= androidValues[i - 1]) {
|
|
304
|
-
findings.push({
|
|
305
|
-
domain: "elevation",
|
|
306
|
-
rule: "progression",
|
|
307
|
-
severity: "warning",
|
|
308
|
-
message: "Elevation levels do not increase monotonically. Each level should cast a deeper shadow than the previous.",
|
|
309
|
-
});
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function checkLayoutSizeClasses(tokensDir: string, findings: AuditFinding[]): void {
|
|
317
|
-
const doc = readYamlForAudit(join(tokensDir, "layout.yaml"), "layout", findings);
|
|
318
|
-
if (!doc?.layout?.size_classes) return;
|
|
319
|
-
const classes = Object.keys(doc.layout.size_classes);
|
|
320
|
-
if (classes.length < 2) {
|
|
321
|
-
findings.push({
|
|
322
|
-
domain: "layout",
|
|
323
|
-
rule: "size_class_coverage",
|
|
324
|
-
severity: "warning",
|
|
325
|
-
message: `Only ${classes.length} size class(es) defined. Define at least compact + regular for responsive layouts.`,
|
|
326
|
-
});
|
|
327
|
-
} else if (!classes.includes("compact")) {
|
|
328
|
-
findings.push({
|
|
329
|
-
domain: "layout",
|
|
330
|
-
rule: "size_class_coverage",
|
|
331
|
-
severity: "warning",
|
|
332
|
-
message: "No 'compact' size class defined. Mobile-first layouts require a compact breakpoint.",
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function checkContractStateCoverage(contractsDir: string, findings: AuditFinding[]): void {
|
|
338
|
-
if (!existsSync(contractsDir)) return;
|
|
339
|
-
for (const file of readdirSync(contractsDir).filter((f) => f.endsWith(".yaml") && !f.startsWith("x_"))) {
|
|
340
|
-
const doc = readYamlForAudit(join(contractsDir, file), "contracts", findings);
|
|
341
|
-
if (!doc) continue;
|
|
342
|
-
const contractName = Object.keys(doc)[0];
|
|
343
|
-
const contract = doc[contractName];
|
|
344
|
-
const mustHandle: string[] = contract?.generation?.must_handle ?? [];
|
|
345
|
-
if (mustHandle.length === 0) {
|
|
346
|
-
findings.push({
|
|
347
|
-
domain: "contracts",
|
|
348
|
-
rule: "state_coverage",
|
|
349
|
-
severity: "warning",
|
|
350
|
-
message: `Contract "${contractName}" has no generation.must_handle entries. Define required states for AI compliance.`,
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function checkContracts(contractsDir: string, findings: AuditFinding[]): void {
|
|
357
|
-
// All collections have empty_state in must_handle or variants
|
|
358
|
-
{
|
|
359
|
-
const doc = readYamlForAudit(join(contractsDir, "collection.yaml"), "contracts", findings);
|
|
360
|
-
const collection = doc ? doc[Object.keys(doc)[0]] : null;
|
|
361
|
-
if (collection) {
|
|
362
|
-
const mustHandle: string[] = collection.generation?.must_handle ?? [];
|
|
363
|
-
const hasEmptyState = mustHandle.some((s: string) => s.toLowerCase().includes("empty"));
|
|
364
|
-
if (!hasEmptyState) {
|
|
365
|
-
findings.push({
|
|
366
|
-
domain: "contracts",
|
|
367
|
-
rule: "collection_empty_state",
|
|
368
|
-
severity: "warning",
|
|
369
|
-
message: "collection contract does not list empty_state handling in generation.must_handle.",
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
export function buildAuditResult(projectDir: string, threshold: number = 0): AuditResult {
|
|
377
|
-
const manifest = readYaml(join(projectDir, "openuispec.yaml"));
|
|
378
|
-
const tokensDir = resolve(projectDir, manifest?.includes?.tokens ?? "./tokens/");
|
|
379
|
-
const contractsDir = resolve(projectDir, manifest?.includes?.contracts ?? "./contracts/");
|
|
380
|
-
|
|
381
|
-
// Use audit_threshold from manifest if no CLI override
|
|
382
|
-
const effectiveThreshold = threshold > 0 ? threshold : (manifest?.generation_guidance?.audit_threshold ?? 0);
|
|
383
|
-
|
|
384
|
-
const findings: AuditFinding[] = [];
|
|
385
|
-
checkRequiredTokenFiles(tokensDir, findings);
|
|
386
|
-
checkTypography(tokensDir, findings);
|
|
387
|
-
checkColor(tokensDir, findings);
|
|
388
|
-
checkSpacing(tokensDir, findings);
|
|
389
|
-
checkMotion(tokensDir, findings);
|
|
390
|
-
checkElevationProgression(tokensDir, findings);
|
|
391
|
-
checkLayoutSizeClasses(tokensDir, findings);
|
|
392
|
-
checkContracts(contractsDir, findings);
|
|
393
|
-
checkContractStateCoverage(contractsDir, findings);
|
|
394
|
-
|
|
395
|
-
const errors = findings.filter((f) => f.severity === "error").length;
|
|
396
|
-
const warnings = findings.filter((f) => f.severity === "warning").length;
|
|
397
|
-
const score = Math.max(0, 100 - errors * 10 - warnings * 3);
|
|
398
|
-
|
|
399
|
-
return {
|
|
400
|
-
score,
|
|
401
|
-
errors,
|
|
402
|
-
warnings,
|
|
403
|
-
findings,
|
|
404
|
-
passed: score >= effectiveThreshold,
|
|
405
|
-
threshold: effectiveThreshold,
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export function formatAuditResult(result: AuditResult): string {
|
|
410
|
-
const lines: string[] = [
|
|
411
|
-
`Design Quality Score: ${result.score}/100`,
|
|
412
|
-
`Errors: ${result.errors} Warnings: ${result.warnings}`,
|
|
413
|
-
result.threshold > 0 ? `Threshold: ${result.threshold} — ${result.passed ? "PASS" : "FAIL"}` : "",
|
|
414
|
-
"",
|
|
415
|
-
].filter((l) => l !== "" || lines?.length === 0);
|
|
416
|
-
|
|
417
|
-
if (result.findings.length === 0) {
|
|
418
|
-
lines.push("No issues found.");
|
|
419
|
-
} else {
|
|
420
|
-
for (const f of result.findings) {
|
|
421
|
-
lines.push(`[${f.severity.toUpperCase()}] [${f.domain}] ${f.message}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return lines.join("\n");
|
|
426
|
-
}
|