From a5c70b2b691586f47e8a9b155f8c964c56597679 Mon Sep 17 00:00:00 2001 From: Hrishikesh Borkar Date: Fri, 11 Oct 2024 12:48:22 -0500 Subject: [PATCH 1/4] Added custom pre-commit hook --- .pre-commit-config.yaml | 7 ++++++ .pre-commit-hooks.yaml | 8 +++++++ pre-commit/check_json_indentation.py | 34 ++++++++++++++++++++++++++++ tox.ini | 16 ------------- 4 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 .pre-commit-hooks.yaml create mode 100644 pre-commit/check_json_indentation.py delete mode 100644 tox.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 373faa33e..9acf6dd2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,5 +61,12 @@ repos: - repo: meta hooks: - id: check-useless-excludes + - repo: local + hooks: + - id: check-json-indentation + name: Check JSON Indentation Consistency + entry: pre-commit/check_json_indentation.py + language: python + files: \.json$ default_language_version: python: python3.10 diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 000000000..db2bc0325 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,8 @@ +- id: check-json-indentation + name: Check JSON Indentation Consistency + description: This hook checks that JSON files do not have mixed tabs and spaces for indentation. + entry: pre-commit/check_json_indentation.py + language: python + files: \.json$ + types: [text] + verbose: true diff --git a/pre-commit/check_json_indentation.py b/pre-commit/check_json_indentation.py new file mode 100644 index 000000000..b31b277c4 --- /dev/null +++ b/pre-commit/check_json_indentation.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import sys + + +def check_json_indentation(filename): + with open(filename, "r") as file: + lines = file.readlines() + + tabs_found = False + spaces_found = False + + for line in lines: + stripped_line = line.lstrip() + if stripped_line and line.startswith("\t"): + tabs_found = True + elif stripped_line and line.startswith(" "): + spaces_found = True + + if tabs_found and spaces_found: + print(f"Error: {filename} contains mixed tabs and spaces for indentation.") + return False + + return True + + +if __name__ == "__main__": + files_to_check = sys.argv[1:] + exit_code = 0 + + for json_file in files_to_check: + if not check_json_indentation(json_file): + exit_code = 1 + + sys.exit(exit_code) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 5e6f8fd62..000000000 --- a/tox.ini +++ /dev/null @@ -1,16 +0,0 @@ -[tox] -envlist = py310 -skipsdist = True - -[testenv] -setenv = - PYTHONDONTWRITEBYTECODE=1 - PYTHONPATH = {toxinidir}/vendor/lib/python -deps = - -rrequirements.txt - -rrequirements-dev.txt - -commands = - alembic upgrade head - coverage erase - coverage run --branch --source {toxinidir}/bugbot -m unittest -v {posargs} From bbacfa6e8ae9d1950f57422cd774cc0fcf44d8fd Mon Sep 17 00:00:00 2001 From: Hrishikesh Borkar Date: Fri, 11 Oct 2024 13:21:04 -0500 Subject: [PATCH 2/4] Make JSON indentation check script executable --- .taskcluster.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.taskcluster.yml b/.taskcluster.yml index 3fe88f3e6..8bcb2c946 100644 --- a/.taskcluster.yml +++ b/.taskcluster.yml @@ -47,6 +47,7 @@ tasks: - "-lcx" - "git clone --quiet ${repository} bugbot && cd bugbot && + chmod +x pre-commit/check_json_indentation.py && git -c advice.detachedHead=false checkout ${head_rev} && pip install --quiet -r requirements-test.txt && pre-commit run --all-files --show-diff-on-failure && From 0a097c54790506895f999803241a830be805656e Mon Sep 17 00:00:00 2001 From: "Hrishikesh (Rishi) Borkar" <23469417+hrishi-1337@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:43:27 -0500 Subject: [PATCH 3/4] Update .taskcluster.yml --- .taskcluster.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.taskcluster.yml b/.taskcluster.yml index 8bcb2c946..eb43b0fd6 100644 --- a/.taskcluster.yml +++ b/.taskcluster.yml @@ -47,8 +47,8 @@ tasks: - "-lcx" - "git clone --quiet ${repository} bugbot && cd bugbot && - chmod +x pre-commit/check_json_indentation.py && git -c advice.detachedHead=false checkout ${head_rev} && + chmod +x pre-commit/check_json_indentation.py && pip install --quiet -r requirements-test.txt && pre-commit run --all-files --show-diff-on-failure && tox -e $TOX_ENV && From 0e2c0b34456c6cee5e02f61f50b948d91b5c6726 Mon Sep 17 00:00:00 2001 From: "Hrishikesh (Rishi) Borkar" <23469417+hrishi-1337@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:43:56 -0500 Subject: [PATCH 4/4] Readded tox.ini --- tox.ini | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..5e6f8fd62 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[tox] +envlist = py310 +skipsdist = True + +[testenv] +setenv = + PYTHONDONTWRITEBYTECODE=1 + PYTHONPATH = {toxinidir}/vendor/lib/python +deps = + -rrequirements.txt + -rrequirements-dev.txt + +commands = + alembic upgrade head + coverage erase + coverage run --branch --source {toxinidir}/bugbot -m unittest -v {posargs}