An extension for flake8 that validates cognitive functions complexity.
Cognitive complexity is analog of cyclomatic complexity, that measure how difficult to understand piece of code. Introduced by G. Ann Campbell and currently used by SonarSource, CodeClimate and others. You can find more readings about cognitive complexity in cognitive-complexity readme file.
Default complexity is 7, can be configured via --max-cognitive-complexity
option.
pip install flake8-cognitive-complexity
def f(a, b):
if a:
for i in range(b):
if b:
return 1
Usage:
$ flake8 --max-cognitive-complexity=3 test.py
text.py:1:5: CCR001 Cognitive complexity is too high (6 > 3)
Tested on Python 3.7.x and flake8 3.7.8.
Error code | Description |
---|---|
CCR001 | Cognitive complexity is too high (X > Y) |
We would love you to contribute to our project. It's simple:
- Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
- Create a pull request. Make sure all checks are green.
- Fix review comments if any.
- Be awesome.
Here are useful tips:
- You can run all checks and tests with
make check
. Please do it before TravisCI does. - We use BestDoctor python styleguide.
- We respect Django CoC. Make soft, not bullshit.