summaryrefslogtreecommitdiff
path: root/Biz/lint.py
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-11-12 17:13:39 -0800
committerBen Sima <ben@bsima.me>2020-11-12 17:21:13 -0800
commit890e44ebcc11c48f7347aa60748a84c48261aa5e (patch)
tree894e30ce7a0c81ef3968c04f82d068a65c15b0f5 /Biz/lint.py
parent19f5402bec9f6346463b83536cc22d7f4525bc18 (diff)
Get Biz.Dev setup again
Also correctly renamed the files (didn't work the first time thanks to the macOS filesystem) and moved the default build.os settings to a OsBase.nix file to be used via imports.
Diffstat (limited to 'Biz/lint.py')
-rwxr-xr-xBiz/lint.py97
1 files changed, 0 insertions, 97 deletions
diff --git a/Biz/lint.py b/Biz/lint.py
deleted file mode 100755
index fccda57..0000000
--- a/Biz/lint.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env python
-"""
-all your lint are belong to us
-"""
-import os
-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
- args = {
- "ormolu": ["--mode", "check"],
- "hlint": [],
- "black": ["--quiet", "--check"],
- "pylint": [],
- }
- # pylint: disable=subprocess-run-check
- ret = subprocess.run([cmd, *args[cmd], file], stdout=subprocess.PIPE)
- if ret.returncode != 0:
- ERRORS += 1 # pylint: disable=undefined-variable
- msg = ret.stdout.decode("utf-8").strip()
- print(Color.WARN + f"lint error: {cmd}: {file}" + Color.END)
- if msg:
- for line in msg.split("\n"):
- print(" " + line)
-
-
-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", "--name-only", merge_base])
- .decode("utf-8")
- .strip()
- .split()
- )
-
-
-def group_files(files, extensions):
- """Given a list of files and list of extensions, return a dict of:
- {ext: [files]}
-
- """
- root = os.getenv("BIZ_ROOT")
- ret = {k: [] for k in extensions}
- for ext in extensions:
- for file in files:
- if file.endswith(ext):
- ret[ext].append(os.path.join(root, file))
- return ret
-
-
-def guard_todos(files):
- for fname in files:
- with open(fname) as text:
- if "TODO" in text.read():
- ERRORS += 1
- print("found todo:", fname)
-
-
-if __name__ == "__main__":
- ERRORS = 0
- if "-h" in sys.argv:
- print(f"usage: {os.path.basename(__file__)} <files...>")
- 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"])
- else:
- FILES = group_files(sys.argv[1:], [".hs", ".py"])
- for hs in FILES[".hs"]:
- print(f"lint: {hs}")
- run("ormolu", hs)
- run("hlint", hs)
- for py in FILES[".py"]:
- print(f"lint: {py}")
- run("black", py)
- run("pylint", py)
- sys.exit(ERRORS)