fbdevelopercircles / open-source-edu-bot

Open Source Education bot, built by the Developer Circles community.
MIT License
59 stars 79 forks source link

Adding Flake8 and Black linter #130

Closed iamrajiv closed 3 years ago

iamrajiv commented 3 years ago

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Flake8 is a Python library that wraps PyFlakes, pycodestyle and Ned Batchelder’s McCabe script. It is a great toolkit for checking your codebase against coding style (PEP8), programming errors (like “library imported but unused” and “Undefined name”) and to check cyclomatic complexity.

elinguiuriel commented 3 years ago

@iamrajiv please can you explain how you will implement it first?

As you can see here:
https://github.com/fbdevelopercircles/open-source-edu-bot/blob/e016a83de92230b21279142c6b2ed35ba2cc2a70/.github/workflows/main.yml#L22 and here : https://github.com/fbdevelopercircles/open-source-edu-bot/blob/e016a83de92230b21279142c6b2ed35ba2cc2a70/requirements.txt#L13

This project already uses flake8 as code formatter and linter, all the code of the app is well formated, and as a rule any PR that does not pass flake8 test will not pass.

iamrajiv commented 3 years ago

@elinguiuriel Since, Flake8 is already implemented so we can go fro Black. Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.

I will implement Black by adding black.yml file workflows.

name: Black

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  formatting:
    name: Black Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup black environment
        run: conda create --quiet --name black black

      - name: Check formatting
        run: |
          export PATH="/usr/share/miniconda/bin:$PATH"
          source activate black
          black --check .
elinguiuriel commented 3 years ago

@iamrajiv I do really appreciate your proposition, I think using flake8 and black is in some aspect redundant. Also, you specify conda we do not use a specific environment in the project as it has to be able to work everywhere. When formatting the code black can bring some issues with the translation alignment. Do you understand my point, have any other improvements propose? checks the issues for example