summaryrefslogtreecommitdiff
path: root/lint
diff options
context:
space:
mode:
Diffstat (limited to 'lint')
-rwxr-xr-xlint45
1 files changed, 45 insertions, 0 deletions
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)