Automate code formatting
vanessa opened this issue · comments
Although flake8 is a really helpful tool for maintaining code quality, it doesn't fix formatting issues automatically. As a result, there are still some inconsistencies in the codebase. I'd like to propose adopting the code formatting tools below, which would improve readability and consistency of the code, ultimately increasing development speed:
- Black, to reformat code to follow a consistent style
- isort, to sort imports
- autoflake, to remove unused imports
These tools can be added to the pre-commit hook to automatically fix and amend files as part of the commit process, saving developers time and effort of manually fixing formatting issues. We can also add a shortcut to run these commands for added convenience.
If we decide to move forward, there's the option of fixing files incrementally or all at once. While the latter approach may result in some merge conflicts with currently open PRs, it'd improve the readability of future PRs by separating formatting changes from actual functional changes.
Would this be useful? Happy to work on this once we've addressed more pressing bugs.
I'd love to have this level of standardization in our codebases. Happy to hear @amakarudze and @marksweb opinions on this too.
@vanessa @ramonsaraiva yeah I'm in favour of any hooks that improve the developer experience.
I thought I'd added isort and a few more already bit clearly I hadn't.
To give you an example of what I usually add to projects, python & Django upgrade are really helpful especially:
https://github.com/django-cms/django-cms/blob/develop/.pre-commit-config.yaml
Those upgrade tools will help get the site to django 4. I think it'd be good to look at doing that soon.
And I don't use black myself and don't like the way it formats code, but I'm starting a new job soon where they use it... So I guess I need to get used to it 😂
From my personal experience, I have also hesitated to use black at some point, but after some customization to its standard configuration, it feels really good to just save the file and let it format the code for you. Especially when you're working with different people that have different code style tastes.
I do use black now in my personal projects so I think this would be great.