Skip to content

Commit ffa435f

Browse files
authored
Merge branch 'main' into doc/known-issues-design
2 parents 137b20d + 30274eb commit ffa435f

File tree

10 files changed

+354
-184
lines changed

10 files changed

+354
-184
lines changed

.github/workflows/checks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ jobs:
6868
uses: actions/[email protected]
6969
with:
7070
name: lint-python${{ matrix.python-version }}
71-
path: .lint.txt
71+
path: |
72+
.lint.txt
73+
.lint.json
7274
include-hidden-files: true
7375

7476
Type-Check:

.github/workflows/report.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ jobs:
3131
working-directory: ./artifacts
3232
run: |
3333
poetry run coverage combine --keep coverage-python3.9*/.coverage
34+
# Errors during copying are ignored because they are checked in the next step
3435
cp .coverage ../ || true
3536
cp lint-python3.9/.lint.txt ../ || true
37+
cp lint-python3.9/.lint.json ../ || true
3638
cp security-python3.9/.security.json ../ || true
3739
3840
- name: Validate Artifacts
@@ -53,6 +55,5 @@ jobs:
5355
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
5456
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
5557
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
56-
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY
57-
cat .lint.txt >> $GITHUB_STEP_SUMMARY
58+
poetry run tbx lint pretty-print >> $GITHUB_STEP_SUMMARY
5859
poetry run tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY

doc/changes/unreleased.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
## ✨ Added
4+
5+
* added tbx task for markdown formating of .lint.json
6+
37
## 🐞 Fixed
48
* Fixed an issue in the CI workflow that caused it to be executed twice on the initial push of a PR if the PR branch was on the repo itself.
59

exasol/toolbox/nox/_artifacts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def check_artifacts(session: Session) -> None:
2323
error = False
2424
if msg := _validate_lint_txt(Path(PROJECT_CONFIG.root, ".lint.txt")):
2525
print(f"error in [.lint.txt]: {msg}")
26+
if msg := _validate_lint_json(Path(PROJECT_CONFIG.root, ".lint.json")):
27+
print(f"error in [.lint.json]: {msg}")
2628
if msg := _validate_security_json(Path(PROJECT_CONFIG.root, ".security.json")):
2729
print(f"error in [.security.json]: {msg}")
2830
error = True

exasol/toolbox/templates/github/workflows/checks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ jobs:
7474
uses: actions/[email protected]
7575
with:
7676
name: lint-python${{ matrix.python-version }}
77-
path: .lint.txt
77+
path: |
78+
.lint.txt
79+
.lint.json
7880
include-hidden-files: true
7981

8082
Type-Check:

exasol/toolbox/templates/github/workflows/report.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ jobs:
3131
working-directory: ./artifacts
3232
run: |
3333
poetry run coverage combine --keep coverage-python3.9*/.coverage
34-
cp .coverage ../
35-
cp lint-python3.9/.lint.txt ../
36-
cp security-python3.9/.security.json ../
34+
# Errors during copying are ignored because they are checked in the next step
35+
cp .coverage ../ || true
36+
cp lint-python3.9/.lint.txt ../ || true
37+
cp lint-python3.9/.lint.txt ../ || true
38+
cp security-python3.9/.security.json ../ || true
39+
40+
- name: Validate Artifacts
41+
run: poetry run nox -s artifacts:validate
3742

3843
- name: Generate Report
3944
run: poetry run nox -s project:report -- -- --format json | tee metrics.json
@@ -50,6 +55,5 @@ jobs:
5055
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
5156
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
5257
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
53-
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY
54-
cat .lint.txt >> $GITHUB_STEP_SUMMARY
58+
poetry run tbx security pretty-print >> $GITHUB_STEP_SUMMARY
5559
poetry run tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY

exasol/toolbox/tools/lint.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import json
2+
from collections.abc import Iterable
3+
from dataclasses import dataclass
4+
from inspect import cleandoc
5+
from pathlib import Path
6+
7+
import typer
8+
9+
CLI = typer.Typer()
10+
11+
12+
@dataclass(frozen=True)
13+
class Finding:
14+
type: str
15+
module: str
16+
obj: str
17+
line: int
18+
column: int
19+
endLine: int
20+
endColumn: int
21+
path: str
22+
symbol: str
23+
message: str
24+
message_id: str
25+
26+
27+
def lint_issue_from_json(data: str) -> Iterable[Finding]:
28+
issues = json.loads(data)
29+
for issue in issues:
30+
yield Finding(
31+
type=issue["type"],
32+
module=issue["module"],
33+
obj=issue["obj"],
34+
line=issue["line"],
35+
column=issue["column"],
36+
endLine=issue["endLine"],
37+
endColumn=issue["endColumn"],
38+
path=issue["path"],
39+
symbol=issue["symbol"],
40+
message=issue["message"],
41+
message_id=issue["message-id"],
42+
)
43+
44+
45+
def lint_issue_to_markdown(lint_issues: Iterable[Finding]) -> str:
46+
def _header() -> str:
47+
header = "# Static Code Analysis\n\n"
48+
header += "|File|line/<br>column|id|message|\n"
49+
header += "|---|:-:|:-:|---|\n"
50+
return header
51+
52+
def _rows(findings: Iterable[Finding]) -> str:
53+
rows = ""
54+
for finding in findings:
55+
rows += f"|{finding.path}"
56+
rows += f"|line: {finding.line}/<br>column: {finding.column}"
57+
rows += f"|{finding.message_id}"
58+
rows += f"|{finding.message}|\n"
59+
return rows
60+
61+
template = cleandoc(
62+
"""
63+
{header}{rows}
64+
"""
65+
)
66+
lint_issues = sorted(lint_issues, key=lambda i: (i.path, i.message_id, i.line))
67+
return template.format(header=_header(), rows=_rows(lint_issues))
68+
69+
70+
@CLI.command(name="pretty-print")
71+
def lint_json_to_markdown(
72+
path: Path = typer.Argument(default=Path(".lint.json"), help="path to lint.json"),
73+
) -> None:
74+
"""converts the lint json to a Markdown table"""
75+
issues = lint_issue_from_json(path.read_text())
76+
print(lint_issue_to_markdown(issues))
77+
78+
79+
if __name__ == "__main__":
80+
CLI()

exasol/toolbox/tools/tbx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from exasol.toolbox.tools import (
44
issue,
5+
lint,
56
security,
67
workflow,
78
)
@@ -10,6 +11,7 @@
1011
CLI.add_typer(workflow.CLI, name="workflow", help="Manage github workflows")
1112
CLI.add_typer(security.CLI, name="security", help="Security related helpers")
1213
CLI.add_typer(issue.CLI, name="issue", help="Manage issue templates")
14+
CLI.add_typer(lint.CLI, name="lint", help="linting related helpers")
1315

1416
if __name__ == "__main__":
1517
CLI()

0 commit comments

Comments
 (0)