I suggest moving Pywikibot's linters/code formatters to [[ https://pre-commit.com/ | pre-commit ]].
pre-commit runs configured hooks (`.pre-commit-config.yaml`) against files changed in a commit when you `git commit ...`. (No more forgetting to run checks before sending for review.) It would also be run against all files in CI in case someone doesn't install it locally.
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/684050 is a proof of concept patch.
```
git-review -d 684050 # checkout the POC patch
pip install pre-commit # Install pre-commit
pre-commit install # Install pre-commit's pre-commit hook
git commit ... # pre-commit will run on the files changed
pre-commit uninstall # Unnstall pre-commit's pre-commit hook
pre-commit run --all-files # Run pre-commit on all files
```
Hooks included in the POC patch to demonstrate functionality:
| Include? | Hook | Description
| ---- | ---- | ----
| | check-added-large-files | Prevent giant files from being committed.
| | check-ast | Simply check whether files parse as valid python.
| | check-builtin-literals | Require literal syntax when initializing empty or zero Python builtin types.
| | check-docstring-first | Checks for a common error of placing code before the docstring.
| | check-json | Attempts to load all json files to verify syntax.
| | check-merge-conflict | Check for files that contain merge conflict strings.
| | check-symlinks | Checks for symlinks which do not point to anything.
| | check-toml | Attempts to load all TOML files to verify syntax.
| | check-vcs-permalinks | Ensures that links to vcs websites are permalinks.
| | check-xml | Attempts to load all xml files to verify syntax.
| | check-yaml | Attempts to load all yaml files to verify syntax.
| | debug-statements | Check for debugger imports and py37+ `breakpoint()` calls in python source.
| | destroyed-symlinks | Detects symlinks which are changed to regular files with a content of a path which that symlink was pointing to. This usually happens on Windows when a user clones a repository that has symlinks but they do not have the permission to create symlinks.
| | end-of-file-fixer | Makes sure files end in a newline and only a newline.
| | fix-byte-order-marker | removes UTF-8 byte order marker
| | fix-encoding-pragma | Remove `# -*- coding: utf-8 -*-` from the top of python files.
| | forbid-new-submodules | Prevent addition of new git submodules.
| | mixed-line-ending | Replaces or checks mixed line ending.
| | pretty-format-json | Checks that all your JSON files are pretty. "Pretty" here means that keys are sorted and indented.
| | trailing-whitespace | Trims trailing whitespace.
| | remove-crlf | Replace CRLF (`\r\n`) with LF (`\n`)
| | remove-tabs | Replace tab characters with spaces
| | pyupgrade | Run [[ https://github.com/asottile/pyupgrade | pyupgrade ]]
| | isort | Run [[ https://github.com/PyCQA/isort | isort ]]
| Yes | flake8 | Run [[ https://github.com/PyCQA/flake8 | flake8 ]]
Please take a look and share your thoughts about using pre-commit in Pywikibot development.
If we want to use it, which hooks do we want to include?