Add Black code formatting as a pre-commit
Closed this issue · 6 comments
We can make sure our code is always properly formatted by using pre-commits
paired with black
. Here is a good guide on how to do it.
This way formatting would be done automatically for the developers with pre-commit
installed.
It can also be easily added to GitHub actions.
After a quick overview, this seems nice. This addresses the styling aspects not covered by flake8. We should check though if flake8 can also do this task (reformat for you) or not at this fine-grained level.
After a quick overview, this seems nice. This addresses the styling aspects not covered by flake8. We should check though if flake8 can also do this task (reformat for you) or not at this fine-grained level.
After a quick overview, this seems nice. This addresses the styling aspects not covered by flake8. We should check though if flake8 can also do this task (reformat for you) or not at this fine-grained level.
Ok, flake8 can notify you but not automatically reformat code.
This is a configuration file we use in other projects, might be helpful as an initial idea:
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
- id: pretty-format-json
args:
- --autofix
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [--profile, black, --filter-files]
Once the configuration has been done, I can add https://pre-commit.ci/ to this project so the versions are automatically maintained.
@pablo-de-andres the only remaining detail is that you add the service to the project 😉