ducminh-phan/reformat-gherkin

View on GitHub
reformat_gherkin/formatter.py

Summary

Maintainability
C
1 day
Test Coverage

File formatter.py has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from itertools import chain, groupby
from typing import (
    Any,
    Callable,
    Dict,
Severity: Minor
Found in reformat_gherkin/formatter.py - About 4 hrs to fix

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

        def __find_nodes_within_rules(self) -> Set[Node]:
            nodes_within_rules: Set[Node] = set()
    
            feature = self.ast.feature
            if feature is not None:
    Severity: Minor
    Found in reformat_gherkin/formatter.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 __construct_contexts has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def __construct_contexts(self) -> ContextMap:
            """
            Construct the information about the context a certain line might need to know to
            properly format these lines.
            """
    Severity: Minor
    Found in reformat_gherkin/formatter.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 __find_nodes_with_newline has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __find_nodes_with_newline(self) -> Set[Node]:
            """
            Find all nodes in the AST that needs a new line after it.
            """
    
    
    Severity: Minor
    Found in reformat_gherkin/formatter.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

    Avoid deeply nested control flow statements.
    Open

                            if not isinstance(node, Rule):
                                nodes_within_rules.add(node)
    
    
    Severity: Major
    Found in reformat_gherkin/formatter.py - About 45 mins to fix

      Function generate_step_line has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def generate_step_line(
      Severity: Minor
      Found in reformat_gherkin/formatter.py - About 45 mins to fix

        Function __construct_contexts_for_comments has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def __construct_contexts_for_comments(nodes: List[Node]) -> ContextMap:
                # The context of each comment line is the next non-comment line.
                #
                # The steps of the algorithm:
                # 1. Group the nodes into comments and non-comments
        Severity: Minor
        Found in reformat_gherkin/formatter.py - About 35 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

        Function __group_tags has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __group_tags(self):
                """
                Group the tags of a node, so that we can render them on a single line.
                """
        
        
        Severity: Minor
        Found in reformat_gherkin/formatter.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

        Function extract_rows has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def extract_rows(node: Union[DataTable, Examples]) -> List[TableRow]:
            """
            Extract table rows from either a Datable or Example instance.
            """
        
        
        Severity: Minor
        Found in reformat_gherkin/formatter.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

        There are no issues that match your filters.

        Category
        Status