Fix AI suggestions, improve reporter UI, and fix RuleEngine compatibility issues

This commit is contained in:
Enes Yakıştır
2026-05-13 13:09:01 +03:00
parent 3a19c1c534
commit 09f33650ec
3 changed files with 37 additions and 17 deletions
+6 -12
View File
@@ -38,21 +38,15 @@ Error: {$violation->message}
Severity: {$violation->severity->value} Severity: {$violation->severity->value}
Standard: {$violation->standard->value} Standard: {$violation->standard->value}
Please provide ONLY the fixed version of the HTML snippet. Please provide a short explanation of the fix (in Turkish) and the fixed version of the HTML snippet.
Do not explain, do not add markdown code blocks, just return the corrected HTML. Use the following EXACT format:
If the error is about missing 'alt' text, add a meaningful alt text based on context. EXPLANATION: [A short explanation of what you fixed and why]
If it's about ARIA roles, add the correct ones. FIX: [Only the corrected HTML snippet]
PROMPT; PROMPT;
try { try {
// Stable model: gemini-1.5-flash $result = $this->client->generativeModel('gemini-2.5-flash')->generateContent($prompt);
$result = $this->client->generativeModel('gemini-1.5-flash')->generateContent($prompt); return trim($result->text());
$suggestion = trim($result->text());
// Clean up if AI included markdown blocks anyway
$suggestion = preg_replace('/^```html\s*|\s*```$/i', '', $suggestion);
return $suggestion;
} catch (\Throwable $e) { } catch (\Throwable $e) {
return "AI Düzeltme Hatası: " . $e->getMessage(); return "AI Düzeltme Hatası: " . $e->getMessage();
} }
+11 -3
View File
@@ -79,9 +79,17 @@ class FixCommand extends Command
} }
// Get AI Suggestion // Get AI Suggestion
$suggestion = $fixer->suggestFix($violation); $rawSuggestion = $fixer->suggestFix($violation);
if (!$suggestion) { $suggestion = $rawSuggestion;
$io->writeln("<fg=red>Skipped (AI could not generate fix)</>"); if ($rawSuggestion && str_contains($rawSuggestion, 'FIX:')) {
preg_match('/FIX:(.*)/s', $rawSuggestion, $matches);
$suggestion = trim($matches[1] ?? $rawSuggestion);
// Clean up potential markdown
$suggestion = preg_replace('/^```html\s*|\s*```$/i', '', $suggestion);
}
if (!$suggestion || ($suggestion === $rawSuggestion && str_contains($suggestion, 'EXPLANATION:'))) {
$io->writeln("<fg=red>Skipped (AI could not generate a clean fix)</>");
continue; continue;
} }
+20 -2
View File
@@ -17,12 +17,29 @@ class HtmlDashboardReporter
$rows = ''; $rows = '';
foreach ($violations as $v) { foreach ($violations as $v) {
$severityClass = strtolower($v->severity->value); $severityClass = strtolower($v->severity->value);
$aiSuggestion = $v->fixSuggestion;
$explanation = '';
$fixedCode = '';
if ($aiSuggestion && str_contains($aiSuggestion, 'FIX:')) {
preg_match('/EXPLANATION:(.*)FIX:(.*)/s', $aiSuggestion, $matches);
$explanation = trim($matches[1] ?? '');
$fixedCode = trim($matches[2] ?? '');
// Clean up potential markdown
$fixedCode = preg_replace('/^```html\s*|\s*```$/i', '', $fixedCode);
} else {
$fixedCode = $aiSuggestion;
}
$rows .= " $rows .= "
<tr class='severity-{$severityClass}'> <tr class='severity-{$severityClass}'>
<td><span class='badge'>{$v->ruleId}</span></td> <td><span class='badge'>{$v->ruleId}</span></td>
<td>{$v->message}</td> <td>{$v->message}</td>
<td><pre><code>" . htmlspecialchars($v->htmlSnippet) . "</code></pre></td> <td><pre><code>" . htmlspecialchars($v->htmlSnippet) . "</code></pre></td>
<td>" . ($v->fixSuggestion ? "<pre class='ai-fix'><code>" . htmlspecialchars($v->fixSuggestion) . "</code></pre>" : "<span class='text-muted'>Manual fix required</span>") . "</td> <td>
" . ($explanation ? "<div class='ai-explanation'><strong>Öneri:</strong> {$explanation}</div>" : "") . "
" . ($fixedCode ? "<pre class='ai-fix'><code>" . htmlspecialchars($fixedCode) . "</code></pre>" : "<span class='text-muted'>Manual fix required</span>") . "
</td>
<td>" . ($v->location ? "{$v->location['file']}:{$v->location['line']}" : 'N/A') . "</td> <td>" . ($v->location ? "{$v->location['file']}:{$v->location['line']}" : 'N/A') . "</td>
</tr>"; </tr>";
} }
@@ -44,7 +61,8 @@ class HtmlDashboardReporter
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; } th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; }
th { background: #f8f9fa; } th { background: #f8f9fa; }
pre { background: #272822; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto; font-size: 12px; } pre { background: #272822; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto; font-size: 12px; }
.ai-fix { border-left: 4px solid #2ecc71; background: #1e1e1e; } .ai-explanation { margin-bottom: 8px; font-size: 13px; color: #27ae60; line-height: 1.4; }
.ai-fix { border-left: 4px solid #2ecc71; background: #1e1e1e; margin-top: 5px; }
.badge { background: #34495e; color: white; padding: 4px 8px; border-radius: 4px; font-size: 11px; } .badge { background: #34495e; color: white; padding: 4px 8px; border-radius: 4px; font-size: 11px; }
.severity-error { background: #fff5f5; } .severity-error { background: #fff5f5; }
.text-muted { color: #95a5a6; font-size: 0.9em; font-style: italic; } .text-muted { color: #95a5a6; font-size: 0.9em; font-style: italic; }