clean-code-python icon indicating copy to clipboard operation
clean-code-python copied to clipboard

Apply blacken-docs / the black code formatter

Open MartinThoma opened this issue 3 years ago • 2 comments

Black is becomming the de-facto standard for code formatting in Python. It makes sure code looks similar in many projects and it leads to minimal diffs.

MartinThoma avatar Feb 12 '22 08:02 MartinThoma

Makes sense. Before I merge this, I'll take a look at integrating Black via its API so tests fail if it detects any style errors. Bear with me...

zedr avatar Feb 20 '22 08:02 zedr

You can add a Github Action by creating .github/workflows/linting.yaml with the content:

name: Lint

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10"]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install blacken-docs
    - name: Test with blacken-docs
      run: |
        blacken-docs .

However, I'm uncertain if that will give a non-zero exit code when the check is run.

MartinThoma avatar Feb 20 '22 11:02 MartinThoma