From c8a847bd544efcdec80a5860a3a01b56297cbfdc Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:44:22 +1000 Subject: [PATCH] Update Pre-Commit hooks (#16983) Summary of the issue: Continuing work on our pre-commit hooks, there are still several we don't use but could. Description of user facing changes None. Description of development approach Tested pre-commit hooks available at pre-commit/pre-commit-hooks. Added those that work as expected and do not require major changes to our code base. Added: Automatic checking of yaml, toml and XML syntax Checks that no Python debug statements are included in commits Remove BOM on Python, C/C++ and Batch files, if present Ensure that unit test files are named according to unittest rules. Ensure that any include VCS links are permalinks. --- .pre-commit-config.yaml | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5cbfec49d8d..2d506f6dcf2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,16 +17,60 @@ repos: # Prevents commits to certain branches - id: no-commit-to-branch args: ["--branch", "master", "--branch", "beta", "--branch", "rc"] + # Checks that large files have not been added. Default cut-off for "large" files is 500kb. + - id: check-added-large-files + # POFiles and TTF fonts can't be made smaller + exclude_types: ["pofile", "ttf"] + # Same applies for NVDA dictionary (.dic) files and Spline Font Database (.SFD) files, but these aren't recognised by the Identify library. + exclude: "\\.(dic|sfd)$" # Checks python syntax - id: check-ast # File uses encoding not supported in Linux exclude: source/comInterfaces/_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py + # Checks for filenames that will conflict on case insensitive filesystems (the majority of Windows filesystems, most of the time) - id: check-case-conflict + # Checks for artifacts from resolving merge conflicts. - id: check-merge-conflict + # Checks Python files for debug statements, such as python's breakpoint function, or those inserted by some IDEs. + - id: debug-statements + # File uses encoding not supported in Linux + exclude: source/comInterfaces/_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py + # Removes trailing whitespace. - id: trailing-whitespace types_or: [python, c, c++, batch, markdown] + # Ensures all files end in 1 (and only 1) newline. - id: end-of-file-fixer types_or: [python, c, c++, batch, markdown] + # Removes the UTF-8 BOM from files that have it. + # See https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/codingStandards.md#encoding + - id: fix-byte-order-marker + types_or: [python, c, c++, batch, markdown] + # Validates TOML files. + - id: check-toml + # Validates YAML files. + - id: check-yaml + # Validates XML files. + - id: check-xml + # Ensures that links to lines in files under version control point to a particular commit. + - id: check-vcs-permalinks + # Checks that tests are named test_*.py. + - id: name-tests-test + args: ["--unittest"] + # Exclude Python files under `tests/` that aren't unittest files. + # This is a Python verbose regular expression. + # See https://docs.python.org/3/library/re.html#re.VERBOSE + exclude: | + (?x)^tests/( + checkPot.py | # Doesn't use unittest + system | # Uses robot + unit/ ( + # Test helpers + textProvider.py | + extensionPointTestHelpers.py | + objectProvider.py | + test_speechManager/speechManagerTestHarness.py + ) + ) - repo: https://github.com/asottile/add-trailing-comma rev: v3.1.0