diff options
author | Ben Sima <ben@bsima.me> | 2020-04-15 14:45:32 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-04-15 16:56:32 -0700 |
commit | cb77d0eb623c7a398ca86a632d0ea37ac385cc3d (patch) | |
tree | 1d0936b2a4ff8d335e6c0f6a3e4c8c4341af8bd3 | |
parent | 98734d2406ee559abf497cc95531980702f162ae (diff) |
Add lint script
-rwxr-xr-x | lint | 45 | ||||
-rwxr-xr-x | turnkey | 1 |
2 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,45 @@ +#!/usr/bin/env python +import os +import glob +import subprocess +import sys + + +def run(cmd, f): + global ERRORS + args = { + "ormolu": ["--mode", "check"], + "hlint": [], + "black": ["--quiet", "--check"], + "pylint": [], + } + ret = subprocess.run([cmd, *args[cmd], f], stdout=subprocess.PIPE) + if ret.returncode != 0: + ERRORS += 1 + msg = ret.stdout.decode("utf-8").strip() + print(f"lint error: {cmd} on {f}") + if msg: + print(msg) + + +def find_files(bizroot, extensions): + ret = {k: [] for k in extensions} + for root, dirs, files in os.walk(bizroot, topdown=True): + (dirs.remove(d) for d in dirs if d.startswith(("_", "."))) + for ext in extensions: + for f in files: + if f.endswith(ext): + ret[ext].append(os.path.join(root, f)) + return ret + + +if __name__ == "__main__": + ERRORS = 0 + files = find_files(os.getenv("BIZ_ROOT"), [".hs", ".py"]) + for hs in files[".hs"]: + run("ormolu", hs) + run("hlint", hs) + for py in files[".py"]: + run("black", py) + run("pylint", py) + sys.exit(ERRORS) @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -ex +lint stuff=( Biz.Cloud Biz.Dev |