- Style Guide Enforcement
- Check code syntax
- Provide instructions on how to clean it
- Prevent things like syntax errors, typos, bad formatting, incorrect styling, etc
- If you working in the team, it saves time for people who are reviewing your code (no need to distrust for typos and formatting issues). Read more
-
pip install flake8
-
Install VSCode plugin: cornflakes-linter
-
Settings.json:
{ "cornflakes.linter.executablePath": "path/to/venvs/myvenv/bin/flake8", "cornflakes.linter.run": "onType" }
- Sort imports alphabetically
- Automatically separated into sections and by type.
-
pip install isort
-
isort mypythonfile.py mypythonfile2.py isort . isort **/*.py isort mypythonfile.py --diff # only applying changes if they don't introduce syntax errors isort --atomic .
- Can be forced to check with GitHub Actions on push or pull requests
-
pip install black
-
- VSCode: Right click + Format Document
-
Sometimes needs to refresh project in VSCode
black my_file.py black .
- isort compatibility
pyproject.toml:[tool.isort] profile = "black" multi_line_output = 3
-
pip install mypy
-
mypy .