@raintree-technology/hig-doctor-core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +23 -1
- package/dist/analyze.d.ts +2 -0
- package/dist/baseline.d.ts +28 -0
- package/dist/benchmark.d.ts +38 -0
- package/dist/cache.d.ts +19 -0
- package/dist/config.d.ts +26 -0
- package/dist/engines/ast-tsx.d.ts +12 -0
- package/dist/engines/swift-structural.d.ts +7 -0
- package/dist/fixes.d.ts +26 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +183 -25
- package/dist/patterns.d.ts +6 -0
- package/dist/sarif.d.ts +11 -0
- package/package.json +1 -1
- package/src/analyze.ts +5 -3
- package/src/cache.test.ts +26 -0
- package/src/cache.ts +8 -2
- package/src/config.test.ts +25 -0
- package/src/config.ts +6 -1
- package/src/engines/ast-tsx.test.ts +68 -1
- package/src/engines/ast-tsx.ts +32 -4
- package/src/fixes.test.ts +66 -1
- package/src/fixes.ts +135 -6
- package/src/index.ts +1 -0
- package/src/patterns.test.ts +29 -1
- package/src/patterns.ts +20 -9
- package/src/scanner.test.ts +43 -0
- package/src/scanner.ts +29 -4
package/src/scanner.test.ts
CHANGED
|
@@ -83,6 +83,49 @@ describe("scanProject", () => {
|
|
|
83
83
|
expect(result.codeFiles.length).toBe(1);
|
|
84
84
|
} finally { await rm(dir, { recursive: true }); }
|
|
85
85
|
});
|
|
86
|
+
|
|
87
|
+
// `ios/` is generated boilerplate in Flutter/RN but real source in a native
|
|
88
|
+
// app; skipping it unconditionally reported such projects clean.
|
|
89
|
+
test("scans ios/ sources in a native project", async () => {
|
|
90
|
+
const dir = await mkdtemp(join(tmpdir(), "hig-test-"));
|
|
91
|
+
try {
|
|
92
|
+
await mkdir(join(dir, "ios", "MyApp"), { recursive: true });
|
|
93
|
+
await writeFile(join(dir, "ios", "MyApp", "ContentView.swift"), "import SwiftUI\nstruct ContentView: View {}");
|
|
94
|
+
const result = await scanProject(dir);
|
|
95
|
+
expect(result.swiftFiles.length).toBe(1);
|
|
96
|
+
expect(result.frameworks).toContain("swiftui");
|
|
97
|
+
} finally { await rm(dir, { recursive: true }); }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("still skips generated platform hosts in a Flutter project", async () => {
|
|
101
|
+
const dir = await mkdtemp(join(tmpdir(), "hig-test-"));
|
|
102
|
+
try {
|
|
103
|
+
await writeFile(join(dir, "pubspec.yaml"), "name: demo\n");
|
|
104
|
+
await mkdir(join(dir, "ios", "Runner"), { recursive: true });
|
|
105
|
+
await writeFile(join(dir, "ios", "Runner", "AppDelegate.swift"), "import UIKit");
|
|
106
|
+
await mkdir(join(dir, "android", "app"), { recursive: true });
|
|
107
|
+
await writeFile(join(dir, "android", "app", "Main.kt"), "class Main");
|
|
108
|
+
await mkdir(join(dir, "lib"), { recursive: true });
|
|
109
|
+
await writeFile(join(dir, "lib", "main.dart"), "void main() {}");
|
|
110
|
+
const result = await scanProject(dir);
|
|
111
|
+
expect(result.swiftFiles.length).toBe(0);
|
|
112
|
+
expect(result.codeFiles.map(f => f.relativePath)).toEqual([join("lib", "main.dart")]);
|
|
113
|
+
} finally { await rm(dir, { recursive: true }); }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("still skips generated platform hosts in a React Native project", async () => {
|
|
117
|
+
const dir = await mkdtemp(join(tmpdir(), "hig-test-"));
|
|
118
|
+
try {
|
|
119
|
+
await writeFile(join(dir, "package.json"), JSON.stringify({ dependencies: { "react-native": "0.76.0" } }));
|
|
120
|
+
await mkdir(join(dir, "ios"), { recursive: true });
|
|
121
|
+
await writeFile(join(dir, "ios", "AppDelegate.swift"), "import UIKit");
|
|
122
|
+
await mkdir(join(dir, "src"), { recursive: true });
|
|
123
|
+
await writeFile(join(dir, "src", "App.tsx"), "export const App = () => null;");
|
|
124
|
+
const result = await scanProject(dir);
|
|
125
|
+
expect(result.swiftFiles.length).toBe(0);
|
|
126
|
+
expect(result.codeFiles.some(f => f.relativePath.endsWith("App.tsx"))).toBe(true);
|
|
127
|
+
} finally { await rm(dir, { recursive: true }); }
|
|
128
|
+
});
|
|
86
129
|
});
|
|
87
130
|
|
|
88
131
|
describe("scanProject — ignore patterns", () => {
|
package/src/scanner.ts
CHANGED
|
@@ -31,9 +31,15 @@ const IGNORED_DIRS = new Set([
|
|
|
31
31
|
".build", ".git", "node_modules", "Pods", "DerivedData",
|
|
32
32
|
".swiftpm", "Carthage", "Build", ".next", ".nuxt", ".output",
|
|
33
33
|
"dist", "build", ".cache", ".turbo", "coverage", "__pycache__",
|
|
34
|
-
".dart_tool", ".pub-cache",
|
|
34
|
+
".dart_tool", ".pub-cache",
|
|
35
35
|
]);
|
|
36
36
|
|
|
37
|
+
// Flutter and React Native generate these as platform host directories full of
|
|
38
|
+
// boilerplate, so they're noise there. Everywhere else they hold real source —
|
|
39
|
+
// a native iOS app under `ios/` is the common layout — and skipping them
|
|
40
|
+
// unconditionally made the Swift tiers silently report such projects clean.
|
|
41
|
+
const PLATFORM_HOST_DIRS = new Set(["android", "ios", "macos", "linux", "windows"]);
|
|
42
|
+
|
|
37
43
|
// Skip files larger than this — generated bundles, minified assets, and data
|
|
38
44
|
// blobs cost memory and regex time without yielding real findings. The auditor
|
|
39
45
|
// runs on arbitrary paths (including via the MCP server), so this is also a DoS
|
|
@@ -139,7 +145,25 @@ async function readText(path: string): Promise<string | null> {
|
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
// Flutter/React Native roots own generated platform host directories; detected
|
|
149
|
+
// once at the scan root so the walker can skip them only for those projects.
|
|
150
|
+
async function hasCrossPlatformHost(directory: string): Promise<boolean> {
|
|
151
|
+
const exists = async (name: string) => {
|
|
152
|
+
try { await stat(join(directory, name)); return true; } catch { return false; }
|
|
153
|
+
};
|
|
154
|
+
if (await exists("pubspec.yaml")) return true;
|
|
155
|
+
if (await exists("app.json") || await exists("expo.json") || await exists("eas.json")) return true;
|
|
156
|
+
try {
|
|
157
|
+
const pkg = JSON.parse(await readFile(join(directory, "package.json"), "utf-8"));
|
|
158
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
159
|
+
if (deps["react-native"] || deps["expo"]) return true;
|
|
160
|
+
} catch {
|
|
161
|
+
// no/unreadable package.json — not a JS cross-platform root
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function walkDir(dir: string, rootDir: string, result: ScanResult, isIgnored: (relPath: string) => boolean, skipPlatformHosts: boolean, depth = 0): Promise<void> {
|
|
143
167
|
if (depth > MAX_DEPTH) return;
|
|
144
168
|
let entries;
|
|
145
169
|
try {
|
|
@@ -155,10 +179,11 @@ async function walkDir(dir: string, rootDir: string, result: ScanResult, isIgnor
|
|
|
155
179
|
if (entry.isSymbolicLink()) continue;
|
|
156
180
|
if (entry.isDirectory()) {
|
|
157
181
|
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
182
|
+
if (skipPlatformHosts && PLATFORM_HOST_DIRS.has(entry.name)) continue;
|
|
158
183
|
if (isIgnored(relPath)) continue;
|
|
159
184
|
if (entry.name.endsWith(".xcassets")) { result.assetCatalogs.push(relPath); continue; }
|
|
160
185
|
if (entry.name.endsWith(".xcodeproj") || entry.name.endsWith(".xcworkspace")) { result.xcodeProjects.push(relPath); continue; }
|
|
161
|
-
await walkDir(fullPath, rootDir, result, isIgnored, depth + 1);
|
|
186
|
+
await walkDir(fullPath, rootDir, result, isIgnored, skipPlatformHosts, depth + 1);
|
|
162
187
|
} else if (entry.isFile()) {
|
|
163
188
|
const ext = extname(entry.name);
|
|
164
189
|
// Skip test/spec files — they contain example code that triggers false positives
|
|
@@ -298,7 +323,7 @@ export async function scanProject(directory: string, options: ScanOptions = {}):
|
|
|
298
323
|
};
|
|
299
324
|
const patterns = [...(await loadIgnorePatterns(directory)), ...(options.exclude ?? [])];
|
|
300
325
|
const isIgnored = buildIgnoreMatcher(patterns);
|
|
301
|
-
await walkDir(directory, directory, result, isIgnored);
|
|
326
|
+
await walkDir(directory, directory, result, isIgnored, await hasCrossPlatformHost(directory));
|
|
302
327
|
result.frameworks = detectFrameworks(result);
|
|
303
328
|
return result;
|
|
304
329
|
}
|