@raintree-technology/hig-doctor-core 0.1.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/CHANGELOG.md +23 -0
- package/README.md +38 -0
- package/dist/audit-generator.d.ts +4 -0
- package/dist/audit.d.ts +39 -0
- package/dist/categorizer.d.ts +16 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +2780 -0
- package/dist/patterns.d.ts +53 -0
- package/dist/scanner.d.ts +26 -0
- package/package.json +58 -0
- package/src/analyze.ts +35 -0
- package/src/audit-generator.test.ts +166 -0
- package/src/audit-generator.ts +294 -0
- package/src/audit.test.ts +121 -0
- package/src/audit.ts +150 -0
- package/src/baseline.test.ts +83 -0
- package/src/baseline.ts +0 -0
- package/src/benchmark.test.ts +29 -0
- package/src/benchmark.ts +354 -0
- package/src/cache.test.ts +64 -0
- package/src/cache.ts +83 -0
- package/src/categorizer.test.ts +51 -0
- package/src/categorizer.ts +98 -0
- package/src/config.test.ts +131 -0
- package/src/config.ts +174 -0
- package/src/engines/ast-tsx.test.ts +54 -0
- package/src/engines/ast-tsx.ts +167 -0
- package/src/engines/swift-structural.test.ts +39 -0
- package/src/engines/swift-structural.ts +171 -0
- package/src/fixes.test.ts +87 -0
- package/src/fixes.ts +136 -0
- package/src/index.ts +80 -0
- package/src/patterns.test.ts +844 -0
- package/src/patterns.ts +1296 -0
- package/src/sarif.test.ts +39 -0
- package/src/sarif.ts +117 -0
- package/src/scanner.test.ts +153 -0
- package/src/scanner.ts +304 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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.0] - 2026-07-21
|
|
9
|
+
|
|
10
|
+
Initial release of the extracted rule engine.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `audit` pipeline (scan → detect → categorize → report) with config, baseline,
|
|
15
|
+
inline suppression, and content-hash cache support.
|
|
16
|
+
- Tiered analysis: `detectPatterns` (regex base tier), `analyzeFile` (regex +
|
|
17
|
+
Swift structural + TypeScript-compiler JSX refinement, each finding tagged
|
|
18
|
+
with its engine).
|
|
19
|
+
- Rule catalog with stable IDs, severities, engines, HIG citations, and fix
|
|
20
|
+
guidance (`ruleCatalog`, `getRuleById`); 431 rules across 15 frameworks.
|
|
21
|
+
- SARIF 2.1.0 output (`toSarif`) with suggested fixes.
|
|
22
|
+
- Baseline (`createBaseline` / `applyBaseline`), config (`loadConfig` /
|
|
23
|
+
`applyConfig`), fixes (`suggestFix` / `applyFixes`), and cache (`ScanCache`) APIs.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/raintree-technology/hig-doctor/main/brand/hig-doctor-mark.svg" alt="HIG Doctor" width="72" height="72" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @raintree-technology/hig-doctor-core
|
|
6
|
+
|
|
7
|
+
The rule engine behind [HIG Doctor](https://github.com/raintree-technology/hig-doctor): framework detection, the Apple HIG rule catalog, tiered analysis (regex → Swift structural → TypeScript-compiler JSX), and the audit pipeline. The [`hig-doctor`](../cli) CLI and [`hig-mcp`](../mcp) server are thin wrappers over this package; embed it directly to run audits from your own tooling.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { audit, analyzeFile, ruleCatalog, toSarif } from "@raintree-technology/hig-doctor-core";
|
|
11
|
+
|
|
12
|
+
// Whole-directory audit (honors hig-doctor.config.json, baselines, suppressions)
|
|
13
|
+
const result = await audit("./my-app");
|
|
14
|
+
console.log(result.categories, result.configPath, result.baselined);
|
|
15
|
+
|
|
16
|
+
// Single-file analysis (regex + AST/structural refinement), engine-tagged
|
|
17
|
+
const findings = analyzeFile(source, "Header.tsx");
|
|
18
|
+
|
|
19
|
+
// Rule metadata for docs, dashboards, or an editor integration
|
|
20
|
+
for (const rule of ruleCatalog()) {
|
|
21
|
+
console.log(rule.id, rule.severity, rule.engine, rule.hig, rule.fix);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Exports
|
|
26
|
+
|
|
27
|
+
- `audit(dir, skillsDir?, options?)` — full scan → detect → categorize → report, with config, baseline, and cache support.
|
|
28
|
+
- `analyzeFile(content, file)` — tiered per-file analysis; every match is tagged `regex` / `swift-structural` / `ast-tsx`.
|
|
29
|
+
- `detectPatterns(content, file)` — the regex base tier alone (zero dependencies).
|
|
30
|
+
- `ruleCatalog()` / `getRuleById(id)` — stable rule IDs, severities, engines, HIG citations, and fix guidance.
|
|
31
|
+
- `toSarif(matches, options)` — SARIF 2.1.0 with optional suggested fixes.
|
|
32
|
+
- `createBaseline` / `applyBaseline`, `loadConfig` / `applyConfig`, `suggestFix` / `applyFixes`, `ScanCache`.
|
|
33
|
+
|
|
34
|
+
The `ast-tsx` tier uses the TypeScript compiler when the optional `typescript` dependency is present, and falls back to the regex tier otherwise.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT. Apple HIG reference content the engine cites is © Apple Inc. — see the repository [LICENSE](../../LICENSE).
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ScanResult } from "./scanner";
|
|
2
|
+
import type { CategorySummary } from "./categorizer";
|
|
3
|
+
export declare function loadSkillContent(skillsDir: string, skillName: string): Promise<string | null>;
|
|
4
|
+
export declare function generateAuditMarkdown(scanResult: ScanResult, categories: CategorySummary[], skillsDir: string | null, skillContents?: Map<string, string>): string;
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ScanResult } from "./scanner";
|
|
2
|
+
import { type PatternMatch } from "./patterns";
|
|
3
|
+
import { type CategorySummary } from "./categorizer";
|
|
4
|
+
export interface AuditOptions {
|
|
5
|
+
/** Path globs (relative to the audited directory) to exclude from scanning. */
|
|
6
|
+
exclude?: string[];
|
|
7
|
+
/** Explicit path to a hig-doctor.config.json (default: discovered in the audited directory). */
|
|
8
|
+
configPath?: string;
|
|
9
|
+
/** Skip config discovery entirely. */
|
|
10
|
+
noConfig?: boolean;
|
|
11
|
+
/** Explicit path to a .hig-baseline.json (default: discovered in the audited directory). */
|
|
12
|
+
baselinePath?: string;
|
|
13
|
+
/** Skip baseline discovery entirely. */
|
|
14
|
+
noBaseline?: boolean;
|
|
15
|
+
/** Enable the content-hash cache under the audited directory (local scans). */
|
|
16
|
+
cache?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface AuditResult {
|
|
19
|
+
scanResult: ScanResult;
|
|
20
|
+
allMatches: PatternMatch[];
|
|
21
|
+
categories: CategorySummary[];
|
|
22
|
+
markdown: string;
|
|
23
|
+
/** Absolute path of the applied config file, or null. */
|
|
24
|
+
configPath: string | null;
|
|
25
|
+
/** Non-fatal config problems (unknown rule IDs etc.). */
|
|
26
|
+
configWarnings: string[];
|
|
27
|
+
/** Absolute path of the applied baseline file, or null. */
|
|
28
|
+
baselinePath: string | null;
|
|
29
|
+
/** Concerns absorbed by the baseline (hidden from results and gating). */
|
|
30
|
+
baselined: number;
|
|
31
|
+
/** Baseline occurrences that no longer match anything — time to re-snapshot. */
|
|
32
|
+
baselineStale: number;
|
|
33
|
+
/** Cache hit/miss counts when the cache is enabled, else null. */
|
|
34
|
+
cacheStats: {
|
|
35
|
+
hits: number;
|
|
36
|
+
misses: number;
|
|
37
|
+
} | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function audit(directory: string, skillsDir?: string, options?: AuditOptions): Promise<AuditResult>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PatternMatch } from "./patterns";
|
|
2
|
+
export interface CategorySummary {
|
|
3
|
+
skillName: string;
|
|
4
|
+
category: string;
|
|
5
|
+
label: string;
|
|
6
|
+
matches: PatternMatch[];
|
|
7
|
+
concerns: number;
|
|
8
|
+
positives: number;
|
|
9
|
+
patterns: number;
|
|
10
|
+
critical: number;
|
|
11
|
+
serious: number;
|
|
12
|
+
moderate: number;
|
|
13
|
+
fileCount: number;
|
|
14
|
+
files: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function categorizeMatches(matches: PatternMatch[]): CategorySummary[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { audit, type AuditOptions, type AuditResult, } from "./audit";
|
|
2
|
+
export { analyzeFile } from "./analyze";
|
|
3
|
+
export { astTsxAvailable, AST_TSX_RULES } from "./engines/ast-tsx";
|
|
4
|
+
export { refineSwift } from "./engines/swift-structural";
|
|
5
|
+
export { detectPatterns, severityFor, ruleCatalog, getRuleById, higCitation, fixGuidance, RULE_COUNT, HIG_SNAPSHOT_DATE, type PatternMatch, type Severity, type Engine, type RuleMeta, } from "./patterns";
|
|
6
|
+
export { scanProject, globToRegExp, type Framework, type ScanResult, type ScannedFile, } from "./scanner";
|
|
7
|
+
export { loadConfig, parseConfig, applyConfig, CONFIG_FILENAME, type HigDoctorConfig, type LoadedConfig, type RuleSetting, type ConfigOverride, } from "./config";
|
|
8
|
+
export { categorizeMatches, type CategorySummary, } from "./categorizer";
|
|
9
|
+
export { generateAuditMarkdown, loadSkillContent, } from "./audit-generator";
|
|
10
|
+
export { createBaseline, applyBaseline, loadBaseline, parseBaseline, writeBaseline, baselineKey, BASELINE_FILENAME, type Baseline, type BaselineApplication, } from "./baseline";
|
|
11
|
+
export { ScanCache, CACHE_FILENAME } from "./cache";
|
|
12
|
+
export { toSarif, type SarifOptions, } from "./sarif";
|
|
13
|
+
export { suggestFix, applyFixes, isFixable, type SuggestedFix, type FixApplication, } from "./fixes";
|
|
14
|
+
export { runBenchmark, BENCHMARK_CASES, type BenchmarkCase, type BenchmarkReport, type RuleScore, } from "./benchmark";
|