Skip to content

Flakeheaven

Flakeheaven is a Flake8 wrapper to make it cool.

Some of it's features are:

You can use this cookiecutter template to create a python project with flakeheaven already configured.

Installation

pip install flakeheaven

Configuration

Flakeheaven can be configured in pyproject.toml. You can specify any Flake8 options and Flakeheaven-specific parameters.

Plugins

In pyproject.toml you can specify [tool.flakeheaven.plugins] table. It's a list of flake8 plugins and associated to them rules.

Key can be exact plugin name or wildcard template. For example "flake8-commas" or "flake8-*". Flakeheaven will choose the longest match for every plugin if possible. In the previous example, flake8-commas will match to the first pattern, flake8-bandit and flake8-bugbear to the second, and pycodestyle will not match to any pattern.

Value is a list of templates for error codes for this plugin. First symbol in every template must be + (include) or - (exclude). The latest matched pattern wins. For example, ["+*", "-F*", "-E30?", "-E401"] means "Include everything except all checks that starts with F, check from E301 to E310, and E401".

Example: pyproject.toml

[tool.flakeheaven]
# specify any flake8 options. For example, exclude "example.py":
exclude = ["example.py"]
# make output nice
format = "grouped"
# don't limit yourself
max_line_length = 120
# show line of source code in output
show_source = true

# list of plugins and rules for them
[tool.flakeheaven.plugins]
# include everything in pyflakes except F401
pyflakes = ["+*", "-F401"]
# enable only codes from S100 to S199
flake8-bandit = ["-*", "+S1??"]
# enable everything that starts from `flake8-`
"flake8-*" = ["+*"]
# explicitly disable plugin
flake8-docstrings = ["-*"]

# disable some checks for tests
[tool.flakeheaven.exceptions."tests/"]
pycodestyle = ["-F401"]     # disable a check
pyflakes = ["-*"]           # disable a plugin

# do not disable `pyflakes` for one file in tests
[tool.flakeheaven.exceptions."tests/test_example.py"]
pyflakes = ["+*"]           # enable a plugin

Check a complete list of flake8 extensions.

Usage

When using Flakeheaven, I frequently use the following commands:

flakeheaven lint
Runs the linter, similar to the flake8 command.
flakeheaven plugins
Lists all the plugins used, and their configuration status.
flakeheaven missed
Shows any plugins that are in the configuration but not installed properly.
flakeheaven code S322
(or any other code) Shows the explanation for that specific warning code.
flakeheaven yesqa
Removes unused codes from # noqa and removes bare noqa that says “ignore everything on this line” as is a bad practice.

Integrations

Flakeheaven checks can be run in:

  • In Vim though the ALE plugin.

  • Through a pre-commit:

      - repo: https://github.com/flakeheaven/flakeheaven
        rev: master
        hooks:
          - name: Run flakeheaven static analysis tool
            id: flakeheaven
    
  • In the CI:

      - name: Test linters
        run: make lint
    

    Assuming you're using a Makefile like the one in my cookiecutter-python-project.

Issues

Troubleshooting

['Namespace' object has no attribute

'extended_default_ignore'](https://githubmemory.com/repo/flakeheaven/flakeheaven/issues/10)

Add to your pyproject.toml:

[tool.flakeheaven]
extended_default_ignore=[]

References