From cb77d0eb623c7a398ca86a632d0ea37ac385cc3d Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 15 Apr 2020 14:45:32 -0700 Subject: Add lint script --- lint | 45 +++++++++++++++++++++++++++++++++++++++++++++ turnkey | 1 + 2 files changed, 46 insertions(+) create mode 100755 lint diff --git a/lint b/lint new file mode 100755 index 0000000..a69b424 --- /dev/null +++ b/lint @@ -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) diff --git a/turnkey b/turnkey index 7b13332..5330ec4 100755 --- a/turnkey +++ b/turnkey @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -ex +lint stuff=( Biz.Cloud Biz.Dev -- cgit v1.2.3