renderpilot 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 (34) hide show
  1. package/README.md +121 -0
  2. package/package.json +65 -0
  3. package/src/cli/commands/scan.js +83 -0
  4. package/src/cli/index.js +49 -0
  5. package/src/cli/options.js +18 -0
  6. package/src/config/ConfigLoader.js +102 -0
  7. package/src/config/DefaultConfig.js +33 -0
  8. package/src/index.js +34 -0
  9. package/src/parser/ASTUtils.js +241 -0
  10. package/src/parser/BabelParser.js +66 -0
  11. package/src/parser/ComponentDetector.js +53 -0
  12. package/src/reporters/HtmlReporter.js +42 -0
  13. package/src/reporters/JsonReporter.js +52 -0
  14. package/src/reporters/TerminalReporter.js +91 -0
  15. package/src/reporters/templates/report.html.js +655 -0
  16. package/src/rules/base/AbstractRule.js +136 -0
  17. package/src/rules/engine/RuleEngine.js +67 -0
  18. package/src/rules/implementations/R001_MissingKeyProp.js +97 -0
  19. package/src/rules/implementations/R002_InfiniteUseEffect.js +86 -0
  20. package/src/rules/implementations/R003_IncorrectDepsArray.js +112 -0
  21. package/src/rules/implementations/R004_LargeComponent.js +47 -0
  22. package/src/rules/implementations/R005_InlineCallback.js +58 -0
  23. package/src/rules/implementations/R006_HeavyRenderCalc.js +86 -0
  24. package/src/rules/implementations/R007_MemoCandidate.js +87 -0
  25. package/src/rules/implementations/R008_NestedComponent.js +65 -0
  26. package/src/rules/implementations/R009_UnusedState.js +62 -0
  27. package/src/rules/index.js +37 -0
  28. package/src/rules/registry/RuleRegistry.js +67 -0
  29. package/src/scanner/FileScanner.js +42 -0
  30. package/src/scanner/ProjectScanner.js +116 -0
  31. package/src/score/CategoryScorer.js +53 -0
  32. package/src/score/ScoreCalculator.js +97 -0
  33. package/src/score/ScoreWeights.js +33 -0
  34. package/src/types/index.js +176 -0
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @file types/index.js
3
+ * @description
4
+ * Central JSDoc type definitions for RenderPilot.
5
+ * All types used across the project are documented here.
6
+ * This file is never executed — it exists purely for editor
7
+ * IntelliSense and JSDoc annotation purposes.
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ // ─── Enumerations (as JSDoc unions) ──────────────────────────────────────────
13
+
14
+ /**
15
+ * Severity levels for rule violations.
16
+ * @typedef {'critical' | 'warning' | 'info'} Severity
17
+ */
18
+
19
+ /**
20
+ * Performance analysis categories.
21
+ * @typedef {'rendering' | 'hooks' | 'architecture' | 'maintainability'} Category
22
+ */
23
+
24
+ /**
25
+ * Impact level of a single violation.
26
+ * @typedef {'low' | 'medium' | 'high' | 'critical'} ImpactLevel
27
+ */
28
+
29
+ /**
30
+ * Letter grade for a performance score.
31
+ * @typedef {'A' | 'B' | 'C' | 'D' | 'F'} Grade
32
+ */
33
+
34
+ // ─── Impact Estimate ─────────────────────────────────────────────────────────
35
+
36
+ /**
37
+ * Estimated performance impact of a rule violation.
38
+ * @typedef {Object} ImpactEstimate
39
+ * @property {ImpactLevel} level - Categorical impact level
40
+ * @property {string} description - Human-readable impact description
41
+ * @property {string} [estimatedFpsGain] - Optional FPS improvement estimate
42
+ * @property {string} [estimatedRerenderReduction] - Optional rerender reduction estimate
43
+ */
44
+
45
+ // ─── Rule Violation ───────────────────────────────────────────────────────────
46
+
47
+ /**
48
+ * A single detected rule violation in a source file.
49
+ * This is the primary output unit produced by every rule.
50
+ * @typedef {Object} RuleViolation
51
+ * @property {string} ruleId - Unique rule identifier (e.g. "R001")
52
+ * @property {string} ruleName - Human-readable rule name
53
+ * @property {Severity} severity - Violation severity
54
+ * @property {Category} category - Performance category
55
+ * @property {string} filePath - Absolute file path
56
+ * @property {number} line - 1-indexed line number
57
+ * @property {number} column - 0-indexed column number
58
+ * @property {string} message - Human-readable violation message
59
+ * @property {string} suggestion - Actionable fix suggestion
60
+ * @property {ImpactEstimate} impact - Estimated performance impact
61
+ * @property {string} [codeSnippet] - Snippet of the violating code
62
+ * @property {string} [componentName] - Name of the component containing the violation
63
+ */
64
+
65
+ // ─── Rule Context ─────────────────────────────────────────────────────────────
66
+
67
+ /**
68
+ * Context object passed to every rule's detect() method.
69
+ * @typedef {Object} RuleContext
70
+ * @property {import('@babel/parser').ParseResult<import('@babel/types').File>} ast - Parsed Babel AST
71
+ * @property {string} filePath - Absolute path of the file being analyzed
72
+ * @property {string} fileContent - Raw source code of the file
73
+ * @property {string[]} lines - Source split by newline
74
+ * @property {ResolvedConfig} config - Resolved user configuration
75
+ */
76
+
77
+ // ─── Config Types ─────────────────────────────────────────────────────────────
78
+
79
+ /**
80
+ * Severity override map (ruleId → Severity)
81
+ * @typedef {Object.<string, Severity>} SeverityOverride
82
+ */
83
+
84
+ /**
85
+ * User-facing configuration object (renderpilot.config.js)
86
+ * @typedef {Object} UserConfig
87
+ * @property {string[]} [ignoreDirs] - Extra directories to ignore
88
+ * @property {number} [maxComponentLines] - Max component line count (default: 300)
89
+ * @property {SeverityOverride} [severityOverrides] - Per-rule severity overrides
90
+ * @property {string[]} [enabledRules] - Allowlist of rule IDs to run
91
+ * @property {string[]} [disabledRules] - Rule IDs to skip
92
+ * @property {string} [outputDir] - Output directory for reports (default: '.renderpilot')
93
+ */
94
+
95
+ /**
96
+ * Fully resolved configuration used internally (defaults merged with user config)
97
+ * @typedef {Object} ResolvedConfig
98
+ * @property {string[]} ignoreDirs - Directories to skip during file scanning
99
+ * @property {number} maxComponentLines - Maximum component lines threshold
100
+ * @property {SeverityOverride} severityOverrides - Effective severity per rule
101
+ * @property {Set<string>|null} enabledRules - Enabled rule IDs (null = all enabled)
102
+ * @property {Set<string>} disabledRules - Disabled rule IDs
103
+ * @property {string} outputDir - Report output directory
104
+ * @property {boolean} hasCustomConfig - Whether a custom config file was found
105
+ */
106
+
107
+ // ─── Scan Types ───────────────────────────────────────────────────────────────
108
+
109
+ /**
110
+ * Analysis result for a single source file.
111
+ * @typedef {Object} FileAnalysisResult
112
+ * @property {string} filePath - Absolute file path
113
+ * @property {string} relativePath - Relative file path from scan root
114
+ * @property {RuleViolation[]} violations - All violations in this file
115
+ * @property {number} analysisDurationMs - Time taken to analyze in ms
116
+ * @property {boolean} parsed - Whether parsing succeeded
117
+ * @property {string} [parseError] - Parse error message if failed
118
+ * @property {number} lineCount - Number of lines in the file
119
+ * @property {string[]} componentNames - Detected component names
120
+ */
121
+
122
+ /**
123
+ * Complete scan result across all files in the project.
124
+ * @typedef {Object} ScanResult
125
+ * @property {string} scanRoot - Root directory that was scanned
126
+ * @property {string} startedAt - ISO 8601 scan start timestamp
127
+ * @property {string} completedAt - ISO 8601 scan end timestamp
128
+ * @property {number} durationMs - Total scan duration in ms
129
+ * @property {FileAnalysisResult[]} files - All analyzed files
130
+ * @property {number} totalFiles - Total number of files scanned
131
+ * @property {number} parseErrors - Number of files that failed to parse
132
+ * @property {RuleViolation[]} allViolations - All violations (flattened)
133
+ * @property {number} totalViolations - Total violation count
134
+ * @property {{critical:number, warning:number, info:number}} violationsBySeverity
135
+ * @property {{rendering:number, hooks:number, architecture:number, maintainability:number}} violationsByCategory
136
+ * @property {Object.<string, number>} violationsByRule - Violation counts per rule ID
137
+ */
138
+
139
+ // ─── Score Types ──────────────────────────────────────────────────────────────
140
+
141
+ /**
142
+ * Score for a single performance category.
143
+ * @typedef {Object} CategoryScore
144
+ * @property {Category} category - The category being scored
145
+ * @property {number} score - Numeric score 0–100
146
+ * @property {Grade} grade - Letter grade
147
+ * @property {number} violations - Number of violations in this category
148
+ * @property {number} penaltyApplied - Total penalty applied
149
+ */
150
+
151
+ /**
152
+ * Complete performance score for the scanned project.
153
+ * @typedef {Object} PerformanceScore
154
+ * @property {number} overall - Overall score 0–100
155
+ * @property {Grade} grade - Overall letter grade
156
+ * @property {string} label - Human-readable label (e.g., "Excellent")
157
+ * @property {CategoryScore[]} categories - Scores per category
158
+ * @property {number} totalPenalty - Total penalty applied to overall score
159
+ * @property {{critical:number, warning:number, info:number}} penaltyBySeverity
160
+ * @property {number} estimatedImprovementOnCriticalFix - Score gain if critical issues fixed
161
+ * @property {number} estimatedImprovementOnAllFix - Score gain if all issues fixed
162
+ * @property {string} topRecommendation - Top actionable recommendation
163
+ */
164
+
165
+ // ─── Report Types ─────────────────────────────────────────────────────────────
166
+
167
+ /**
168
+ * Full report data passed to all reporters.
169
+ * @typedef {Object} ReportData
170
+ * @property {ScanResult} scan - Scan results
171
+ * @property {PerformanceScore} score - Performance score
172
+ * @property {string} version - RenderPilot version used
173
+ * @property {ResolvedConfig} config - Config that was used
174
+ */
175
+
176
+ module.exports = {};