#!/usr/bin/env python3

import subprocess
import sys

from python_tools import lintable_tools_files


python_sources = [
    "zulipterminal/",
    "tests/",
    "setup.py",
]

python_sources += lintable_tools_files

tools = {
    "PEP8 & more (ruff)": ["ruff"] + python_sources,
    "Formatting (black)": ["black", "--check"] + python_sources,
    "Import order (isort)": "./tools/run-isort-check",
    "Type consistency (mypy)": "./tools/run-mypy",
    "Common spelling mistakes": "./tools/run-spellcheck",
    "Hotkey linting & docs sync check": ["./tools/lint-hotkeys"],
    "Docstring linting & docs sync check (lint-docstring)": "./tools/lint-docstring",
}

HEADER = 80 * "="
SUBHEADER = 80 * "-"

for tool_name, command in tools.items():
    print(f"{HEADER}\n{tool_name}\n{SUBHEADER}", flush=True)
    result = subprocess.call(command, stderr=subprocess.STDOUT)
    if result != 0:
        print(f"{HEADER}\nLINTING FAILED")
        sys.exit(1)

print(f"{HEADER}\nLINTING SUCCESSFUL")
