Skip to content

Commit c0d5a5c

Browse files
authored
Align number columns of markdown tables in reports (#4835)
* Center number columns of markdown tables in reports * fix * use Style * changelog * [MegaLinter] Apply linters fixes --------- Co-authored-by: nvuillam <[email protected]>
1 parent b52216a commit c0d5a5c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
1111
- Core
1212
- Replace pychalk (not maintained for 7 years) by termcolor
1313
- Update make scripts so they also work on Windows
14+
- Align number columns of markdown tables in reports
1415

1516
- New linters
1617

megalinter/utils_reporter.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,25 @@
1414
ML_REPO_ISSUES_URL,
1515
OX_MARKDOWN_LINK,
1616
)
17-
from pytablewriter import MarkdownTableWriter
17+
from pytablewriter import Align, MarkdownTableWriter
18+
from pytablewriter.style import Style
1819
from redis import Redis
1920

2021

2122
def build_markdown_summary(reporter_self, action_run_url=""):
2223
table_header = ["Descriptor", "Linter", "Files", "Fixed", "Errors", "Warnings"]
24+
table_column_styles = [
25+
Style(align=Align.LEFT),
26+
Style(align=Align.LEFT),
27+
Style(align=Align.RIGHT),
28+
Style(align=Align.RIGHT),
29+
Style(align=Align.RIGHT),
30+
Style(align=Align.RIGHT),
31+
]
2332
if reporter_self.master.show_elapsed_time is True:
2433
table_header += ["Elapsed time"]
25-
table_data_raw = [table_header]
34+
table_column_styles += [Style(align=Align.RIGHT)]
35+
table_data_raw = []
2636
for linter in reporter_self.master.linters:
2737
if linter.is_active is True:
2838
status = (
@@ -82,7 +92,11 @@ def build_markdown_summary(reporter_self, action_run_url=""):
8292
table_data_raw += [table_line]
8393
# Build markdown table
8494
table_data_raw.pop(0)
85-
writer = MarkdownTableWriter(headers=table_header, value_matrix=table_data_raw)
95+
writer = MarkdownTableWriter(
96+
headers=table_header,
97+
column_styles=table_column_styles,
98+
value_matrix=table_data_raw,
99+
)
86100
table_content = str(writer)
87101
status = (
88102
"✅"

0 commit comments

Comments
 (0)