best-doctor/flake8-expression-complexity

View on GitHub

Showing 2 of 2 total issues

Function iterate_over_expressions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def iterate_over_expressions(node: ast.AST) -> Iterable[ast.AST]:
    additionals_subnodes_info: List[Tuple[Tuple, Callable]] = [
        ((ast.If, ast.While), lambda n: [n.test]),
        ((ast.For, ), lambda n: [n.iter]),
        ((ast.AsyncFor, ), lambda n: [n.iter]),
Severity: Minor
Found in flake8_expression_complexity/utils/ast.py - About 1 hr to fix

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 run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def run(self) -> Generator[Tuple[int, int, str, type], None, None]:
        for expression in iterate_over_expressions(self.tree):
            if self.ignore_django_orm_queries and is_django_orm_query(expression):
                continue
            complexity = get_expression_complexity(expression)
Severity: Minor
Found in flake8_expression_complexity/checker.py - About 25 mins to fix

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

Severity
Category
Status
Source
Language