forked from jordemort/action-pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyright_to_rdjson.py
executable file
·43 lines (35 loc) · 1.28 KB
/
pyright_to_rdjson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
import sys
from typing import Any, Dict, TextIO
def pyright_to_rdjson(jsonin: TextIO):
pyright = json.load(jsonin)
if "generalDiagnostics" not in pyright:
raise RuntimeError("This doesn't look like pyright json")
rdjson: Dict[str, Any] = {
"source": {"name": "pyright", "url": "https://github.com/Microsoft/pyright"},
"severity": "WARNING",
"diagnostics": [],
}
for d in pyright["generalDiagnostics"]:
rdjson["diagnostics"].append(
{
"message": f"{d['message']} ({d.get('rule', '<no-rule>')})",
"severity": d["severity"].upper(),
"location": {
"path": d["file"],
"range": {
"start": {
"line": d["range"]["start"]["line"],
"column": d["range"]["start"]["character"],
},
"end": {
"line": d["range"]["end"]["line"],
"column": d["range"]["end"]["character"],
},
},
},
}
)
return json.dumps(rdjson)
if __name__ == "__main__":
print(pyright_to_rdjson(sys.stdin))