@raintree-technology/hig-doctor-core 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -18
- package/dist/audit.d.ts +1 -1
- package/dist/cache.d.ts +3 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +27 -494
- package/package.json +7 -8
- package/src/analyze.ts +1 -1
- package/src/audit-generator.ts +5 -130
- package/src/audit.ts +7 -13
- package/src/baseline.ts +0 -0
- package/src/benchmark.ts +1 -1
- package/src/cache.ts +12 -11
- package/src/categorizer.ts +2 -28
- package/src/config.ts +3 -3
- package/src/index.ts +1 -10
- package/src/patterns.ts +8 -9
- package/src/scanner.ts +3 -5
- package/CHANGELOG.md +0 -58
- package/src/audit-generator.test.ts +0 -166
- package/src/audit.test.ts +0 -121
- package/src/baseline.test.ts +0 -83
- package/src/benchmark.test.ts +0 -29
- package/src/cache.test.ts +0 -90
- package/src/categorizer.test.ts +0 -51
- package/src/config.test.ts +0 -156
- package/src/engines/ast-tsx.test.ts +0 -121
- package/src/engines/swift-structural.test.ts +0 -39
- package/src/fixes.test.ts +0 -152
- package/src/patterns.test.ts +0 -872
- package/src/sarif.test.ts +0 -39
- package/src/scanner.test.ts +0 -196
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raintree-technology/hig-doctor-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "HIG Doctor rule engine: framework detection, Apple HIG and accessibility rules, and the audit pipeline.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
18
|
"src",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"!src/**/*.test.ts",
|
|
20
|
+
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": "
|
|
23
|
+
"node": ">=22"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"typescript": "^5.9.3"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "esbuild src/index.ts --bundle --platform=node --target=
|
|
46
|
+
"build": "esbuild src/index.ts --bundle --platform=node --target=node22 --format=esm --external:typescript --outfile=dist/index.js && tsc -p tsconfig.build.json",
|
|
47
47
|
"test": "bun test",
|
|
48
48
|
"typecheck": "tsc --noEmit",
|
|
49
49
|
"prepublishOnly": "bun run build"
|
|
@@ -53,6 +53,5 @@
|
|
|
53
53
|
"@types/node": "^20",
|
|
54
54
|
"esbuild": "^0.25.0",
|
|
55
55
|
"typescript": "^5.9.3"
|
|
56
|
-
}
|
|
57
|
-
"packageManager": "bun@1.3.11"
|
|
56
|
+
}
|
|
58
57
|
}
|
package/src/analyze.ts
CHANGED
package/src/audit-generator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// audit
|
|
1
|
+
// Renders the Markdown audit report.
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ScanResult } from "./scanner";
|
|
@@ -96,7 +96,7 @@ export async function loadSkillContent(skillsDir: string, skillName: string): Pr
|
|
|
96
96
|
const skillPath = join(skillsDir, skillName, "SKILL.md");
|
|
97
97
|
const content = await readFile(skillPath, "utf-8");
|
|
98
98
|
const stripped = content.replace(/^---\s*\r?\n[\s\S]*?\r?\n---\s*(?:\r?\n|$)/, "");
|
|
99
|
-
const principlesMatch = stripped.match(/## Key Principles\n([\s\S]*?)(?=\n## |$)/);
|
|
99
|
+
const principlesMatch = stripped.match(/## Key Principles\r?\n([\s\S]*?)(?=\r?\n## |$)/);
|
|
100
100
|
return principlesMatch ? principlesMatch[1].trim() : stripped.slice(0, 2000);
|
|
101
101
|
} catch {
|
|
102
102
|
return null;
|
|
@@ -133,32 +133,16 @@ export function generateAuditMarkdown(
|
|
|
133
133
|
lines.push(`**Quick stats**: ${totalConcerns} potential concerns, ${totalPositives} positive patterns, ${totalPatterns} component usages detected across ${categories.length} HIG categories`);
|
|
134
134
|
lines.push("");
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
lines.push("## Instructions for AI Evaluator");
|
|
136
|
+
lines.push("## How to use this report");
|
|
138
137
|
lines.push("");
|
|
139
|
-
lines.push("
|
|
140
|
-
lines.push("The HIG principles (accessibility, color systems, typography, responsive layout, motion) apply to all surfaces — native, web, and cross-platform.");
|
|
141
|
-
lines.push("For each category below, evaluate the code excerpts against the HIG reference material.");
|
|
142
|
-
lines.push("");
|
|
143
|
-
lines.push("**Scoring**: Rate each category 1-10:");
|
|
144
|
-
lines.push("- **9-10**: Excellent HIG compliance, follows best practices");
|
|
145
|
-
lines.push("- **7-8**: Good compliance with minor improvements possible");
|
|
146
|
-
lines.push("- **5-6**: Partial compliance, several areas need attention");
|
|
147
|
-
lines.push("- **3-4**: Significant HIG violations");
|
|
148
|
-
lines.push("- **1-2**: Major violations or missing fundamental practices");
|
|
149
|
-
lines.push("");
|
|
150
|
-
lines.push("**Output**: For each category, provide:");
|
|
151
|
-
lines.push("1. Score (1-10)");
|
|
152
|
-
lines.push("2. What's done well (cite specific code)");
|
|
153
|
-
lines.push("3. What needs improvement (cite specific file:line)");
|
|
154
|
-
lines.push("4. Specific fix recommendations");
|
|
138
|
+
lines.push("Concerns are probable problems found by static rules; positives and patterns only record what the code uses. Check each concern against the HIG reference under its category, then fix it or document why it does not apply. Automated findings do not establish HIG or accessibility conformance.");
|
|
155
139
|
lines.push("");
|
|
156
140
|
|
|
157
141
|
// Categories
|
|
158
142
|
for (const category of categories) {
|
|
159
143
|
lines.push(`## Category: ${category.label}`);
|
|
160
144
|
lines.push("");
|
|
161
|
-
lines.push(`*${category.matches.length} detections across ${category.fileCount} file(s)
|
|
145
|
+
lines.push(`*${category.matches.length} detections across ${category.fileCount} file(s): ${category.concerns} concern(s), ${category.positives} positive(s)*`);
|
|
162
146
|
lines.push("");
|
|
163
147
|
|
|
164
148
|
lines.push("### Code Excerpts");
|
|
@@ -179,116 +163,7 @@ export function generateAuditMarkdown(
|
|
|
179
163
|
lines.push(`*Load reference from skill: ${category.skillName}*`);
|
|
180
164
|
}
|
|
181
165
|
lines.push("");
|
|
182
|
-
|
|
183
|
-
lines.push("### Evaluate");
|
|
184
|
-
lines.push("");
|
|
185
|
-
const checks = getEvaluationChecklist(category.skillName);
|
|
186
|
-
for (const check of checks) {
|
|
187
|
-
lines.push(`- ${check}`);
|
|
188
|
-
}
|
|
189
|
-
lines.push("");
|
|
190
166
|
}
|
|
191
167
|
|
|
192
|
-
// Scoring table
|
|
193
|
-
lines.push("## Scoring Summary");
|
|
194
|
-
lines.push("");
|
|
195
|
-
lines.push("| Category | Score (1-10) | Key Findings |");
|
|
196
|
-
lines.push("|----------|-------------|-------------|");
|
|
197
|
-
for (const category of categories) {
|
|
198
|
-
lines.push(`| ${category.label} | | |`);
|
|
199
|
-
}
|
|
200
|
-
lines.push("| **Overall** | **/10** | |");
|
|
201
|
-
lines.push("");
|
|
202
|
-
|
|
203
168
|
return lines.join("\n");
|
|
204
169
|
}
|
|
205
|
-
|
|
206
|
-
function getEvaluationChecklist(skillName: string): string[] {
|
|
207
|
-
const checklists: Record<string, string[]> = {
|
|
208
|
-
"hig-foundations": [
|
|
209
|
-
"Color usage: system semantic colors vs hardcoded values",
|
|
210
|
-
"Typography: Dynamic Type text styles vs fixed font sizes",
|
|
211
|
-
"Accessibility: labels, hints, traits on interactive elements",
|
|
212
|
-
"Dark mode: proper color adaptation, no hardcoded light/dark values",
|
|
213
|
-
"Motion: Reduce Motion support for animations",
|
|
214
|
-
],
|
|
215
|
-
"hig-components-layout": [
|
|
216
|
-
"Navigation pattern matches app structure (tabs for flat, sidebar for deep)",
|
|
217
|
-
"Adaptive layout: responds to size classes, multitasking",
|
|
218
|
-
"Standard navigation components (NavigationSplitView, not deprecated NavigationView)",
|
|
219
|
-
"Consistent back navigation and spatial hierarchy",
|
|
220
|
-
],
|
|
221
|
-
"hig-components-controls": [
|
|
222
|
-
"Standard control usage (Button, Toggle, Picker, etc.)",
|
|
223
|
-
"Proper button styles and roles",
|
|
224
|
-
"Clear action labels and consistent interaction patterns",
|
|
225
|
-
],
|
|
226
|
-
"hig-components-selection": [
|
|
227
|
-
"Appropriate picker and selection controls",
|
|
228
|
-
"Clear selection state feedback",
|
|
229
|
-
],
|
|
230
|
-
"hig-components-actions": [
|
|
231
|
-
"Button hierarchy and prominence",
|
|
232
|
-
"Destructive actions clearly marked",
|
|
233
|
-
"Swipe actions follow HIG conventions",
|
|
234
|
-
],
|
|
235
|
-
"hig-components-presentation": [
|
|
236
|
-
"Sheets for focused tasks, popovers for contextual info",
|
|
237
|
-
"Alerts used sparingly for important decisions",
|
|
238
|
-
"Confirmation dialogs for destructive actions",
|
|
239
|
-
],
|
|
240
|
-
"hig-components-textinput": [
|
|
241
|
-
"Text fields use appropriate keyboard types",
|
|
242
|
-
"Search functionality uses .searchable where appropriate",
|
|
243
|
-
],
|
|
244
|
-
"hig-components-media": [
|
|
245
|
-
"Image handling with proper async loading",
|
|
246
|
-
"Media playback uses system controls",
|
|
247
|
-
],
|
|
248
|
-
"hig-components-menus": [
|
|
249
|
-
"Context menus provide relevant actions",
|
|
250
|
-
"Menu organization follows HIG grouping conventions",
|
|
251
|
-
],
|
|
252
|
-
"hig-components-dialogs": [
|
|
253
|
-
"Alerts used sparingly for important decisions",
|
|
254
|
-
"Sheets for focused tasks, popovers for contextual info",
|
|
255
|
-
"Confirmation dialogs for destructive actions",
|
|
256
|
-
],
|
|
257
|
-
"hig-components-search": [
|
|
258
|
-
"Searchable modifier used for filterable content",
|
|
259
|
-
"Search suggestions and scopes where appropriate",
|
|
260
|
-
],
|
|
261
|
-
"hig-components-status": [
|
|
262
|
-
"Progress indicators for long operations",
|
|
263
|
-
"Appropriate use of determinate vs indeterminate progress",
|
|
264
|
-
],
|
|
265
|
-
"hig-components-content": [
|
|
266
|
-
"Content display uses appropriate containers",
|
|
267
|
-
"Image handling with proper async loading",
|
|
268
|
-
],
|
|
269
|
-
"hig-components-system": [
|
|
270
|
-
"System integration uses standard APIs (ShareLink, PhotosPicker)",
|
|
271
|
-
"Deep link handling, widget support where relevant",
|
|
272
|
-
],
|
|
273
|
-
"hig-patterns": [
|
|
274
|
-
"Drag and drop support where appropriate",
|
|
275
|
-
"Pull-to-refresh for refreshable content",
|
|
276
|
-
"Swipe actions follow HIG conventions",
|
|
277
|
-
"Undo support for destructive actions",
|
|
278
|
-
],
|
|
279
|
-
"hig-inputs": [
|
|
280
|
-
"Text input uses appropriate field types",
|
|
281
|
-
"Keyboard shortcuts for power users (macOS/iPad)",
|
|
282
|
-
"Gesture usage follows platform conventions",
|
|
283
|
-
],
|
|
284
|
-
"hig-technologies": [
|
|
285
|
-
"Apple framework integration follows HIG for that technology",
|
|
286
|
-
"Proper permission handling and progressive disclosure",
|
|
287
|
-
],
|
|
288
|
-
"hig-platforms": [
|
|
289
|
-
"UI adapts appropriately across target platforms",
|
|
290
|
-
"Platform idioms respected (iPhone vs iPad vs Mac)",
|
|
291
|
-
],
|
|
292
|
-
};
|
|
293
|
-
return checklists[skillName] ?? ["Evaluate against Apple HIG best practices for this category"];
|
|
294
|
-
}
|
package/src/audit.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Full pipeline: scan, detect, apply config and baseline, categorize, render Markdown.
|
|
2
2
|
import { scanProject, type ScanResult } from "./scanner";
|
|
3
3
|
import { type PatternMatch } from "./patterns";
|
|
4
4
|
import { analyzeFile } from "./analyze";
|
|
@@ -43,7 +43,7 @@ export interface AuditResult {
|
|
|
43
43
|
baselinePath: string | null;
|
|
44
44
|
/** Concerns absorbed by the baseline (hidden from results and gating). */
|
|
45
45
|
baselined: number;
|
|
46
|
-
/** Baseline occurrences that no longer match anything
|
|
46
|
+
/** Baseline occurrences that no longer match anything (time to re-snapshot). */
|
|
47
47
|
baselineStale: number;
|
|
48
48
|
/** Cache hit/miss counts when the cache is enabled, else null. */
|
|
49
49
|
cacheStats: { hits: number; misses: number } | null;
|
|
@@ -68,17 +68,15 @@ export async function audit(directory: string, skillsDir?: string, options: Audi
|
|
|
68
68
|
const allFiles = [...scanResult.codeFiles, ...scanResult.styleFiles, ...scanResult.markupFiles];
|
|
69
69
|
const cachePath = join(resolvedDir, CACHE_FILENAME);
|
|
70
70
|
const cache = options.cache ? await ScanCache.load(cachePath) : null;
|
|
71
|
-
const touched = new Set<string>();
|
|
72
71
|
for (const file of allFiles) {
|
|
73
72
|
let matches = cache?.get(file.relativePath, file.content) ?? null;
|
|
74
73
|
if (matches === null) {
|
|
75
74
|
matches = analyzeFile(file.content, file.relativePath);
|
|
76
75
|
cache?.set(file.relativePath, file.content, matches);
|
|
77
76
|
}
|
|
78
|
-
if (cache) touched.add(cache.keyOf(file.relativePath, file.content));
|
|
79
77
|
detected.push(...matches);
|
|
80
78
|
}
|
|
81
|
-
if (cache) await cache.save(cachePath
|
|
79
|
+
if (cache) await cache.save(cachePath);
|
|
82
80
|
const configured = applyConfig(detected, loaded.config);
|
|
83
81
|
|
|
84
82
|
// 4. Apply baseline: previously-snapshotted concerns are absorbed so only
|
|
@@ -108,14 +106,10 @@ export async function audit(directory: string, skillsDir?: string, options: Audi
|
|
|
108
106
|
if (skillsDir) {
|
|
109
107
|
resolvedSkillsDir = resolve(skillsDir);
|
|
110
108
|
} else {
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
join(resolvedDir, "..", "..", "skills"),
|
|
116
|
-
// Relative to this package (for development: packages/core/src → repo root)
|
|
117
|
-
join(moduleDir, "..", "..", "..", "skills"),
|
|
118
|
-
];
|
|
109
|
+
// The audited project's own skills/, then this repo's (running from source).
|
|
110
|
+
// Parent directories are not searched: an unrelated ../skills folder would
|
|
111
|
+
// otherwise leak into the report.
|
|
112
|
+
const candidates = [join(resolvedDir, "skills"), join(moduleDir, "..", "..", "..", "skills")];
|
|
119
113
|
for (const candidate of candidates) {
|
|
120
114
|
try {
|
|
121
115
|
await access(candidate);
|
package/src/baseline.ts
CHANGED
|
Binary file
|
package/src/benchmark.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// should produce. "bad" fixtures assert true positives (a missing one is a
|
|
5
5
|
// false negative); "good" fixtures assert the absence of concerns (any concern
|
|
6
6
|
// is a false positive). The harness scores per-rule and overall so regressions
|
|
7
|
-
// in either direction are visible.
|
|
7
|
+
// in either direction are visible.
|
|
8
8
|
import { analyzeFile } from "./analyze";
|
|
9
9
|
|
|
10
10
|
export interface BenchmarkCase {
|
package/src/cache.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Content-hash cache for local scans.
|
|
2
2
|
//
|
|
3
3
|
// Analysis is a pure function of (path, content, ruleset), so re-scanning a
|
|
4
4
|
// project only needs to re-analyze files whose content changed. The cache keys
|
|
@@ -33,6 +33,7 @@ function keyFor(path: string, content: string): string {
|
|
|
33
33
|
|
|
34
34
|
export class ScanCache {
|
|
35
35
|
private entries: Map<string, PatternMatch[]>;
|
|
36
|
+
private touched = new Set<string>();
|
|
36
37
|
private hits = 0;
|
|
37
38
|
private misses = 0;
|
|
38
39
|
|
|
@@ -44,7 +45,7 @@ export class ScanCache {
|
|
|
44
45
|
try {
|
|
45
46
|
const raw = await readFile(path, "utf-8");
|
|
46
47
|
const parsed = JSON.parse(raw) as CacheFile;
|
|
47
|
-
// A namespace mismatch means the ruleset or cache format changed
|
|
48
|
+
// A namespace mismatch means the ruleset or cache format changed: drop it.
|
|
48
49
|
if (parsed.namespace === namespace() && parsed.entries) {
|
|
49
50
|
return new ScanCache(new Map(Object.entries(parsed.entries)));
|
|
50
51
|
}
|
|
@@ -56,7 +57,9 @@ export class ScanCache {
|
|
|
56
57
|
|
|
57
58
|
/** Return cached findings for this file, or null on a miss. */
|
|
58
59
|
get(path: string, content: string): PatternMatch[] | null {
|
|
59
|
-
const
|
|
60
|
+
const key = keyFor(path, content);
|
|
61
|
+
this.touched.add(key);
|
|
62
|
+
const hit = this.entries.get(key);
|
|
60
63
|
if (hit) {
|
|
61
64
|
this.hits++;
|
|
62
65
|
return hit;
|
|
@@ -66,24 +69,22 @@ export class ScanCache {
|
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
set(path: string, content: string, matches: PatternMatch[]): void {
|
|
69
|
-
|
|
72
|
+
const key = keyFor(path, content);
|
|
73
|
+
this.touched.add(key);
|
|
74
|
+
this.entries.set(key, matches);
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
get stats(): { hits: number; misses: number } {
|
|
73
78
|
return { hits: this.hits, misses: this.misses };
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
/** Persist only
|
|
77
|
-
async save(path: string
|
|
81
|
+
/** Persist only entries read or written this run, so deleted files drop out. */
|
|
82
|
+
async save(path: string): Promise<void> {
|
|
78
83
|
const entries: Record<string, PatternMatch[]> = {};
|
|
79
84
|
for (const [k, v] of this.entries) {
|
|
80
|
-
if (touched.has(k)) entries[k] = v;
|
|
85
|
+
if (this.touched.has(k)) entries[k] = v;
|
|
81
86
|
}
|
|
82
87
|
const file: CacheFile = { namespace: namespace(), entries };
|
|
83
88
|
await writeFile(path, JSON.stringify(file));
|
|
84
89
|
}
|
|
85
|
-
|
|
86
|
-
keyOf(path: string, content: string): string {
|
|
87
|
-
return keyFor(path, content);
|
|
88
|
-
}
|
|
89
90
|
}
|
package/src/categorizer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Groups matches by HIG skill: rule category N maps to skill hig-N.
|
|
2
2
|
import type { PatternMatch } from "./patterns";
|
|
3
3
|
|
|
4
4
|
export interface CategorySummary {
|
|
@@ -16,35 +16,9 @@ export interface CategorySummary {
|
|
|
16
16
|
files: string[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const CATEGORY_TO_SKILL: Record<string, string> = {
|
|
20
|
-
"foundations": "hig-foundations",
|
|
21
|
-
"components-layout": "hig-components-layout",
|
|
22
|
-
"components-selection": "hig-components-selection",
|
|
23
|
-
"components-actions": "hig-components-actions",
|
|
24
|
-
"components-presentation": "hig-components-presentation",
|
|
25
|
-
"components-textinput": "hig-components-textinput",
|
|
26
|
-
"components-media": "hig-components-media",
|
|
27
|
-
"components-controls": "hig-components-controls",
|
|
28
|
-
"components-menus": "hig-components-menus",
|
|
29
|
-
"components-dialogs": "hig-components-dialogs",
|
|
30
|
-
"components-search": "hig-components-search",
|
|
31
|
-
"components-status": "hig-components-status",
|
|
32
|
-
"components-content": "hig-components-content",
|
|
33
|
-
"components-system": "hig-components-system",
|
|
34
|
-
"patterns": "hig-patterns",
|
|
35
|
-
"platforms": "hig-platforms",
|
|
36
|
-
"technologies": "hig-technologies",
|
|
37
|
-
"inputs": "hig-inputs",
|
|
38
|
-
};
|
|
39
|
-
|
|
40
19
|
const CATEGORY_LABELS: Record<string, string> = {
|
|
41
20
|
"hig-foundations": "Foundations",
|
|
42
21
|
"hig-components-layout": "Layout & Navigation",
|
|
43
|
-
"hig-components-selection": "Selection Controls",
|
|
44
|
-
"hig-components-actions": "Actions",
|
|
45
|
-
"hig-components-presentation": "Presentation",
|
|
46
|
-
"hig-components-textinput": "Text Input",
|
|
47
|
-
"hig-components-media": "Media",
|
|
48
22
|
"hig-components-controls": "Controls",
|
|
49
23
|
"hig-components-menus": "Menus & Actions",
|
|
50
24
|
"hig-components-dialogs": "Dialogs & Presentations",
|
|
@@ -64,7 +38,7 @@ export function categorizeMatches(matches: PatternMatch[]): CategorySummary[] {
|
|
|
64
38
|
const grouped = new Map<string, PatternMatch[]>();
|
|
65
39
|
|
|
66
40
|
for (const match of matches) {
|
|
67
|
-
const skillName =
|
|
41
|
+
const skillName = `hig-${match.category}`;
|
|
68
42
|
if (!grouped.has(skillName)) {
|
|
69
43
|
grouped.set(skillName, []);
|
|
70
44
|
}
|
package/src/config.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// { "files": ["marketing/**"], "rules": { "css/outline-none": "off" } }
|
|
9
9
|
// ]
|
|
10
10
|
// }
|
|
11
|
-
// Rule keys are stable rule IDs (see
|
|
11
|
+
// Rule keys are stable rule IDs (see the README rule table) or prefix globs ending in
|
|
12
12
|
// "*". Values: "off" drops the rule, a severity remaps concern severity, "on"
|
|
13
13
|
// keeps the default. Overrides apply per file glob; the last matching override
|
|
14
14
|
// wins over the global rules map.
|
|
@@ -56,11 +56,11 @@ function validateRules(
|
|
|
56
56
|
for (const [id, setting] of Object.entries(rules)) {
|
|
57
57
|
if (typeof setting !== "string" || !VALID_SETTINGS.has(setting)) {
|
|
58
58
|
throw new Error(
|
|
59
|
-
`${where}: invalid setting ${JSON.stringify(setting)} for rule "${id}"
|
|
59
|
+
`${where}: invalid setting ${JSON.stringify(setting)} for rule "${id}": expected "off", "on", "critical", "serious", or "moderate"`,
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
if (!id.includes("*") && !getRuleById(id)) {
|
|
63
|
-
warnings.push(`${where}: unknown rule ID "${id}"
|
|
63
|
+
warnings.push(`${where}: unknown rule ID "${id}"`);
|
|
64
64
|
}
|
|
65
65
|
out[id] = setting as RuleSetting;
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// @raintree-technology/hig-doctor-core
|
|
2
|
-
// The CLI, MCP server, and website audit demo all consume the engine through
|
|
3
|
-
// this module; keep additions here deliberate since they become npm API.
|
|
1
|
+
// Public API of @raintree-technology/hig-doctor-core. Everything exported here is npm API.
|
|
4
2
|
export {
|
|
5
3
|
audit,
|
|
6
4
|
type AuditOptions,
|
|
@@ -72,10 +70,3 @@ export {
|
|
|
72
70
|
type SuggestedFix,
|
|
73
71
|
type FixApplication,
|
|
74
72
|
} from "./fixes";
|
|
75
|
-
export {
|
|
76
|
-
runBenchmark,
|
|
77
|
-
BENCHMARK_CASES,
|
|
78
|
-
type BenchmarkCase,
|
|
79
|
-
type BenchmarkReport,
|
|
80
|
-
type RuleScore,
|
|
81
|
-
} from "./benchmark";
|
package/src/patterns.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// The authoritative rule count is the exported RULE_COUNT (end of file); never
|
|
4
|
-
// hardcode a count in prose — import RULE_COUNT instead.
|
|
1
|
+
// Rule catalog and the regex detection tier for every supported framework.
|
|
2
|
+
// Use the exported RULE_COUNT rather than hardcoding a count.
|
|
5
3
|
export type Severity = "critical" | "serious" | "moderate";
|
|
6
4
|
|
|
7
5
|
// The Apple HIG snapshot this ruleset and the skills corpus were authored
|
|
@@ -630,7 +628,7 @@ const flutterRules: PatternRule[] = [
|
|
|
630
628
|
// Color
|
|
631
629
|
{ category: "foundations", subcategory: "color", type: "positive", pattern: "Theme color", regex: /Theme\.of\(context\)\.colorScheme/, fileFilter: DART },
|
|
632
630
|
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color", regex: /Color\(0x[0-9a-fA-F]+\)/, fileFilter: DART },
|
|
633
|
-
{ category: "foundations", subcategory: "color", type: "concern", pattern: "Colors.red/blue", regex:
|
|
631
|
+
{ category: "foundations", subcategory: "color", type: "concern", pattern: "Colors.red/blue", regex: /\bColors\.(red|blue|green|yellow|orange|purple|pink|white|black|grey)\b/, fileFilter: DART },
|
|
634
632
|
// Typography
|
|
635
633
|
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "Theme text style", regex: /Theme\.of\(context\)\.textTheme/, fileFilter: DART },
|
|
636
634
|
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded fontSize", regex: /fontSize:\s*\d+/, fileFilter: DART },
|
|
@@ -1044,8 +1042,10 @@ export function ruleCatalog(): RuleMeta[] {
|
|
|
1044
1042
|
return allRules.map(toMeta);
|
|
1045
1043
|
}
|
|
1046
1044
|
|
|
1045
|
+
const rulesById = new Map(allRules.map(r => [r.id, r]));
|
|
1046
|
+
|
|
1047
1047
|
export function getRuleById(id: string): RuleMeta | undefined {
|
|
1048
|
-
const rule =
|
|
1048
|
+
const rule = rulesById.get(id);
|
|
1049
1049
|
return rule ? toMeta(rule) : undefined;
|
|
1050
1050
|
}
|
|
1051
1051
|
|
|
@@ -1131,7 +1131,7 @@ function suppressionCovers(ids: string[] | "all", ruleId: string): boolean {
|
|
|
1131
1131
|
* `hig-disable-*` comments the regex tier does.
|
|
1132
1132
|
*/
|
|
1133
1133
|
export function buildSuppressionFilter(code: string): (ruleId: string, line: number) => boolean {
|
|
1134
|
-
const rawLines = code.split(
|
|
1134
|
+
const rawLines = code.split(/\r?\n/);
|
|
1135
1135
|
|
|
1136
1136
|
// Collect suppressions before any stripping. next-line targets are 1-based.
|
|
1137
1137
|
let fileSuppression: string[] | "all" | null = null;
|
|
@@ -1165,7 +1165,7 @@ export function buildSuppressionFilter(code: string): (ruleId: string, line: num
|
|
|
1165
1165
|
// tiers on top. Callers wanting the strongest available analysis use analyzeFile.
|
|
1166
1166
|
export function detectPatterns(code: string, file: string): PatternMatch[] {
|
|
1167
1167
|
const matches: PatternMatch[] = [];
|
|
1168
|
-
const rawLines = code.split(
|
|
1168
|
+
const rawLines = code.split(/\r?\n/);
|
|
1169
1169
|
|
|
1170
1170
|
const isSuppressed = buildSuppressionFilter(code);
|
|
1171
1171
|
const isStyleFile = /\.(css|scss|sass|less)$/.test(file);
|
|
@@ -1303,5 +1303,4 @@ export function detectPatterns(code: string, file: string): PatternMatch[] {
|
|
|
1303
1303
|
return matches;
|
|
1304
1304
|
}
|
|
1305
1305
|
|
|
1306
|
-
// Export rule count for documentation
|
|
1307
1306
|
export const RULE_COUNT = allRules.length;
|
package/src/scanner.ts
CHANGED
|
@@ -127,10 +127,7 @@ async function loadIgnorePatterns(directory: string): Promise<string[]> {
|
|
|
127
127
|
function buildIgnoreMatcher(patterns: string[]): (relPath: string) => boolean {
|
|
128
128
|
const regexps = patterns.map(globToRegExp);
|
|
129
129
|
if (regexps.length === 0) return () => false;
|
|
130
|
-
return (relPath: string) =>
|
|
131
|
-
const posix = relPath.split(sep).join("/");
|
|
132
|
-
return regexps.some(re => re.test(posix));
|
|
133
|
-
};
|
|
130
|
+
return (relPath: string) => regexps.some(re => re.test(relPath));
|
|
134
131
|
}
|
|
135
132
|
|
|
136
133
|
// Read a UTF-8 file, skipping anything too large to be worth scanning. Returns
|
|
@@ -173,7 +170,8 @@ async function walkDir(dir: string, rootDir: string, result: ScanResult, isIgnor
|
|
|
173
170
|
}
|
|
174
171
|
for (const entry of entries) {
|
|
175
172
|
const fullPath = join(dir, entry.name);
|
|
176
|
-
|
|
173
|
+
// POSIX separators everywhere downstream: globs, baselines, SARIF, reports.
|
|
174
|
+
const relPath = relative(rootDir, fullPath).split(sep).join("/");
|
|
177
175
|
// Never follow symlinks: avoids escaping the scanned tree (e.g. a link to /)
|
|
178
176
|
// and breaks any directory cycles.
|
|
179
177
|
if (entry.isSymbolicLink()) continue;
|
package/CHANGELOG.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `@raintree-technology/hig-doctor-core` are documented here.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [0.1.3] - 2026-09-04
|
|
9
|
-
|
|
10
|
-
### Changed
|
|
11
|
-
|
|
12
|
-
- Established this package as the canonical audit engine and rule catalog for
|
|
13
|
-
the CLI, MCP server, website, and generated demonstration data.
|
|
14
|
-
|
|
15
|
-
## [0.1.2] - 2026-09-02
|
|
16
|
-
|
|
17
|
-
### Fixed
|
|
18
|
-
|
|
19
|
-
- Match `onMouseOver` and `onMouseOut` accessibility concerns within one JSX
|
|
20
|
-
element so handlers on separate elements cannot satisfy each other.
|
|
21
|
-
- Preserve valid `onFocus` and `onBlur` counterparts regardless of their
|
|
22
|
-
attribute order or line position inside the element.
|
|
23
|
-
|
|
24
|
-
## [0.1.1] - 2026-07-26
|
|
25
|
-
|
|
26
|
-
### Fixed
|
|
27
|
-
|
|
28
|
-
- Report the opening element's line for JSX findings and honor inline
|
|
29
|
-
suppressions in the AST tier.
|
|
30
|
-
- Fall back to regex analysis when Bun resolves a missing TypeScript compiler
|
|
31
|
-
to an unusable stub module.
|
|
32
|
-
- Include analysis-tier availability in cache identity so caches cannot replay
|
|
33
|
-
AST findings in environments without the AST tier.
|
|
34
|
-
- Scan native platform directories unless the project is Flutter or React
|
|
35
|
-
Native, and normalize Windows paths before applying config overrides.
|
|
36
|
-
- Keep safe CSS fixes out of comments and strings, including multi-line forms.
|
|
37
|
-
|
|
38
|
-
### Added
|
|
39
|
-
|
|
40
|
-
- `suggestFixInContent`, which uses surrounding file context when producing
|
|
41
|
-
machine-readable edits.
|
|
42
|
-
|
|
43
|
-
## [0.1.0] - 2026-07-21
|
|
44
|
-
|
|
45
|
-
Initial release of the extracted rule engine.
|
|
46
|
-
|
|
47
|
-
### Added
|
|
48
|
-
|
|
49
|
-
- `audit` pipeline (scan → detect → categorize → report) with config, baseline,
|
|
50
|
-
inline suppression, and content-hash cache support.
|
|
51
|
-
- Tiered analysis: `detectPatterns` (regex base tier), `analyzeFile` (regex +
|
|
52
|
-
Swift structural + TypeScript-compiler JSX refinement, each finding tagged
|
|
53
|
-
with its engine).
|
|
54
|
-
- Rule catalog with stable IDs, severities, engines, HIG citations, and fix
|
|
55
|
-
guidance (`ruleCatalog`, `getRuleById`); 431 rules across 14 frameworks.
|
|
56
|
-
- SARIF 2.1.0 output (`toSarif`) with suggested fixes.
|
|
57
|
-
- Baseline (`createBaseline` / `applyBaseline`), config (`loadConfig` /
|
|
58
|
-
`applyConfig`), fixes (`suggestFix` / `applyFixes`), and cache (`ScanCache`) APIs.
|