Function warnings_wrapper
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def warnings_wrapper(args):
parser = argparse.ArgumentParser(prog='mlx-warnings')
group1 = parser.add_argument_group('Configuration command line options')
group1.add_argument('--coverity', dest='coverity', action='store_true')
group1.add_argument('-d', '--doxygen', dest='doxygen', action='store_true')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Cyclomatic complexity is too high in function warnings_wrapper. (29) Open
def warnings_wrapper(args):
parser = argparse.ArgumentParser(prog='mlx-warnings')
group1 = parser.add_argument_group('Configuration command line options')
group1.add_argument('--coverity', dest='coverity', action='store_true')
group1.add_argument('-d', '--doxygen', dest='doxygen', action='store_true')
- Read upRead up
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
File warnings.py
has 342 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import errno
Consider simplifying this complex logical expression. Open
if args.configfile is not None:
checker_flags = args.sphinx or args.doxygen or args.junit or args.coverity or args.xmlrunner or args.robot
warning_args = args.maxwarnings or args.minwarnings or args.exact_warnings
if checker_flags or warning_args:
print("Configfile cannot be provided with other arguments")
Function warnings_wrapper
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def warnings_wrapper(args):
parser = argparse.ArgumentParser(prog='mlx-warnings')
group1 = parser.add_argument_group('Configuration command line options')
group1.add_argument('--coverity', dest='coverity', action='store_true')
group1.add_argument('-d', '--doxygen', dest='doxygen', action='store_true')
Function return_check_limits
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def return_check_limits(self, name=None):
''' Function for determining the return value of the script
If the name parameter is set, this function will check (and return) the
return value of that checker. If not, this function checks whether the
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function substitute_envvar
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def substitute_envvar(checker_config, keys):
"""Modifies configuration for checker in-place, resolving any environment variables for ``keys``
Args:
checker_config (dict): Configuration for a specific WarningsChecker
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Refactor this function to reduce its Cognitive Complexity from 40 to the 15 allowed. Open
def warnings_wrapper(args):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.