Add pre-commit hooks for static code analysis and code formattaing#35
Add pre-commit hooks for static code analysis and code formattaing#35MArpogaus wants to merge 6 commits intoprobabilists:masterfrom MArpogaus:pre-commit
Conversation
|
I noticed that the project uses the older This offers several advantages. I would like to highlight the two most important benefits from my point of view:
Specifically the I did the migration from |
|
Hello @MArpogaus, thanks for the PR. I agree that automatic linting/formatting would be great. We already recommend So when I read your initial comment (with isort, flake8, black, ...), I decided to test Ruff and configure it to comply with the current conventions (see Now concerning the other changes,
More generally, as mentioned in the contributing guidelines, if you want to modify something (fix bug, add feature), first create a feature request issue. This allows to separate the discussions related to the bug/feature, from the discussions related to the fix/implementation. |
|
I just pushed a few commits that a) switch to a |
|
Hello @francois-rozet, I am happy to hear, that my PR gave you the final confidence to make the switch to I am very for ignoring your Contribution guidelines, i will respect them in following contributions! I agree with your concerns about auto-correcting linting errors, but I personally like the idea of rejecting commits with erroneous or incorrectly formatted code. |
Definitely better if the pre-commit only rejects without silent modifications. Still, would it be possible to make that an opt-in behavior? Also, do the hooks run locally before every commit or remotely on push? |
|
Hello @francois-rozet, yes, pre-commit hooks are always opt-in and only run locally if you don't add a specific CI workflow. If developers decide to integrate them into thiere git workflow, they can simply install the pre-commit package and install the hook via I hope this explanation helps. Just let me know if you wish to integrate it or not and i will rebase and adjust my changes accordingly :-) |
|
Ok let's try that! |
Hello @francois-rozet,
I hope you're doing well. I wanted to share my recent changes.
To make our codebase more consistent and maintainable, I've added some automated code formatters and static code analysis tools using the pre-commit framework.
(Edit: my first draft used a couple of linters (isort,flake8) and formatters (black, autoflake) in parallel. this adds unnecessary complexity, hence i decided to switch to a more modern approach using ruff)
Here's a quick overview of each hook and their repository links:
ruff An extremely fast Python linter and code formatter, written in Rust.
pre-commit-hooks: These hooks provide a range of useful features, including checking for trailing whitespace, validating YAML and TOML files, detecting accidentally added large files, and identifying merge conflicts.
language-formatters-pre-commit-hooks: The hooks in this repository enable pretty formatting of YAML and TOML files, making them more readable and following best practices.
By incorporating these automated code formatters and static code analysis tools into the project, we can save time during code reviews by minimizing manual fixes and ensuring that everyone follows consistent coding standards.
I'm really excited about these enhancements and how they'll benefit our collaboration.
Let's discuss these changes further! Let me know If you have any concerns or questions.
Best regards,
Marcel