diff options
author | Ben Sima <ben@bsima.me> | 2020-07-25 15:39:57 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-07-25 15:39:57 -0700 |
commit | 22139c06244d224f543dc6c5c38e8f05cddc4b51 (patch) | |
tree | a6c2a69152a8507aa77677030e317851e7b757f2 | |
parent | e8b1ebd849a1312add580cf3492721670001ca30 (diff) |
lint: colors and check all changed files
-rwxr-xr-x | Biz/lint.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Biz/lint.py b/Biz/lint.py index d12431c..88720b3 100755 --- a/Biz/lint.py +++ b/Biz/lint.py @@ -7,6 +7,18 @@ import subprocess import sys +# pylint: disable=missing-class-docstring,too-few-public-methods +class Color: + HEAD = "\033[95m" + BLUE = "\033[94m" + GREEN = "\033[92m" + WARN = "\033[93m" + FAIL = "\033[91m" + BOLD = "\033[1m" + UNDER = "\033[4m" + END = "\033[0m" + + def run(cmd, file): "Exec a linter for a file." global ERRORS # pylint: disable=global-statement @@ -21,17 +33,23 @@ def run(cmd, file): if ret.returncode != 0: ERRORS += 1 # pylint: disable=undefined-variable msg = ret.stdout.decode("utf-8").strip() - print(f"lint error: {cmd} on {file}") + print(Color.WARN + f"lint error: {cmd}: {file}" + Color.END) if msg: print(msg) def changed_files(): "Return a list of changed files according to git." + merge_base = ( + subprocess.check_output(["git", "merge-base", "HEAD", "origin/master"]) + .decode("utf-8") + .strip() + ) return ( - subprocess.check_output(["git", "diff", "--cached", "--name-only"]) + subprocess.check_output(["git", "diff", "--name-only", merge_base]) .decode("utf-8") .strip() + .split() ) @@ -53,7 +71,7 @@ if __name__ == "__main__": ERRORS = 0 if "-h" in sys.argv: print(f"usage: {os.path.basename(__file__)} <files...>") - print("if no files given, lint files staged in git") + print("if no files given, lint changed files in this branch") sys.exit(0) elif len(sys.argv) == 1: FILES = group_files(changed_files(), [".hs", ".py"]) @@ -67,6 +85,4 @@ if __name__ == "__main__": print(f"lint: {py}") run("black", py) run("pylint", py) - run("black", __file__) - run("pylint", __file__) sys.exit(ERRORS) |