Skip to content

Commit 0a05984

Browse files
committed
refactor: adjust rule details format in generated markdown report
Rather than generating one big table, with lots of wide columns, this generates one table per violation to be more extendable with new fields. It also ends up being more consistent with how the data is displayed in the CLI output. Signed-off-by: Dustin Popp <[email protected]>
1 parent b5ace72 commit 0a05984

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
/**
2-
* Copyright 2024 IBM Corporation.
2+
* Copyright 2024 - 2025 IBM Corporation.
33
* SPDX-License-Identifier: Apache2.0
44
*/
55

66
const MarkdownTable = require('../markdown-table');
77

8-
function getTable({ error, warning }) {
9-
const table = new MarkdownTable(
10-
'Rule',
11-
'Message',
12-
'Path',
13-
'Line',
14-
'Severity'
15-
);
8+
function getTables(violations) {
9+
let tableOutput = '';
10+
for (const severity of ['error', 'warning']) {
11+
for (const { message, path, rule, line } of violations[severity].results) {
12+
const table = new MarkdownTable('Rule', rule);
13+
table.addRow('Message', message);
14+
table.addRow('Path', path.join('.'));
15+
table.addRow('Line', line);
16+
table.addRow('Severity', severity);
1617

17-
error.results.forEach(({ message, path, rule, line }) => {
18-
table.addRow(rule, message, path.join('.'), line, 'error');
19-
});
18+
tableOutput += `${table.render()}\n\n`;
19+
}
20+
}
2021

21-
warning.results.forEach(({ message, path, rule, line }) => {
22-
table.addRow(rule, message, path.join('.'), line, 'warning');
23-
});
24-
25-
return table.render();
22+
// Remove the final newline characters from the string.
23+
return tableOutput.trim();
2624
}
2725

28-
module.exports = getTable;
26+
module.exports = getTables;

0 commit comments

Comments
 (0)