@raintree-technology/hig-doctor-core 0.1.2 → 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 -51
- 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/dist/index.js
CHANGED
|
@@ -116,10 +116,7 @@ async function loadIgnorePatterns(directory) {
|
|
|
116
116
|
function buildIgnoreMatcher(patterns) {
|
|
117
117
|
const regexps = patterns.map(globToRegExp);
|
|
118
118
|
if (regexps.length === 0) return () => false;
|
|
119
|
-
return (relPath) =>
|
|
120
|
-
const posix = relPath.split(sep).join("/");
|
|
121
|
-
return regexps.some((re) => re.test(posix));
|
|
122
|
-
};
|
|
119
|
+
return (relPath) => regexps.some((re) => re.test(relPath));
|
|
123
120
|
}
|
|
124
121
|
async function readText(path) {
|
|
125
122
|
try {
|
|
@@ -159,7 +156,7 @@ async function walkDir(dir, rootDir, result, isIgnored, skipPlatformHosts, depth
|
|
|
159
156
|
}
|
|
160
157
|
for (const entry of entries) {
|
|
161
158
|
const fullPath = join(dir, entry.name);
|
|
162
|
-
const relPath = relative(rootDir, fullPath);
|
|
159
|
+
const relPath = relative(rootDir, fullPath).split(sep).join("/");
|
|
163
160
|
if (entry.isSymbolicLink()) continue;
|
|
164
161
|
if (entry.isDirectory()) {
|
|
165
162
|
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
@@ -788,7 +785,7 @@ var flutterRules = [
|
|
|
788
785
|
// Color
|
|
789
786
|
{ category: "foundations", subcategory: "color", type: "positive", pattern: "Theme color", regex: /Theme\.of\(context\)\.colorScheme/, fileFilter: DART },
|
|
790
787
|
{ category: "foundations", subcategory: "color", type: "concern", pattern: "hardcoded Color", regex: /Color\(0x[0-9a-fA-F]+\)/, fileFilter: DART },
|
|
791
|
-
{ category: "foundations", subcategory: "color", type: "concern", pattern: "Colors.red/blue", regex:
|
|
788
|
+
{ 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 },
|
|
792
789
|
// Typography
|
|
793
790
|
{ category: "foundations", subcategory: "typography", type: "positive", pattern: "Theme text style", regex: /Theme\.of\(context\)\.textTheme/, fileFilter: DART },
|
|
794
791
|
{ category: "foundations", subcategory: "typography", type: "concern", pattern: "hardcoded fontSize", regex: /fontSize:\s*\d+/, fileFilter: DART },
|
|
@@ -1104,8 +1101,9 @@ function toMeta(rule) {
|
|
|
1104
1101
|
function ruleCatalog() {
|
|
1105
1102
|
return allRules.map(toMeta);
|
|
1106
1103
|
}
|
|
1104
|
+
var rulesById = new Map(allRules.map((r) => [r.id, r]));
|
|
1107
1105
|
function getRuleById(id) {
|
|
1108
|
-
const rule =
|
|
1106
|
+
const rule = rulesById.get(id);
|
|
1109
1107
|
return rule ? toMeta(rule) : void 0;
|
|
1110
1108
|
}
|
|
1111
1109
|
function stripComments(line, state, lineComments) {
|
|
@@ -1185,7 +1183,7 @@ function suppressionCovers(ids, ruleId) {
|
|
|
1185
1183
|
);
|
|
1186
1184
|
}
|
|
1187
1185
|
function buildSuppressionFilter(code) {
|
|
1188
|
-
const rawLines = code.split(
|
|
1186
|
+
const rawLines = code.split(/\r?\n/);
|
|
1189
1187
|
let fileSuppression = null;
|
|
1190
1188
|
const lineSuppressions = /* @__PURE__ */ new Map();
|
|
1191
1189
|
for (let i = 0; i < rawLines.length; i++) {
|
|
@@ -1210,7 +1208,7 @@ function buildSuppressionFilter(code) {
|
|
|
1210
1208
|
}
|
|
1211
1209
|
function detectPatterns(code, file) {
|
|
1212
1210
|
const matches = [];
|
|
1213
|
-
const rawLines = code.split(
|
|
1211
|
+
const rawLines = code.split(/\r?\n/);
|
|
1214
1212
|
const isSuppressed = buildSuppressionFilter(code);
|
|
1215
1213
|
const isStyleFile = /\.(css|scss|sass|less)$/.test(file);
|
|
1216
1214
|
const allowLineComments = !/\.(css|html?|xml|storyboard|xib)$/i.test(file);
|
|
@@ -1634,34 +1632,9 @@ function analyzeFile(code, file) {
|
|
|
1634
1632
|
}
|
|
1635
1633
|
|
|
1636
1634
|
// src/categorizer.ts
|
|
1637
|
-
var CATEGORY_TO_SKILL = {
|
|
1638
|
-
"foundations": "hig-foundations",
|
|
1639
|
-
"components-layout": "hig-components-layout",
|
|
1640
|
-
"components-selection": "hig-components-selection",
|
|
1641
|
-
"components-actions": "hig-components-actions",
|
|
1642
|
-
"components-presentation": "hig-components-presentation",
|
|
1643
|
-
"components-textinput": "hig-components-textinput",
|
|
1644
|
-
"components-media": "hig-components-media",
|
|
1645
|
-
"components-controls": "hig-components-controls",
|
|
1646
|
-
"components-menus": "hig-components-menus",
|
|
1647
|
-
"components-dialogs": "hig-components-dialogs",
|
|
1648
|
-
"components-search": "hig-components-search",
|
|
1649
|
-
"components-status": "hig-components-status",
|
|
1650
|
-
"components-content": "hig-components-content",
|
|
1651
|
-
"components-system": "hig-components-system",
|
|
1652
|
-
"patterns": "hig-patterns",
|
|
1653
|
-
"platforms": "hig-platforms",
|
|
1654
|
-
"technologies": "hig-technologies",
|
|
1655
|
-
"inputs": "hig-inputs"
|
|
1656
|
-
};
|
|
1657
1635
|
var CATEGORY_LABELS = {
|
|
1658
1636
|
"hig-foundations": "Foundations",
|
|
1659
1637
|
"hig-components-layout": "Layout & Navigation",
|
|
1660
|
-
"hig-components-selection": "Selection Controls",
|
|
1661
|
-
"hig-components-actions": "Actions",
|
|
1662
|
-
"hig-components-presentation": "Presentation",
|
|
1663
|
-
"hig-components-textinput": "Text Input",
|
|
1664
|
-
"hig-components-media": "Media",
|
|
1665
1638
|
"hig-components-controls": "Controls",
|
|
1666
1639
|
"hig-components-menus": "Menus & Actions",
|
|
1667
1640
|
"hig-components-dialogs": "Dialogs & Presentations",
|
|
@@ -1678,7 +1651,7 @@ function categorizeMatches(matches) {
|
|
|
1678
1651
|
if (matches.length === 0) return [];
|
|
1679
1652
|
const grouped = /* @__PURE__ */ new Map();
|
|
1680
1653
|
for (const match of matches) {
|
|
1681
|
-
const skillName =
|
|
1654
|
+
const skillName = `hig-${match.category}`;
|
|
1682
1655
|
if (!grouped.has(skillName)) {
|
|
1683
1656
|
grouped.set(skillName, []);
|
|
1684
1657
|
}
|
|
@@ -1788,7 +1761,7 @@ async function loadSkillContent(skillsDir, skillName) {
|
|
|
1788
1761
|
const skillPath = join2(skillsDir, skillName, "SKILL.md");
|
|
1789
1762
|
const content = await readFile2(skillPath, "utf-8");
|
|
1790
1763
|
const stripped = content.replace(/^---\s*\r?\n[\s\S]*?\r?\n---\s*(?:\r?\n|$)/, "");
|
|
1791
|
-
const principlesMatch = stripped.match(/## Key Principles\n([\s\S]*?)(?=\n## |$)/);
|
|
1764
|
+
const principlesMatch = stripped.match(/## Key Principles\r?\n([\s\S]*?)(?=\r?\n## |$)/);
|
|
1792
1765
|
return principlesMatch ? principlesMatch[1].trim() : stripped.slice(0, 2e3);
|
|
1793
1766
|
} catch {
|
|
1794
1767
|
return null;
|
|
@@ -1814,29 +1787,14 @@ function generateAuditMarkdown(scanResult, categories, skillsDir, skillContents)
|
|
|
1814
1787
|
const totalPatterns = categories.reduce((s, c) => s + c.patterns, 0);
|
|
1815
1788
|
lines.push(`**Quick stats**: ${totalConcerns} potential concerns, ${totalPositives} positive patterns, ${totalPatterns} component usages detected across ${categories.length} HIG categories`);
|
|
1816
1789
|
lines.push("");
|
|
1817
|
-
lines.push("##
|
|
1818
|
-
lines.push("");
|
|
1819
|
-
lines.push("You are reviewing a project for Apple Human Interface Guidelines compliance.");
|
|
1820
|
-
lines.push("The HIG principles (accessibility, color systems, typography, responsive layout, motion) apply to all surfaces \u2014 native, web, and cross-platform.");
|
|
1821
|
-
lines.push("For each category below, evaluate the code excerpts against the HIG reference material.");
|
|
1822
|
-
lines.push("");
|
|
1823
|
-
lines.push("**Scoring**: Rate each category 1-10:");
|
|
1824
|
-
lines.push("- **9-10**: Excellent HIG compliance, follows best practices");
|
|
1825
|
-
lines.push("- **7-8**: Good compliance with minor improvements possible");
|
|
1826
|
-
lines.push("- **5-6**: Partial compliance, several areas need attention");
|
|
1827
|
-
lines.push("- **3-4**: Significant HIG violations");
|
|
1828
|
-
lines.push("- **1-2**: Major violations or missing fundamental practices");
|
|
1790
|
+
lines.push("## How to use this report");
|
|
1829
1791
|
lines.push("");
|
|
1830
|
-
lines.push("
|
|
1831
|
-
lines.push("1. Score (1-10)");
|
|
1832
|
-
lines.push("2. What's done well (cite specific code)");
|
|
1833
|
-
lines.push("3. What needs improvement (cite specific file:line)");
|
|
1834
|
-
lines.push("4. Specific fix recommendations");
|
|
1792
|
+
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.");
|
|
1835
1793
|
lines.push("");
|
|
1836
1794
|
for (const category of categories) {
|
|
1837
1795
|
lines.push(`## Category: ${category.label}`);
|
|
1838
1796
|
lines.push("");
|
|
1839
|
-
lines.push(`*${category.matches.length} detections across ${category.fileCount} file(s)
|
|
1797
|
+
lines.push(`*${category.matches.length} detections across ${category.fileCount} file(s): ${category.concerns} concern(s), ${category.positives} positive(s)*`);
|
|
1840
1798
|
lines.push("");
|
|
1841
1799
|
lines.push("### Code Excerpts");
|
|
1842
1800
|
lines.push("");
|
|
@@ -1855,114 +1813,9 @@ function generateAuditMarkdown(scanResult, categories, skillsDir, skillContents)
|
|
|
1855
1813
|
lines.push(`*Load reference from skill: ${category.skillName}*`);
|
|
1856
1814
|
}
|
|
1857
1815
|
lines.push("");
|
|
1858
|
-
lines.push("### Evaluate");
|
|
1859
|
-
lines.push("");
|
|
1860
|
-
const checks = getEvaluationChecklist(category.skillName);
|
|
1861
|
-
for (const check of checks) {
|
|
1862
|
-
lines.push(`- ${check}`);
|
|
1863
|
-
}
|
|
1864
|
-
lines.push("");
|
|
1865
1816
|
}
|
|
1866
|
-
lines.push("## Scoring Summary");
|
|
1867
|
-
lines.push("");
|
|
1868
|
-
lines.push("| Category | Score (1-10) | Key Findings |");
|
|
1869
|
-
lines.push("|----------|-------------|-------------|");
|
|
1870
|
-
for (const category of categories) {
|
|
1871
|
-
lines.push(`| ${category.label} | | |`);
|
|
1872
|
-
}
|
|
1873
|
-
lines.push("| **Overall** | **/10** | |");
|
|
1874
|
-
lines.push("");
|
|
1875
1817
|
return lines.join("\n");
|
|
1876
1818
|
}
|
|
1877
|
-
function getEvaluationChecklist(skillName) {
|
|
1878
|
-
const checklists = {
|
|
1879
|
-
"hig-foundations": [
|
|
1880
|
-
"Color usage: system semantic colors vs hardcoded values",
|
|
1881
|
-
"Typography: Dynamic Type text styles vs fixed font sizes",
|
|
1882
|
-
"Accessibility: labels, hints, traits on interactive elements",
|
|
1883
|
-
"Dark mode: proper color adaptation, no hardcoded light/dark values",
|
|
1884
|
-
"Motion: Reduce Motion support for animations"
|
|
1885
|
-
],
|
|
1886
|
-
"hig-components-layout": [
|
|
1887
|
-
"Navigation pattern matches app structure (tabs for flat, sidebar for deep)",
|
|
1888
|
-
"Adaptive layout: responds to size classes, multitasking",
|
|
1889
|
-
"Standard navigation components (NavigationSplitView, not deprecated NavigationView)",
|
|
1890
|
-
"Consistent back navigation and spatial hierarchy"
|
|
1891
|
-
],
|
|
1892
|
-
"hig-components-controls": [
|
|
1893
|
-
"Standard control usage (Button, Toggle, Picker, etc.)",
|
|
1894
|
-
"Proper button styles and roles",
|
|
1895
|
-
"Clear action labels and consistent interaction patterns"
|
|
1896
|
-
],
|
|
1897
|
-
"hig-components-selection": [
|
|
1898
|
-
"Appropriate picker and selection controls",
|
|
1899
|
-
"Clear selection state feedback"
|
|
1900
|
-
],
|
|
1901
|
-
"hig-components-actions": [
|
|
1902
|
-
"Button hierarchy and prominence",
|
|
1903
|
-
"Destructive actions clearly marked",
|
|
1904
|
-
"Swipe actions follow HIG conventions"
|
|
1905
|
-
],
|
|
1906
|
-
"hig-components-presentation": [
|
|
1907
|
-
"Sheets for focused tasks, popovers for contextual info",
|
|
1908
|
-
"Alerts used sparingly for important decisions",
|
|
1909
|
-
"Confirmation dialogs for destructive actions"
|
|
1910
|
-
],
|
|
1911
|
-
"hig-components-textinput": [
|
|
1912
|
-
"Text fields use appropriate keyboard types",
|
|
1913
|
-
"Search functionality uses .searchable where appropriate"
|
|
1914
|
-
],
|
|
1915
|
-
"hig-components-media": [
|
|
1916
|
-
"Image handling with proper async loading",
|
|
1917
|
-
"Media playback uses system controls"
|
|
1918
|
-
],
|
|
1919
|
-
"hig-components-menus": [
|
|
1920
|
-
"Context menus provide relevant actions",
|
|
1921
|
-
"Menu organization follows HIG grouping conventions"
|
|
1922
|
-
],
|
|
1923
|
-
"hig-components-dialogs": [
|
|
1924
|
-
"Alerts used sparingly for important decisions",
|
|
1925
|
-
"Sheets for focused tasks, popovers for contextual info",
|
|
1926
|
-
"Confirmation dialogs for destructive actions"
|
|
1927
|
-
],
|
|
1928
|
-
"hig-components-search": [
|
|
1929
|
-
"Searchable modifier used for filterable content",
|
|
1930
|
-
"Search suggestions and scopes where appropriate"
|
|
1931
|
-
],
|
|
1932
|
-
"hig-components-status": [
|
|
1933
|
-
"Progress indicators for long operations",
|
|
1934
|
-
"Appropriate use of determinate vs indeterminate progress"
|
|
1935
|
-
],
|
|
1936
|
-
"hig-components-content": [
|
|
1937
|
-
"Content display uses appropriate containers",
|
|
1938
|
-
"Image handling with proper async loading"
|
|
1939
|
-
],
|
|
1940
|
-
"hig-components-system": [
|
|
1941
|
-
"System integration uses standard APIs (ShareLink, PhotosPicker)",
|
|
1942
|
-
"Deep link handling, widget support where relevant"
|
|
1943
|
-
],
|
|
1944
|
-
"hig-patterns": [
|
|
1945
|
-
"Drag and drop support where appropriate",
|
|
1946
|
-
"Pull-to-refresh for refreshable content",
|
|
1947
|
-
"Swipe actions follow HIG conventions",
|
|
1948
|
-
"Undo support for destructive actions"
|
|
1949
|
-
],
|
|
1950
|
-
"hig-inputs": [
|
|
1951
|
-
"Text input uses appropriate field types",
|
|
1952
|
-
"Keyboard shortcuts for power users (macOS/iPad)",
|
|
1953
|
-
"Gesture usage follows platform conventions"
|
|
1954
|
-
],
|
|
1955
|
-
"hig-technologies": [
|
|
1956
|
-
"Apple framework integration follows HIG for that technology",
|
|
1957
|
-
"Proper permission handling and progressive disclosure"
|
|
1958
|
-
],
|
|
1959
|
-
"hig-platforms": [
|
|
1960
|
-
"UI adapts appropriately across target platforms",
|
|
1961
|
-
"Platform idioms respected (iPhone vs iPad vs Mac)"
|
|
1962
|
-
]
|
|
1963
|
-
};
|
|
1964
|
-
return checklists[skillName] ?? ["Evaluate against Apple HIG best practices for this category"];
|
|
1965
|
-
}
|
|
1966
1819
|
|
|
1967
1820
|
// src/config.ts
|
|
1968
1821
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -1978,11 +1831,11 @@ function validateRules(rules, where, warnings) {
|
|
|
1978
1831
|
for (const [id, setting] of Object.entries(rules)) {
|
|
1979
1832
|
if (typeof setting !== "string" || !VALID_SETTINGS.has(setting)) {
|
|
1980
1833
|
throw new Error(
|
|
1981
|
-
`${where}: invalid setting ${JSON.stringify(setting)} for rule "${id}"
|
|
1834
|
+
`${where}: invalid setting ${JSON.stringify(setting)} for rule "${id}": expected "off", "on", "critical", "serious", or "moderate"`
|
|
1982
1835
|
);
|
|
1983
1836
|
}
|
|
1984
1837
|
if (!id.includes("*") && !getRuleById(id)) {
|
|
1985
|
-
warnings.push(`${where}: unknown rule ID "${id}"
|
|
1838
|
+
warnings.push(`${where}: unknown rule ID "${id}"`);
|
|
1986
1839
|
}
|
|
1987
1840
|
out[id] = setting;
|
|
1988
1841
|
}
|
|
@@ -2084,7 +1937,7 @@ import { isAbsolute as isAbsolute2, join as join4, resolve as resolve2 } from "n
|
|
|
2084
1937
|
var BASELINE_FILENAME = ".hig-baseline.json";
|
|
2085
1938
|
function baselineKey(match) {
|
|
2086
1939
|
const content = match.lineContent.replace(/\s+/g, " ").trim();
|
|
2087
|
-
return `${match.ruleId}\0${match.file}\0${content}`;
|
|
1940
|
+
return `${match.ruleId}\0${match.file.replace(/\\/g, "/")}\0${content}`;
|
|
2088
1941
|
}
|
|
2089
1942
|
function createBaseline(matches, generated) {
|
|
2090
1943
|
const findings = {};
|
|
@@ -2161,6 +2014,7 @@ function keyFor(path, content) {
|
|
|
2161
2014
|
}
|
|
2162
2015
|
var ScanCache = class _ScanCache {
|
|
2163
2016
|
entries;
|
|
2017
|
+
touched = /* @__PURE__ */ new Set();
|
|
2164
2018
|
hits = 0;
|
|
2165
2019
|
misses = 0;
|
|
2166
2020
|
constructor(entries) {
|
|
@@ -2179,7 +2033,9 @@ var ScanCache = class _ScanCache {
|
|
|
2179
2033
|
}
|
|
2180
2034
|
/** Return cached findings for this file, or null on a miss. */
|
|
2181
2035
|
get(path, content) {
|
|
2182
|
-
const
|
|
2036
|
+
const key = keyFor(path, content);
|
|
2037
|
+
this.touched.add(key);
|
|
2038
|
+
const hit = this.entries.get(key);
|
|
2183
2039
|
if (hit) {
|
|
2184
2040
|
this.hits++;
|
|
2185
2041
|
return hit;
|
|
@@ -2188,23 +2044,22 @@ var ScanCache = class _ScanCache {
|
|
|
2188
2044
|
return null;
|
|
2189
2045
|
}
|
|
2190
2046
|
set(path, content, matches) {
|
|
2191
|
-
|
|
2047
|
+
const key = keyFor(path, content);
|
|
2048
|
+
this.touched.add(key);
|
|
2049
|
+
this.entries.set(key, matches);
|
|
2192
2050
|
}
|
|
2193
2051
|
get stats() {
|
|
2194
2052
|
return { hits: this.hits, misses: this.misses };
|
|
2195
2053
|
}
|
|
2196
|
-
/** Persist only
|
|
2197
|
-
async save(path
|
|
2054
|
+
/** Persist only entries read or written this run, so deleted files drop out. */
|
|
2055
|
+
async save(path) {
|
|
2198
2056
|
const entries = {};
|
|
2199
2057
|
for (const [k, v] of this.entries) {
|
|
2200
|
-
if (touched.has(k)) entries[k] = v;
|
|
2058
|
+
if (this.touched.has(k)) entries[k] = v;
|
|
2201
2059
|
}
|
|
2202
2060
|
const file = { namespace: namespace(), entries };
|
|
2203
2061
|
await writeFile2(path, JSON.stringify(file));
|
|
2204
2062
|
}
|
|
2205
|
-
keyOf(path, content) {
|
|
2206
|
-
return keyFor(path, content);
|
|
2207
|
-
}
|
|
2208
2063
|
};
|
|
2209
2064
|
|
|
2210
2065
|
// src/audit.ts
|
|
@@ -2221,17 +2076,15 @@ async function audit(directory, skillsDir, options = {}) {
|
|
|
2221
2076
|
const allFiles = [...scanResult.codeFiles, ...scanResult.styleFiles, ...scanResult.markupFiles];
|
|
2222
2077
|
const cachePath = join5(resolvedDir, CACHE_FILENAME);
|
|
2223
2078
|
const cache = options.cache ? await ScanCache.load(cachePath) : null;
|
|
2224
|
-
const touched = /* @__PURE__ */ new Set();
|
|
2225
2079
|
for (const file of allFiles) {
|
|
2226
2080
|
let matches = cache?.get(file.relativePath, file.content) ?? null;
|
|
2227
2081
|
if (matches === null) {
|
|
2228
2082
|
matches = analyzeFile(file.content, file.relativePath);
|
|
2229
2083
|
cache?.set(file.relativePath, file.content, matches);
|
|
2230
2084
|
}
|
|
2231
|
-
if (cache) touched.add(cache.keyOf(file.relativePath, file.content));
|
|
2232
2085
|
detected.push(...matches);
|
|
2233
2086
|
}
|
|
2234
|
-
if (cache) await cache.save(cachePath
|
|
2087
|
+
if (cache) await cache.save(cachePath);
|
|
2235
2088
|
const configured = applyConfig(detected, loaded.config);
|
|
2236
2089
|
let allMatches = configured;
|
|
2237
2090
|
let baselinePath = null;
|
|
@@ -2253,13 +2106,7 @@ async function audit(directory, skillsDir, options = {}) {
|
|
|
2253
2106
|
if (skillsDir) {
|
|
2254
2107
|
resolvedSkillsDir = resolve3(skillsDir);
|
|
2255
2108
|
} else {
|
|
2256
|
-
const candidates = [
|
|
2257
|
-
join5(resolvedDir, "skills"),
|
|
2258
|
-
join5(resolvedDir, "..", "skills"),
|
|
2259
|
-
join5(resolvedDir, "..", "..", "skills"),
|
|
2260
|
-
// Relative to this package (for development: packages/core/src → repo root)
|
|
2261
|
-
join5(moduleDir, "..", "..", "..", "skills")
|
|
2262
|
-
];
|
|
2109
|
+
const candidates = [join5(resolvedDir, "skills"), join5(moduleDir, "..", "..", "..", "skills")];
|
|
2263
2110
|
for (const candidate of candidates) {
|
|
2264
2111
|
try {
|
|
2265
2112
|
await access(candidate);
|
|
@@ -2584,322 +2431,9 @@ function applyFixes(content, matches) {
|
|
|
2584
2431
|
}
|
|
2585
2432
|
return { content: lines.join("\n"), applied, suggestions };
|
|
2586
2433
|
}
|
|
2587
|
-
|
|
2588
|
-
// src/benchmark.ts
|
|
2589
|
-
var BENCHMARK_CASES = [
|
|
2590
|
-
// ── Swift / SwiftUI ────────────────────────────────────────────
|
|
2591
|
-
{
|
|
2592
|
-
id: "swift-color-bad",
|
|
2593
|
-
framework: "swift",
|
|
2594
|
-
file: "BadColors.swift",
|
|
2595
|
-
kind: "bad",
|
|
2596
|
-
code: `struct V: View {
|
|
2597
|
-
var body: some View {
|
|
2598
|
-
Text("Hi").foregroundColor(.red)
|
|
2599
|
-
Rectangle().foregroundColor(.blue)
|
|
2600
|
-
}
|
|
2601
|
-
}`,
|
|
2602
|
-
expect: ["swift/hardcoded-color", "swift/hardcoded-color"]
|
|
2603
|
-
},
|
|
2604
|
-
{
|
|
2605
|
-
id: "swift-color-good",
|
|
2606
|
-
framework: "swift",
|
|
2607
|
-
file: "GoodColors.swift",
|
|
2608
|
-
kind: "good",
|
|
2609
|
-
code: `struct V: View {
|
|
2610
|
-
var body: some View {
|
|
2611
|
-
Text("Hi").foregroundStyle(.primary)
|
|
2612
|
-
Rectangle().foregroundColor(Color("BrandAccent"))
|
|
2613
|
-
}
|
|
2614
|
-
}`,
|
|
2615
|
-
expect: []
|
|
2616
|
-
},
|
|
2617
|
-
{
|
|
2618
|
-
id: "swift-nav-bad",
|
|
2619
|
-
framework: "swift",
|
|
2620
|
-
file: "BadNav.swift",
|
|
2621
|
-
kind: "bad",
|
|
2622
|
-
code: `struct Root: View {
|
|
2623
|
-
var body: some View {
|
|
2624
|
-
NavigationView {
|
|
2625
|
-
Text("Legacy")
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
}`,
|
|
2629
|
-
expect: ["swift/navigation-view-deprecated"]
|
|
2630
|
-
},
|
|
2631
|
-
{
|
|
2632
|
-
id: "swift-nav-good",
|
|
2633
|
-
framework: "swift",
|
|
2634
|
-
file: "GoodNav.swift",
|
|
2635
|
-
kind: "good",
|
|
2636
|
-
code: `struct Root: View {
|
|
2637
|
-
var body: some View {
|
|
2638
|
-
NavigationStack {
|
|
2639
|
-
Text("Modern")
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
}`,
|
|
2643
|
-
expect: []
|
|
2644
|
-
},
|
|
2645
|
-
{
|
|
2646
|
-
id: "swift-typography-bad",
|
|
2647
|
-
framework: "swift",
|
|
2648
|
-
file: "BadType.swift",
|
|
2649
|
-
kind: "bad",
|
|
2650
|
-
code: `Text("Title").font(.system(size: 24))`,
|
|
2651
|
-
expect: ["swift/hardcoded-font-size"]
|
|
2652
|
-
},
|
|
2653
|
-
{
|
|
2654
|
-
id: "swift-typography-good",
|
|
2655
|
-
framework: "swift",
|
|
2656
|
-
file: "GoodType.swift",
|
|
2657
|
-
kind: "good",
|
|
2658
|
-
code: `Text("Title").font(.title)`,
|
|
2659
|
-
expect: []
|
|
2660
|
-
},
|
|
2661
|
-
// ── Web / React ────────────────────────────────────────────────
|
|
2662
|
-
{
|
|
2663
|
-
id: "web-img-bad",
|
|
2664
|
-
framework: "web",
|
|
2665
|
-
file: "BadImg.tsx",
|
|
2666
|
-
kind: "bad",
|
|
2667
|
-
code: `export const Hero = () => <img src="/hero.png" />;`,
|
|
2668
|
-
expect: ["web/missing-alt"]
|
|
2669
|
-
},
|
|
2670
|
-
{
|
|
2671
|
-
id: "web-img-good",
|
|
2672
|
-
framework: "web",
|
|
2673
|
-
file: "GoodImg.tsx",
|
|
2674
|
-
kind: "good",
|
|
2675
|
-
code: `export const Hero = () => <img src="/hero.png" alt="Product hero shot" />;`,
|
|
2676
|
-
expect: []
|
|
2677
|
-
},
|
|
2678
|
-
{
|
|
2679
|
-
id: "web-clickable-bad",
|
|
2680
|
-
framework: "web",
|
|
2681
|
-
file: "BadClick.tsx",
|
|
2682
|
-
kind: "bad",
|
|
2683
|
-
code: `export const Row = () => <div onClick={() => open()}>Open</div>;`,
|
|
2684
|
-
expect: ["web/div-with-on-click-no-role"]
|
|
2685
|
-
},
|
|
2686
|
-
{
|
|
2687
|
-
id: "web-clickable-good",
|
|
2688
|
-
framework: "web",
|
|
2689
|
-
file: "GoodClick.tsx",
|
|
2690
|
-
kind: "good",
|
|
2691
|
-
code: `export const Row = () => <button onClick={() => open()}>Open</button>;`,
|
|
2692
|
-
expect: []
|
|
2693
|
-
},
|
|
2694
|
-
{
|
|
2695
|
-
id: "web-tabindex-bad",
|
|
2696
|
-
framework: "web",
|
|
2697
|
-
file: "BadTab.tsx",
|
|
2698
|
-
kind: "bad",
|
|
2699
|
-
code: `export const F = () => <input tabIndex={3} />;`,
|
|
2700
|
-
expect: ["web/positive-tabindex"]
|
|
2701
|
-
},
|
|
2702
|
-
{
|
|
2703
|
-
id: "web-link-good",
|
|
2704
|
-
framework: "web",
|
|
2705
|
-
file: "GoodLink.tsx",
|
|
2706
|
-
kind: "good",
|
|
2707
|
-
code: `export const L = () => <a href="/pricing">See pricing plans</a>;`,
|
|
2708
|
-
expect: []
|
|
2709
|
-
},
|
|
2710
|
-
// ── CSS ────────────────────────────────────────────────────────
|
|
2711
|
-
{
|
|
2712
|
-
id: "css-outline-bad",
|
|
2713
|
-
framework: "css",
|
|
2714
|
-
file: "bad.css",
|
|
2715
|
-
kind: "bad",
|
|
2716
|
-
code: `button:focus { outline: none; }`,
|
|
2717
|
-
expect: ["css/outline-none"]
|
|
2718
|
-
},
|
|
2719
|
-
{
|
|
2720
|
-
id: "css-outline-good",
|
|
2721
|
-
framework: "css",
|
|
2722
|
-
file: "good.css",
|
|
2723
|
-
kind: "good",
|
|
2724
|
-
code: `button:focus-visible { outline: 2px solid Highlight; }`,
|
|
2725
|
-
expect: []
|
|
2726
|
-
},
|
|
2727
|
-
{
|
|
2728
|
-
id: "css-important-bad",
|
|
2729
|
-
framework: "css",
|
|
2730
|
-
file: "important.css",
|
|
2731
|
-
kind: "bad",
|
|
2732
|
-
code: `.a { color: var(--fg) !important; }`,
|
|
2733
|
-
expect: ["css/important-usage"]
|
|
2734
|
-
},
|
|
2735
|
-
{
|
|
2736
|
-
id: "css-logical-good",
|
|
2737
|
-
framework: "css",
|
|
2738
|
-
file: "logical.css",
|
|
2739
|
-
kind: "good",
|
|
2740
|
-
code: `.a { text-align: start; margin-inline-start: 8px; }`,
|
|
2741
|
-
expect: []
|
|
2742
|
-
},
|
|
2743
|
-
// ── HTML ───────────────────────────────────────────────────────
|
|
2744
|
-
{
|
|
2745
|
-
id: "html-viewport-bad",
|
|
2746
|
-
framework: "web",
|
|
2747
|
-
file: "bad.html",
|
|
2748
|
-
kind: "bad",
|
|
2749
|
-
code: `<!doctype html><html lang="en"><head><meta name="viewport" content="width=device-width, user-scalable=no"></head><body><h1>Hi</h1></body></html>`,
|
|
2750
|
-
expect: ["web/user-scalable-no"]
|
|
2751
|
-
},
|
|
2752
|
-
{
|
|
2753
|
-
id: "html-good",
|
|
2754
|
-
framework: "web",
|
|
2755
|
-
file: "good.html",
|
|
2756
|
-
kind: "good",
|
|
2757
|
-
code: `<!doctype html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><h1>Hi</h1></body></html>`,
|
|
2758
|
-
expect: []
|
|
2759
|
-
},
|
|
2760
|
-
// ── AST-tier precision cases (regex would misjudge these) ──────
|
|
2761
|
-
{
|
|
2762
|
-
id: "web-img-spread-good",
|
|
2763
|
-
framework: "web",
|
|
2764
|
-
file: "SpreadImg.tsx",
|
|
2765
|
-
kind: "good",
|
|
2766
|
-
code: `export const Avatar = (props) => <img {...props} />;`,
|
|
2767
|
-
expect: []
|
|
2768
|
-
// spread props may carry alt — the AST tier abstains
|
|
2769
|
-
},
|
|
2770
|
-
{
|
|
2771
|
-
id: "web-img-multiline-bad",
|
|
2772
|
-
framework: "web",
|
|
2773
|
-
file: "MultilineImg.tsx",
|
|
2774
|
-
kind: "bad",
|
|
2775
|
-
code: `export const Hero = () => (
|
|
2776
|
-
<img
|
|
2777
|
-
src="/hero.png"
|
|
2778
|
-
width={640}
|
|
2779
|
-
/>
|
|
2780
|
-
);`,
|
|
2781
|
-
expect: ["web/missing-alt"]
|
|
2782
|
-
},
|
|
2783
|
-
{
|
|
2784
|
-
id: "web-div-nested-gt-bad",
|
|
2785
|
-
framework: "web",
|
|
2786
|
-
file: "NestedGt.tsx",
|
|
2787
|
-
kind: "bad",
|
|
2788
|
-
code: `export const Row = () => (
|
|
2789
|
-
<div onClick={() => select(a > b ? a : b)}>
|
|
2790
|
-
Pick
|
|
2791
|
-
</div>
|
|
2792
|
-
);`,
|
|
2793
|
-
expect: ["web/div-with-on-click-no-role"]
|
|
2794
|
-
},
|
|
2795
|
-
{
|
|
2796
|
-
id: "web-span-keyboard-good",
|
|
2797
|
-
framework: "web",
|
|
2798
|
-
file: "AccessibleSpan.tsx",
|
|
2799
|
-
kind: "good",
|
|
2800
|
-
code: `export const Row = () => (
|
|
2801
|
-
<span role="button" tabIndex={0} onKeyDown={onKey} onClick={onClick}>
|
|
2802
|
-
Pick
|
|
2803
|
-
</span>
|
|
2804
|
-
);`,
|
|
2805
|
-
expect: []
|
|
2806
|
-
// AST tier abstains: role + tabIndex + keydown make it operable
|
|
2807
|
-
},
|
|
2808
|
-
{
|
|
2809
|
-
id: "swift-image-labeled-good",
|
|
2810
|
-
framework: "swift",
|
|
2811
|
-
file: "LabeledImage.swift",
|
|
2812
|
-
kind: "good",
|
|
2813
|
-
code: `Image(systemName: "star")
|
|
2814
|
-
.resizable()
|
|
2815
|
-
.accessibilityLabel("Favorite")`,
|
|
2816
|
-
expect: []
|
|
2817
|
-
// structural analysis sees the chained label
|
|
2818
|
-
},
|
|
2819
|
-
{
|
|
2820
|
-
id: "swift-image-bare-bad",
|
|
2821
|
-
framework: "swift",
|
|
2822
|
-
file: "BareImage.swift",
|
|
2823
|
-
kind: "bad",
|
|
2824
|
-
code: `Image(systemName: "star").frame(width: 20, height: 20)`,
|
|
2825
|
-
expect: ["swift/image-without-a11y"]
|
|
2826
|
-
},
|
|
2827
|
-
// ── Cross-platform ─────────────────────────────────────────────
|
|
2828
|
-
{
|
|
2829
|
-
id: "compose-clickable-bad",
|
|
2830
|
-
framework: "compose",
|
|
2831
|
-
file: "Bad.kt",
|
|
2832
|
-
kind: "bad",
|
|
2833
|
-
code: `Box(Modifier.clickable { open() }) { Text("Open") }`,
|
|
2834
|
-
expect: ["compose/clickable-without-role"]
|
|
2835
|
-
},
|
|
2836
|
-
{
|
|
2837
|
-
id: "android-image-bad",
|
|
2838
|
-
framework: "android-xml",
|
|
2839
|
-
file: "bad.xml",
|
|
2840
|
-
kind: "bad",
|
|
2841
|
-
code: `<ImageView android:src="@drawable/logo" android:layout_width="48dp" android:layout_height="48dp" />`,
|
|
2842
|
-
expect: ["android-xml/image-view-without-content-description"]
|
|
2843
|
-
},
|
|
2844
|
-
{
|
|
2845
|
-
id: "flutter-color-bad",
|
|
2846
|
-
framework: "flutter",
|
|
2847
|
-
file: "bad.dart",
|
|
2848
|
-
kind: "bad",
|
|
2849
|
-
code: `Container(color: Color(0xFFFF0000));`,
|
|
2850
|
-
expect: ["flutter/hardcoded-color"]
|
|
2851
|
-
}
|
|
2852
|
-
];
|
|
2853
|
-
function ratio(n, d) {
|
|
2854
|
-
return d === 0 ? 1 : Math.round(n / d * 1e3) / 1e3;
|
|
2855
|
-
}
|
|
2856
|
-
function runBenchmark(cases = BENCHMARK_CASES) {
|
|
2857
|
-
const tp = /* @__PURE__ */ new Map();
|
|
2858
|
-
const fp = /* @__PURE__ */ new Map();
|
|
2859
|
-
const fn = /* @__PURE__ */ new Map();
|
|
2860
|
-
const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
|
|
2861
|
-
const falsePositives = [];
|
|
2862
|
-
const falseNegatives = [];
|
|
2863
|
-
for (const c of cases) {
|
|
2864
|
-
const concerns = analyzeFile(c.code, c.file).filter((m) => m.type === "concern");
|
|
2865
|
-
const expected = [...c.expect];
|
|
2866
|
-
for (const match of concerns) {
|
|
2867
|
-
const idx = expected.indexOf(match.ruleId);
|
|
2868
|
-
if (idx !== -1) {
|
|
2869
|
-
expected.splice(idx, 1);
|
|
2870
|
-
bump(tp, match.ruleId);
|
|
2871
|
-
} else {
|
|
2872
|
-
bump(fp, match.ruleId);
|
|
2873
|
-
falsePositives.push({ case: c.id, ruleId: match.ruleId, line: match.line });
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
for (const missed of expected) {
|
|
2877
|
-
bump(fn, missed);
|
|
2878
|
-
falseNegatives.push({ case: c.id, ruleId: missed });
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
const ruleIds = /* @__PURE__ */ new Set([...tp.keys(), ...fp.keys(), ...fn.keys()]);
|
|
2882
|
-
const perRule = [...ruleIds].sort().map((ruleId) => {
|
|
2883
|
-
const t = tp.get(ruleId) ?? 0;
|
|
2884
|
-
const f = fp.get(ruleId) ?? 0;
|
|
2885
|
-
const n = fn.get(ruleId) ?? 0;
|
|
2886
|
-
return { ruleId, tp: t, fp: f, fn: n, precision: ratio(t, t + f), recall: ratio(t, t + n) };
|
|
2887
|
-
});
|
|
2888
|
-
const sum = (m) => [...m.values()].reduce((a, b) => a + b, 0);
|
|
2889
|
-
const T = sum(tp);
|
|
2890
|
-
const F = sum(fp);
|
|
2891
|
-
const N = sum(fn);
|
|
2892
|
-
return {
|
|
2893
|
-
perRule,
|
|
2894
|
-
overall: { tp: T, fp: F, fn: N, precision: ratio(T, T + F), recall: ratio(T, T + N) },
|
|
2895
|
-
falsePositives,
|
|
2896
|
-
falseNegatives
|
|
2897
|
-
};
|
|
2898
|
-
}
|
|
2899
2434
|
export {
|
|
2900
2435
|
AST_TSX_RULES,
|
|
2901
2436
|
BASELINE_FILENAME,
|
|
2902
|
-
BENCHMARK_CASES,
|
|
2903
2437
|
CACHE_FILENAME,
|
|
2904
2438
|
CONFIG_FILENAME,
|
|
2905
2439
|
HIG_SNAPSHOT_DATE,
|
|
@@ -2928,7 +2462,6 @@ export {
|
|
|
2928
2462
|
parseConfig,
|
|
2929
2463
|
refineSwift,
|
|
2930
2464
|
ruleCatalog,
|
|
2931
|
-
runBenchmark,
|
|
2932
2465
|
scanProject,
|
|
2933
2466
|
severityFor,
|
|
2934
2467
|
suggestFix,
|