Skip to main content

A flake8 extension that checks cyclomatic complexity and calculates max complexity limit in runtime

Project description

flake8-adjustable-complexity

Build Status Maintainability Test Coverage

An extension for flake8 to report on too complex functions with bad variables names.

Sometimes you want to use too generic variable name inside some function. It this case you want to be sure that the function is more simple that others, so a reader doesn't have to remember meaning of a variable together with other logic for a long time.

This plugin calculates max allowed cyclomatic complexity for each function separately. Default is 7, and it is decreased by 2 for each variable from blacklist inside the function. If actual complexity overcomes max calculated complexity, the plugin reports an error.

Currently, the following errors are reported:

Code Description
CAC001 func is too complex (complexity > max allowed complexity)
CAC002 func is too complex (complexity). Bad variable names penalty is too high (penalty)

Installation

pip install flake8-adjustable-complexity

Configuration

The plugin has the following configuration options:

  • --max-mccabe-complexity (or --max-adjustable-complexity) - Max allowed cyclomatic complexity.
  • --per-path-max-adjustable-complexity - Per-path complexity settings. The value of the option must be a comma-separated list of <path>:<complexity> pairs.
  • --var-names-extra-blacklist - Comma-separated list of bad variable names to blacklist. Each variable will affect the max allowed complexity.
  • --var-names-whitelist - Comma-separated list of bad variable names to whitelist.

All options also can be specified via [flake8] section of setup.cfg.

Example

Sample file:

# test.py

def foo():
    for vars in range(5):
        for info in range(5):
            for obj in range(5):
                pass

Usage:

$ flake8 test.py
test.py:1:1: CAC001 foo is too complex (4 > 1)

Contributing

We would love you to contribute to our project. It's simple:

  1. Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
  2. Create a pull request. Make sure all checks are green.
  3. Fix review comments if any.
  4. Be awesome.

Here are useful tips:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_adjustable_complexity-0.0.6.tar.gz (8.5 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page