Dinnerbone / mcstatus

A Python class for checking the status of an enabled Minecraft server
http://dinnerbone.com/minecraft/tools/status/
1.11k stars 146 forks source link

Add pre-commit #220

Closed ItsDrike closed 2 years ago

ItsDrike commented 2 years ago

Using pre-commit is benificial as it prevents people to make a commit which would fail our validation workflow anyway. It's a way to quickly run all of the necessary checks that we require to pass and if they fail, the commit will simply be blocked. Though because it will run on every commit, it shouldn't perform actions which would take too long (such as running all of the tests).

On top of this, pre-commit also allows us to put auto-formatters there (such as black, or automatic fixer for trailing whitespaces), which will edit the files for us, however it will not stage them and the commit will still get blocked. This allows us to easily revert this autoformatted change if we need to, but also to easily stage these files and redo the commit with it.

While this isn't required, it would be ideal for every contributor to run pre-commit install (as now documented in CONTRIBUTING.md), which will add the git hook running precommit before each commit on the changed files.

I've also included running pre-commit in the Validation workflow, as it does add some things which we weren't checking before, such as verifying the validity of toml and yaml files, automatically fixing trailing whitespaces, disallowing blanket noqas and disallowing the use of type-comments instead of type-hints. However I did skip the actions which we run standalone checks for, since it's much clearer to immediately see that for example black formatting has failed, in comparison to just seeing pre-commit has failed in one of it's actions, requiring us to open the workflow and see what happened each time.

ItsDrike commented 2 years ago

I'm reaaaaly getting annoyed now. Wrong repo again!