This section demonstrates how static code analysis is automatically executed before each commit using pre-commit, Ruff, and Mypy.
Pre-commit is installed as a development dependency:
poetry add -D pre-committhen the Git hook is activated:
poetry run pre-commit installThis creates the file .git/hooks/pre-commit which runs automatically at each commit.
The configuration is located at the root of the repository in: .pre-commit-config.yaml Link : https://github.com/aymaneVXx/todo-cli/blob/main/.pre-commit-config.yaml
- repo: local → uses the tools already installed via Poetry
- ruff hook → runs static linting
- mypy hook → runs type checking
- pass_filenames: false → ensures pre-commit does not append filenames (avoids Mypy duplicate module errors)
Manually on all files:
poetry run pre-commit run --all-filesAutomatically before every commit:
git commit -m "Your message"If Ruff or Mypy find issues, the commit is blocked until the issues are fixed — this ensures code quality.