Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Melevir/flake8-cognitive-complexity
An extension for flake8 that validates cognitive functions complexity
https://github.com/Melevir/flake8-cognitive-complexity
code-complexity code-style complexity flake8 flake8-plugin styleguide
Last synced: 3 months ago
JSON representation
An extension for flake8 that validates cognitive functions complexity
- Host: GitHub
- URL: https://github.com/Melevir/flake8-cognitive-complexity
- Owner: Melevir
- License: mit
- Created: 2019-10-31T06:56:12.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-24T05:24:21.000Z (over 3 years ago)
- Last Synced: 2024-07-19T01:39:15.007Z (4 months ago)
- Topics: code-complexity, code-style, complexity, flake8, flake8-plugin, styleguide
- Language: Python
- Size: 19.5 KB
- Stars: 69
- Watchers: 3
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flake8-extensions - flake8-cognitive-complexity - Extension for flake8 that validates cognitive functions complexity. (Complexity)
README
# flake8-cognitive-complexity
[![Build Status](https://travis-ci.org/Melevir/flake8-cognitive-complexity.svg?branch=master)](https://travis-ci.org/Melevir/flake8-cognitive-complexity)
[![Maintainability](https://api.codeclimate.com/v1/badges/579738d149e489c631a6/maintainability)](https://codeclimate.com/github/Melevir/flake8-cognitive-complexity/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/579738d149e489c631a6/test_coverage)](https://codeclimate.com/github/Melevir/flake8-cognitive-complexity/test_coverage)
[![PyPI version](https://badge.fury.io/py/flake8-cognitive-complexity.svg)](https://badge.fury.io/py/flake8-cognitive-complexity)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-cognitive-complexity)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](https://github.com/ganncamp)
and currently used by SonarSource, CodeClimate and others.
You can find more readings about cognitive complexity in
[cognitive-complexity readme file](https://github.com/Melevir/cognitive_complexity/blob/master/README.md#what-is-cognitive-complexity).Default complexity is 7, can be configured via `--max-cognitive-complexity` option.
## Installation
```terminal
pip install flake8-cognitive-complexity
```## Example
```python
def f(a, b):
if a:
for i in range(b):
if b:
return 1
```Usage:
```terminal
$ 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 codes
| Error code | Description |
|:----------:|:----------------------------------------:|
| CCR001 | Cognitive complexity is too high (X > Y) |## Contributing
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](https://github.com/best-doctor/guides/blob/master/guides/en/python_styleguide.md).
- We respect [Django CoC](https://www.djangoproject.com/conduct/).
Make soft, not bullshit.