forked from alexpdp7/pyrde
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
28 lines (21 loc) · 791 Bytes
/
example.py
File metadata and controls
28 lines (21 loc) · 791 Bytes
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
import argparse
import pathlib
import sys
import pyrde
from pyrde import diagnostics
def main():
parser = argparse.ArgumentParser()
parser.add_argument("file", nargs="*", type=pathlib.Path)
pyrde.add_error_format_args(parser)
args = parser.parse_args()
db = pyrde.get_diagnostic_builder_from_args(args)
errors = False
for file in args.file:
content = file.read_text()
bad_lines = [(number, line) for number, line in enumerate(content.splitlines()) if "foo" in line]
for number, line in bad_lines:
db.add_diagnostic("Line '{line}' contains foo", {"line": line}, diagnostics.Severity.ERROR, file, number + 1, None, None, None, "BAD_LINE", None)
errors = True
db.finish()
if errors:
sys.exit(1)