Fix linter errors; use custom check for print statements because flake8-print is not working anymore

This commit is contained in:
Sumner Evans
2020-05-08 12:38:16 -06:00
parent db358d8f8d
commit 00b96c9bd4
5 changed files with 34 additions and 19 deletions

View File

@@ -6,8 +6,17 @@ from pathlib import Path
from termcolor import cprint
todo_re = re.compile(r"#\s*TODO:?\s*")
accounted_for_todo = re.compile(r"#\s*TODO:?\s*\((#\d+)\)")
todo_re = re.compile(r"\s*#\s*TODO:?\s*")
accounted_for_todo = re.compile(r"\s*#\s*TODO:?\s*\((#\d+)\)")
print_re = re.compile(r"\s+print\(.*\)")
def noqa_re(error_id: str = ""):
return re.compile(rf"#\s*noqa(:\s*{error_id})?\s*\n$")
def eprint(*strings):
cprint(" ".join(strings), "red", end="", attrs=["bold"])
def check_file(path: Path) -> bool:
@@ -16,8 +25,12 @@ def check_file(path: Path) -> bool:
valid = True
for i, line in enumerate(file, start=1):
if todo_re.search(line) and not accounted_for_todo.search(line):
cprint(f"{i}: {line}", "red", end="", attrs=["bold"])
if todo_re.match(line) and not accounted_for_todo.match(line):
eprint(f"{i}: {line}")
valid = False
if print_re.search(line) and not noqa_re("T001").search(line):
eprint(f"{i}: {line}")
valid = False
file.close()