Flake8 - Octo-Ninja Linter¶
Main point
Flake8 combines so much linter-power under the hood of a single tool! If used correctly, it will make your code not only more consistent, but simply better (and more pythonic 🐍).
Flake8 is a wrapper around three tools:
- PyFlakes - checks for Python errors.
- pycodestyle - tests Python code against some of the style conventions in PEP 8.
- McCabe - analyses Python code complexity (see the next section for more details).
Flake8 is configurable, where specific setup can be pointed in a couple of ways.
- You may find preconfigured .flake8 in Big-Bang-py.
There is an abundance of plugins greatly extending capability of Flake8. Search for them on GitHub.
- A bunch of plugins are included in Flake8 configuration of Big-Bang-py. See all flake8-* packages in dev.in file.
- An interesting example is flake8-html, which generates readable Flake8 HTML report (works similar to coverage html).
It is recommended to include Flake8 in your linting Invoke task and also to run it during Pre-commit Git Hook. Example of both can be found in Big-Bang-py, see project.py and Pre-commit.
To manage edge cases, exclude Flake8 checking:
Option 3 & 4 are best set in Flake8 config. See an example below:
ignore = # C408: Unnecessary (dict/list/tuple) call - rewrite as a literal # # Calling directly dict/list/tuple is more obvious & explicit, making it # easier to read. C408, # C812 missing trailing comma # # Experience shows that this can be seriously inconvenient. C812 per-file-ignores = ci/ci_checks.py: T001 tasks/release.py: T001