Pre commit using flake-8 and Black

Pre commit using flake-8 and Black

Your Tool For Style Guide Enforcement

Formatting :

whenever we commit the code for reviews, sometimes we forgot to check for the pep-8 standards and we miss small items like importing libraries not in the correct order, writing code more than 78 characters in a single line. these will give bad impressions

we see the review comments like

  • Missing 2 white spaces
  • Missing 2 blank lines between the 2 function definitions

Why don't we embed all linting before creating the commit/push?

We have the git hooks which will help It enables you to automatically run a short script before committing

Packages required: flake8

pip3 install flake8
pip3 install pre-commit

Install git-hooks in the repo

pre-commit install
# for checking the version
 pre-commit --version

Set up:

in the root directory of the git repo create the .pre-commit-config. yaml

repos:
-   repo: https://github.com/ambv/black
    rev: stable
    hooks:
    - id: black
      language_version: python3.6
-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
    - id: flake8

Run against all the files

pre-commit run --all-files

Screenshot from 2021-04-05 22-43-10.png

Thank you (.~.)