uiaudit.js 1.0.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.
Files changed (52) hide show
  1. package/dist/auditor.d.ts +11 -0
  2. package/dist/auditor.d.ts.map +1 -0
  3. package/dist/auditor.js +70 -0
  4. package/dist/auditor.js.map +1 -0
  5. package/dist/auditors/accessibility.d.ts +8 -0
  6. package/dist/auditors/accessibility.d.ts.map +1 -0
  7. package/dist/auditors/accessibility.js +1769 -0
  8. package/dist/auditors/accessibility.js.map +1 -0
  9. package/dist/auditors/performance.d.ts +8 -0
  10. package/dist/auditors/performance.d.ts.map +1 -0
  11. package/dist/auditors/performance.js +168 -0
  12. package/dist/auditors/performance.js.map +1 -0
  13. package/dist/auditors/seo.d.ts +8 -0
  14. package/dist/auditors/seo.d.ts.map +1 -0
  15. package/dist/auditors/seo.js +171 -0
  16. package/dist/auditors/seo.js.map +1 -0
  17. package/dist/cli.d.ts +10 -0
  18. package/dist/cli.d.ts.map +1 -0
  19. package/dist/cli.js +115 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/index.d.ts +13 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +12 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/parser/index.d.ts +18 -0
  26. package/dist/parser/index.d.ts.map +1 -0
  27. package/dist/parser/index.js +87 -0
  28. package/dist/parser/index.js.map +1 -0
  29. package/dist/parser/traverse.d.ts +10 -0
  30. package/dist/parser/traverse.d.ts.map +1 -0
  31. package/dist/parser/traverse.js +13 -0
  32. package/dist/parser/traverse.js.map +1 -0
  33. package/dist/reporter/terminal.d.ts +3 -0
  34. package/dist/reporter/terminal.d.ts.map +1 -0
  35. package/dist/reporter/terminal.js +200 -0
  36. package/dist/reporter/terminal.js.map +1 -0
  37. package/dist/types.d.ts +38 -0
  38. package/dist/types.d.ts.map +1 -0
  39. package/dist/types.js +3 -0
  40. package/dist/types.js.map +1 -0
  41. package/package.json +39 -0
  42. package/src/auditor.ts +100 -0
  43. package/src/auditors/accessibility.ts +2125 -0
  44. package/src/auditors/performance.ts +212 -0
  45. package/src/auditors/seo.ts +212 -0
  46. package/src/cli.ts +162 -0
  47. package/src/index.ts +22 -0
  48. package/src/parser/index.ts +106 -0
  49. package/src/parser/traverse.ts +14 -0
  50. package/src/reporter/terminal.ts +247 -0
  51. package/src/types.ts +51 -0
  52. package/tsconfig.json +47 -0
package/src/auditor.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { collectFiles, parseFile, type ParsedFile } from './parser/index.js';
2
+ import { auditPerformance } from './auditors/performance.js';
3
+ import { auditSEO } from './auditors/seo.js';
4
+ import { auditAccessibility } from './auditors/accessibility.js';
5
+ import type {
6
+ AuditCategory,
7
+ AuditOptions,
8
+ AuditReport,
9
+ AuditResult,
10
+ Issue,
11
+ IssueImpact,
12
+ } from './types.js';
13
+
14
+ // ─── Scoring constants ────────────────────────────────────────────────────────
15
+ // Score starts at 100 and deducts per issue based on impact.
16
+ // These numbers are intentionally asymmetric: a single critical issue should
17
+ // fail a CI gate. Tweak here when adding more checks.
18
+
19
+ const SCORE_DEDUCTIONS: Record<IssueImpact, number> = {
20
+ critical: 20,
21
+ major: 10,
22
+ minor: 5,
23
+ };
24
+
25
+ // ─── Public API ───────────────────────────────────────────────────────────────
26
+
27
+ /**
28
+ * The single entry point for the entire audit engine.
29
+ * Called by both the CLI (src/cli.ts) and the future VS Code extension (src/index.ts).
30
+ *
31
+ * @param target A file path or directory path to audit.
32
+ * @param options Which categories to run and any other options.
33
+ * @returns A complete AuditReport with scores, issues, and fix suggestions.
34
+ */
35
+ export function runAudit(target: string, options: AuditOptions): AuditReport {
36
+ // ── Step 1: Collect and parse files ──────────────────────────────────────
37
+ const filePaths = collectFiles(target);
38
+
39
+ if (filePaths.length === 0) {
40
+ throw new Error(
41
+ `No supported files found at "${target}".\n` +
42
+ `UIAudit supports: .tsx, .ts, .jsx, .js\n` +
43
+ `Make sure the path exists and is not inside node_modules.`
44
+ );
45
+ }
46
+
47
+ const parsedFiles: ParsedFile[] = filePaths
48
+ .map(parseFile)
49
+ .filter((f): f is ParsedFile => f !== null);
50
+
51
+ // ── Step 2: Run each requested auditor ───────────────────────────────────
52
+ const RUNNERS: Record<AuditCategory, (files: ParsedFile[]) => Issue[]> = {
53
+ performance: auditPerformance,
54
+ seo: auditSEO,
55
+ accessibility: auditAccessibility,
56
+ };
57
+
58
+ const results: Partial<Record<AuditCategory, AuditResult>> = {};
59
+
60
+ for (const category of options.types) {
61
+ const issues = RUNNERS[category](parsedFiles);
62
+ results[category] = buildResult(category, issues);
63
+ }
64
+
65
+ // ── Step 3: Compute overall score ────────────────────────────────────────
66
+ const categoryScores = Object.values(results).map((r) => r.score);
67
+ const overallScore =
68
+ categoryScores.length === 0
69
+ ? 100
70
+ : Math.round(
71
+ categoryScores.reduce((sum, s) => sum + s, 0) / categoryScores.length
72
+ );
73
+
74
+ return {
75
+ target,
76
+ timestamp: new Date().toISOString(),
77
+ overallScore,
78
+ totalFiles: parsedFiles.length,
79
+ results,
80
+ };
81
+ }
82
+
83
+ // ─── Private helpers ──────────────────────────────────────────────────────────
84
+
85
+ function buildResult(category: AuditCategory, issues: Issue[]): AuditResult {
86
+ const counts = {
87
+ critical: issues.filter((i) => i.impact === 'critical').length,
88
+ major: issues.filter((i) => i.impact === 'major').length,
89
+ minor: issues.filter((i) => i.impact === 'minor').length,
90
+ total: issues.length,
91
+ };
92
+
93
+ const deduction = issues.reduce(
94
+ (sum, issue) => sum + SCORE_DEDUCTIONS[issue.impact],
95
+ 0
96
+ );
97
+ const score = Math.max(0, Math.min(100, 100 - deduction));
98
+
99
+ return { category, score, issues, counts };
100
+ }