flake8-cognitive-complexity

0.1.0 · maintenance · verified Thu Apr 16

An extension for flake8 that validates cognitive functions complexity. Cognitive complexity is an analog of cyclomatic complexity, measuring how difficult a piece of code is to understand, as introduced by G. Ann Campbell and used by SonarSource and CodeClimate. The library is currently at version 0.1.0 and has seen limited releases since its initial upload in 2020, suggesting a stable but not actively developed state.

Common errors

Warnings

Install

Quickstart

After installation, `flake8-cognitive-complexity` automatically integrates with `flake8`. Simply run `flake8` on your project. By default, it uses a cognitive complexity threshold of 7. You can configure this maximum allowed cognitive complexity using the `--max-cognitive-complexity` option either on the command line or in your `flake8` configuration file (e.g., `setup.cfg` or `tox.ini`).

# test_code.py
def f(a, b):
    if a:
        for i in range(b):
            if b:
                return 1

# Save the above as test_code.py

# To run from terminal (after 'pip install flake8 flake8-cognitive-complexity'):
# flake8 test_code.py
# flake8 --max-cognitive-complexity=3 test_code.py

view raw JSON →