# 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) |
Raw data
{
"_id": null,
"home_page": "https://github.com/Melevir/flake8-cognitive-complexity",
"name": "flake8-cognitive-complexity",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "flake8",
"author": "Ilya Lebedev",
"author_email": "melevir@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e7/d6/2bb09fab21521424d5afc836aa0057d15a92f5e738e506a3e3cb035be517/flake8_cognitive_complexity-0.1.0.tar.gz",
"platform": "",
"description": "# flake8-cognitive-complexity\n\n[![Build Status](https://travis-ci.org/Melevir/flake8-cognitive-complexity.svg?branch=master)](https://travis-ci.org/Melevir/flake8-cognitive-complexity)\n[![Maintainability](https://api.codeclimate.com/v1/badges/579738d149e489c631a6/maintainability)](https://codeclimate.com/github/Melevir/flake8-cognitive-complexity/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/579738d149e489c631a6/test_coverage)](https://codeclimate.com/github/Melevir/flake8-cognitive-complexity/test_coverage)\n[![PyPI version](https://badge.fury.io/py/flake8-cognitive-complexity.svg)](https://badge.fury.io/py/flake8-cognitive-complexity)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-cognitive-complexity)\n\nAn extension for flake8 that validates cognitive functions complexity.\n\nCognitive complexity is analog of cyclomatic complexity, that measure\nhow difficult to understand piece of code. Introduced by [G. Ann Campbell](https://github.com/ganncamp)\nand currently used by SonarSource, CodeClimate and others.\nYou can find more readings about cognitive complexity in\n[cognitive-complexity readme file](https://github.com/Melevir/cognitive_complexity/blob/master/README.md#what-is-cognitive-complexity).\n\nDefault complexity is 7, can be configured via `--max-cognitive-complexity` option.\n\n## Installation\n\n```terminal\npip install flake8-cognitive-complexity\n```\n\n## Example\n\n```python\ndef f(a, b):\n if a:\n for i in range(b):\n if b:\n return 1\n```\n\nUsage:\n\n```terminal\n$ flake8 --max-cognitive-complexity=3 test.py\ntext.py:1:5: CCR001 Cognitive complexity is too high (6 > 3)\n```\n\nTested on Python 3.7.x and flake8 3.7.8.\n\n## Error codes\n\n| Error code | Description |\n|:----------:|:----------------------------------------:|\n| CCR001 | Cognitive complexity is too high (X > Y) |",
"bugtrack_url": null,
"license": "MIT",
"summary": "An extension for flake8 that validates cognitive functions complexity",
"version": "0.1.0",
"split_keywords": [
"flake8"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "91508c65384ff2627a81fbacf1b9fe74",
"sha256": "f202df054e4f6ff182b659c261922b9c684628a47beb19cb0973c50d6a7831c1"
},
"downloads": -1,
"filename": "flake8_cognitive_complexity-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "91508c65384ff2627a81fbacf1b9fe74",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 3061,
"upload_time": "2020-08-01T05:49:18",
"upload_time_iso_8601": "2020-08-01T05:49:18.353486Z",
"url": "https://files.pythonhosted.org/packages/e7/d6/2bb09fab21521424d5afc836aa0057d15a92f5e738e506a3e3cb035be517/flake8_cognitive_complexity-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-08-01 05:49:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Melevir",
"github_project": "flake8-cognitive-complexity",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "flake8-cognitive-complexity"
}