Skip to content

Commit e50d665

Browse files
committed
ci: Let's break everything by adding typo annotations
1 parent 8f7d180 commit e50d665

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
6161
- name: Lint codebase with flake8
6262
run: |
63-
typos --format sarif
63+
typos --format json | python scripts/typos_json_to_gha.py
6464
6565
actionlint:
6666
name: "Lint Github actions YAML files"

scripts/typos_json_to_gha.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import sys
3+
from string import Template
4+
5+
6+
def main():
7+
# Standard Github message template for CI annotations
8+
message_template = Template(
9+
'::error file=$path,line=$line_num,col=$byte_offset,endcol=$end_col,'
10+
'title=$type::`$typo` should be $suggestions'
11+
)
12+
13+
for line in sys.stdin:
14+
# Grab the JSON data coming from typos from stdin
15+
data = json.loads(line.rstrip())
16+
17+
# Calculate the end column and format the correction
18+
end_col = data['byte_offset'] + len(data['typo'])
19+
suggestions = ', '.join(data['corrections'])
20+
21+
# Print the templated message to stdout
22+
print(message_template.safe_substitute(
23+
data, end_col=end_col, suggestions=suggestions
24+
))
25+
26+
27+
if __name__ == '__main__':
28+
exit(main())

0 commit comments

Comments
 (0)