How to auto fix lint errors in a Pull Request (isort & black)
Auto fix lint errors like spacing, sorting imports and much more, let Github Actions create a commit for you fixing them.
If you want to fix lint errors running on CI you can easily commit all changes that the linter has made.
In this example, I will be using black and isort to lint a python repo and sort the imports in the correct order also removing any unused imports.
name: Lint
on:
pull_request:
branches: ['*']
jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Python dependencies and run linters
# Here you can use your own linter commands
run: |
pip install black isort
black .
isort --profile black --sg="app/alembic/**" .
- name: Run linters
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Applied automatic fixes from linters'
github_token: ${{ secrets.GITHUB_TOKEN }}