Skip to content

Commit 26a327d

Browse files
authored
feat(action): add suggestion column to PR comment table (#33)
When validation fails, the PR comment now includes a Suggestion column that shows recommended fixes from the style checker. This helps developers quickly understand what corrections to make.
1 parent 26815e4 commit 26a327d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/comment-formatter.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { ValidatorOutput, ValidationResult } from './types';
1+
import { ValidatorOutput, ValidationResult, StyleViolation } from './types';
22

33
const MAX_CONTENT_LENGTH = 50;
44
const MAX_ISSUES_PER_FILE = 10;
55
const MAX_FILES = 10;
6+
const MAX_SUGGESTION_LENGTH = 100;
67

78
function truncate(str: string, maxLength: number): string {
89
if (str.length <= maxLength) return str;
@@ -27,6 +28,22 @@ function groupByFile(results: ValidationResult[]): Map<string, ValidationResult[
2728
return grouped;
2829
}
2930

31+
function formatSuggestion(details?: StyleViolation[]): string {
32+
if (!details || details.length === 0) {
33+
return '-';
34+
}
35+
36+
const suggestions = details
37+
.filter(d => d.suggestion)
38+
.map(d => escapeHtml(truncate(d.suggestion!, MAX_SUGGESTION_LENGTH)));
39+
40+
if (suggestions.length === 0) {
41+
return '-';
42+
}
43+
44+
return suggestions.join('; ');
45+
}
46+
3047
export function formatPRComment(output: ValidatorOutput): string {
3148
const { results, summary } = output;
3249
const icon = summary.pass ? '✅' : '❌';
@@ -61,20 +78,21 @@ export function formatPRComment(output: ValidatorOutput): string {
6178
comment += `<summary><code>${file}</code> (${issueCount} issue${issueCount > 1 ? 's' : ''})</summary>\n\n`;
6279

6380
// Table header
64-
comment += `| Line | Content | Issue |\n`;
65-
comment += `|------|---------|-------|\n`;
81+
comment += `| Line | Content | Issue | Suggestion |\n`;
82+
comment += `|------|---------|-------|------------|\n`;
6683

6784
// Table rows
6885
const displayResults = fileResults.slice(0, MAX_ISSUES_PER_FILE);
6986
for (const result of displayResults) {
7087
const content = escapeHtml(truncate(result.content, MAX_CONTENT_LENGTH));
7188
const message = escapeHtml(result.message);
72-
comment += `| ${result.line} | \`${content}\` | ${message} |\n`;
89+
const suggestion = formatSuggestion(result.details);
90+
comment += `| ${result.line} | \`${content}\` | ${message} | ${suggestion} |\n`;
7391
}
7492

7593
if (fileResults.length > MAX_ISSUES_PER_FILE) {
7694
const remaining = fileResults.length - MAX_ISSUES_PER_FILE;
77-
comment += `| ... | *${remaining} more* | |\n`;
95+
comment += `| ... | *${remaining} more* | | |\n`;
7896
}
7997

8098
comment += `\n</details>\n\n`;

0 commit comments

Comments
 (0)