Skip to content

Commit d297ade

Browse files
author
Dev Optimizer Bot
committed
fix: Handle undefined suggestedFix in reporter
- Added optional chaining (?.) for suggestedFix access - Prevents TypeError when finding has no suggestedFix - Fixes crash on self-analysis
1 parent 3468724 commit d297ade

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/commands/analyze.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export async function analyzeCommand(options: AnalyzeOptions): Promise<void> {
207207

208208
// Categorize findings
209209
const topFindings = allFindings.slice(0, options.top);
210-
const quickWins = allFindings.filter(f => f.suggestedFix.autoFixable && f.confidence === 'high');
210+
const quickWins = allFindings.filter(f => f.suggestedFix?.autoFixable && f.confidence === 'high');
211211
const manualReview = allFindings.filter(f => !f.autoFixSafe || f.confidence !== 'high');
212212

213213
// Calculate percentage improvement

src/reporters/ConsoleReporter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class ConsoleReporter {
6868

6969
// Quick Wins (unique, from otherFindings)
7070
const quickWins = otherFindings
71-
.filter(f => f.autoFixSafe || f.suggestedFix.autoFixable)
71+
.filter(f => f.autoFixSafe || f.suggestedFix?.autoFixable)
7272
.slice(0, 5);
7373

7474
if (quickWins.length > 0) {
@@ -173,9 +173,9 @@ export class ConsoleReporter {
173173
}
174174
}
175175

176-
if (finding.suggestedFix.autoFixable) {
176+
if (finding.suggestedFix?.autoFixable) {
177177
lines.push(chalk.green(` Fix: ${finding.suggestedFix.description} (auto-fixable)`));
178-
} else {
178+
} else if (finding.suggestedFix) {
179179
lines.push(chalk.yellow(` Suggestion: ${finding.suggestedFix.description}`));
180180
}
181181

@@ -187,7 +187,7 @@ export class ConsoleReporter {
187187

188188
for (const finding of findings) {
189189
const severityColor = this.getSeverityColor(finding.severity);
190-
const autoFix = finding.suggestedFix.autoFixable ? chalk.green(' ✅') : '';
190+
const autoFix = finding.suggestedFix?.autoFixable ? chalk.green(' ✅') : '';
191191
lines.push(` ${severityColor('●')} ${finding.title}${autoFix}`);
192192
}
193193

0 commit comments

Comments
 (0)