Skip to content

Commit

Permalink
feat: Add ruleId to Markdown format output
Browse files Browse the repository at this point in the history
  • Loading branch information
maxreichmann committed Dec 3, 2024
1 parent d34e765 commit ec8af44
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
11 changes: 6 additions & 5 deletions src/formatter/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class Markdown {
// Add the file path as a section header
findings += `### ${filePath}\n\n`;
if (showDetails === true) {
findings += `| Severity | Line | Message | Details |\n`;
findings += `|----------|------|---------|---------|\n`;
findings += `| Severity | Rule | Location | Message | Details |\n`;
findings += `|----------|------|----------|---------|---------|\n`;
} else {
findings += `| Severity | Line | Message |\n`;
findings += `|----------|------|---------|\n`;
findings += `| Severity | Rule | Location | Message |\n`;
findings += `|----------|------|----------|---------|\n`;
}

// Sort messages by severity (sorting order: fatal-errors, errors, warnings)
Expand All @@ -50,14 +50,15 @@ export class Markdown {
messages.forEach((msg) => {
const severity = this.formatSeverity(msg.severity, msg.fatal);
const location = this.formatLocation(msg.line, msg.column);
const rule = msg.ruleId ?? "n/a";
let details;
if (showDetails) {
details = ` ${this.formatMessageDetails(msg)} |`;
} else {
details = "";
}

findings += `| ${severity} | \`${location}\` | ${msg.message} |${details}\n`;
findings += `| ${severity} | ${rule} | \`${location}\` | ${msg.message} |${details}\n`;
});

findings += "\n";
Expand Down
44 changes: 22 additions & 22 deletions test/lib/formatter/snapshots/markdown.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ Generated by [AVA](https://avajs.dev).
## Findings␊
### webapp/Component.js␊
| Severity | Line | Message |␊
|----------|------|---------|␊
| Error | \`1:1\` | Error message |␊
| Warning | \`2:2\` | Warning message |␊
| Severity | Rule | Location | Message |␊
|----------|------|----------|---------|␊
| Error | rule1 | \`1:1\` | Error message |␊
| Warning | rule2 | \`2:2\` | Warning message |␊
### webapp/Main.controller.js␊
| Severity | Line | Message |␊
|----------|------|---------|␊
| Fatal Error | \`3:6\` | Another error message |␊
| Fatal Error | \`12:3\` | Another error message |␊
| Error | \`11:2\` | Another error message |␊
| Error | \`11:3\` | Another error message |␊
| Warning | \`12:3\` | Another error message |␊
| Severity | Rule | Location | Message |␊
|----------|------|----------|---------|␊
| Fatal Error | rule3 | \`3:6\` | Another error message |␊
| Fatal Error | rule3 | \`12:3\` | Another error message |␊
| Error | rule3 | \`11:2\` | Another error message |␊
| Error | rule3 | \`11:3\` | Another error message |␊
| Warning | rule3 | \`12:3\` | Another error message |␊
**Note:** Use \`ui5lint --details\` to show more information about the findings.␊
`
Expand All @@ -48,20 +48,20 @@ Generated by [AVA](https://avajs.dev).
## Findings␊
### webapp/Component.js␊
| Severity | Line | Message | Details |␊
|----------|------|---------|---------|␊
| Error | \`1:1\` | Error message | Message details |␊
| Warning | \`2:2\` | Warning message | Message details |␊
| Severity | Rule | Location | Message | Details |␊
|----------|------|----------|---------|---------|␊
| Error | rule1 | \`1:1\` | Error message | Message details |␊
| Warning | rule2 | \`2:2\` | Warning message | Message details |␊
### webapp/Main.controller.js␊
| Severity | Line | Message | Details |␊
|----------|------|---------|---------|␊
| Fatal Error | \`3:6\` | Another error message | Message details |␊
| Fatal Error | \`12:3\` | Another error message | Message details |␊
| Error | \`11:2\` | Another error message | Message details |␊
| Error | \`11:3\` | Another error message | Message details |␊
| Warning | \`12:3\` | Another error message | Message details |␊
| Severity | Rule | Location | Message | Details |␊
|----------|------|----------|---------|---------|␊
| Fatal Error | rule3 | \`3:6\` | Another error message | Message details |␊
| Fatal Error | rule3 | \`12:3\` | Another error message | Message details |␊
| Error | rule3 | \`11:2\` | Another error message | Message details |␊
| Error | rule3 | \`11:3\` | Another error message | Message details |␊
| Warning | rule3 | \`12:3\` | Another error message | Message details |␊
`

Expand Down
Binary file modified test/lib/formatter/snapshots/markdown.ts.snap
Binary file not shown.

0 comments on commit ec8af44

Please sign in to comment.