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.
pip install flake8-cognitive-complexityNo compatibility data collected yet for this library.
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`).
Check the GitHub repository for recent commits or open issues. If encountering compatibility problems with newer environments, consider the project's maintenance status or community forks.
Adjust the threshold using `--max-cognitive-complexity=<value>` in your `flake8` command or configuration file (e.g., `setup.cfg`, `tox.ini`) under the `[flake8]` section. For instance: `[flake8] max-cognitive-complexity = 15`.
If encountering unexpected errors or plugin not loading, try locking your `flake8` version to one known to be compatible (e.g., `flake8<4.0`). Refer to `flake8`'s release notes for breaking changes related to its plugin interface.
Refactor the function to reduce its complexity. This can involve splitting it into smaller functions, reducing nesting levels, simplifying conditional logic, or extracting helper methods. Alternatively, increase the `max-cognitive-complexity` threshold in your `flake8` configuration.
Install `flake8` in your current Python environment using `pip install flake8`. If using a virtual environment, ensure it is activated before running `flake8`.
Verify that `pip install flake8-cognitive-complexity` was executed in the same Python environment that `flake8` is running from. You can check if the plugin is detected by running `flake8 --version` and looking for 'cognitive-complexity' in the output. If it's not there, reinstall the plugin or check your environment setup.