forked from idris-lang/Idris2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.py
executable file
·50 lines (39 loc) · 1.13 KB
/
lint.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
44
45
46
47
48
49
50
#!/usr/bin/env python3
#
# Lint Idris source files.
import os
import sys
def _lint_file(path):
ok = True
with open(path) as f:
for (line_no, line) in enumerate(f.readlines()):
line_without_newline = line.rstrip("\r\n")
if line_without_newline == line:
print(f"No trailing newline in {path}")
ok = False
continue
if line_without_newline.endswith(" "):
print(f"Trailing whitespace in {path}:{line_no}")
ok = False
continue
return ok
def main():
ok = True
count = 0
for (dirpath, dirnames, filenames) in os.walk("."):
for filename in filenames:
if not filename.endswith(".idr"):
continue
count += 1
assert dirpath.startswith("./")
full = f"{dirpath[2:]}/{filename}"
if not _lint_file(full):
ok = False
# Sanity check
assert count
if ok:
print(f"{count} .idr files are OK")
sys.exit(int(not ok))
if __name__ == "__main__":
main()
# vim: set ts=4 sw=4 et: