Skip to content

chore: Run pre-commit hook against staged files only

What does this merge request do and why?

Changes to Makefile and lefthook.yml:

  • lefthook.yml:
    • Restricts pre-commit linting tasks to staged files only using staged_files variable.
    • Introduces a lint-other command which is designed to work with all non .py staged files (currently only codespell [spelling mistakes in codebase] and editorconfig [formatting rules for various file formats]).
  • Makefile:
    • Introduces EDITORCONFIG_LINT_WORKING_DIR & CODESPELL_LINT_WORKING_DIR variables to limit the scope of both editorconfig and codespell checks.

How to set up and validate locally

Run lefthook run pre-commit to test locally.

Feel free to use this script to generate some test .py files
#!/bin/bash

# Script to create test files for pre-commit hook testing

# Array of variable names and values
declare -a files=(
    "testing.py:TESTING:Bar!"
    "testing0.py:TEST:Foo!"
    "testing1.py:VALUE:Hello!"
    "testing2.py:DATA:World!"
    "testing3.py:CONFIG:Debug!"
    "testing4.py:RESULT:Success!"
    "testing5.py:MESSAGE:Complete!"
    "testing6.py:STATUS:Ready!"
    "testing7.py:OUTPUT:Done!"
    "testing8.py:FLAG:Active!"
    "testing9.py:STATE:Running!"
)

# Create each test file
for file_info in "${files[@]}"; do
    IFS=':' read -r filename varname value <<< "$file_info"
    echo "${varname} = \"${value}\"" > "$filename"
    echo "" >> "$filename"
    echo "Created: $filename"
done

echo "All test files created successfully!"

Then run:

git add testing*.py

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Tim Morriss

Merge request reports

Loading