Enforce Your Chosen Code Style
What:
Use tools to ensure that your code matches the style you wish to maintain
Why: Eases the process of developers writing code by ensuring that all developers use the same style
Implementations:
-
Format in CI
- Provides a repeatable environment to ensure formatting/style
- Has a lot of configuration options for different style preferences
- Independent of version control forge (ie GitHub, Gitlab, etc.)
- May hold up contributions in Pull Requests due to maintainers needing to review style
-
Formatting pre-commit hook
- Runs on the developer machine to ensure that commits are formatted correctly before being committed
- Ensures that only formatted commits get checked into version control
- Runs on every commit which can be detrimental to enabling contribution
- Higher learning curve for new developers
-
Pep8speaks
- Provides a very succinct and clear description of style/linting changes needed on a PR
- Requires greater setup in GitHub to use
- Only works on GitHub
-
CodeClimate
Tools:
-
Ruff
- Very fast and provides lots of linting options
- Highly configurable to match many different style options
- Provides a VSCode extension (https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) for developers
- Adopted by the NumPy project to help prevent breaking changes due to deprecations
- Newer project with few CI options available, mainly used locally
-
Black
- The standard in linting/formatting for Python projects
- Provides a GitHub Action for linting in CI
-
Flake8
- Contains an extensible plugin solution for
Resources: