melexis/sphinx-traceability-extension

View on GitHub
mlx/traceability/directives/item_matrix_directive.py

Summary

Maintainability
B
4 hrs
Test Coverage

Use of possibly insecure function - consider using safer ast.literal_eval.
Invalid

                if not eval(expression):  # pylint: disable=eval-used

Cyclomatic complexity is too high in method perform_replacement. (48)
Open

    def perform_replacement(self, app, collection):
        """
        Creates table with related items, printing their target references. Only source and target items matching
        respective regexp shall be included.

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.

Source: http://radon.readthedocs.org/en/latest/intro.html

File item_matrix_directive.py has 605 lines of code (exceeds 500 allowed). Consider refactoring.
Open

"""Module for the item-matrix directive"""
import re
from collections import namedtuple
from copy import copy, deepcopy

Severity: Major
Found in mlx/traceability/directives/item_matrix_directive.py - About 4 hrs to fix

    Cyclomatic complexity is too high in method _store_data. (15)
    Open

        def _store_data(self, rows, source, right_cells, covered, app):
            """ Stores the data in one or more rows in the given Rows object.
    
            Note that merging and removing cells happens in a later stage.
    
    

    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.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method _postprocess_tbody. (13)
    Open

        def _postprocess_tbody(self, tbody):
            """ Merges cells where appropriate to avoid duplication and removes certain columns depending on configuration
    
            Args:
                tbody (nodes.tbody): Table body to modify

    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.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in class ItemMatrixDirective. (13)
    Open

    class ItemMatrixDirective(TraceableBaseDirective):
        """
        Directive to generate a matrix of item cross-references, based on
        a given set of relationship types.
    
    

    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.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method run. (13)
    Open

        def run(self):
            env = self.state.document.settings.env
            app = env.app
    
            node = ItemMatrix('')

    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.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
    Open

        def _postprocess_tbody(self, tbody):

    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.

    See

    Refactor this function to reduce its Cognitive Complexity from 60 to the 15 allowed.
    Open

        def perform_replacement(self, app, collection):

    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.

    See

    Too many statements (104/50)
    Confirmed

        def perform_replacement(self, app, collection):

    Used when a function or method has too many statements. You should then split it in smaller functions / methods.

    Too many branches (15/12)
    Confirmed

        def _store_data(self, rows, source, right_cells, covered, app):

    Used when a function or method has too many branches, making it hard to follow.

    Too many local variables (18/15)
    Confirmed

        def linking_via_intermediate(self, source_ids, targets_with_ids, collection):

    Used when a function or method has too many local variables.

    Too many local variables (45/15)
    Confirmed

        def perform_replacement(self, app, collection):

    Used when a function or method has too many local variables.

    Too many branches (34/12)
    Confirmed

        def perform_replacement(self, app, collection):

    Used when a function or method has too many branches, making it hard to follow.

    Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.
    Open

        def _store_data(self, rows, source, right_cells, covered, app):

    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.

    See

    Too many local variables (19/15)
    Confirmed

        def _store_data(self, rows, source, right_cells, covered, app):

    Used when a function or method has too many local variables.

    Formatting a regular string which could be a f-string
    Open

                        report_warning('Item-matrix with title {!r} has bad coverage: {} evaluates to False'

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                    expression = '{} {}'.format(percentage, self['coverage'])

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                    "Item-matrix directive should have the same number of values for the options 'target' and "

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                    "Item-matrix {!r} cannot combine 'targetcolumns' with more than one 'target'; "

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                    report_warning('Expected value for coverage option to fully match regex {}; got {!r}'

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                raise TraceabilityException("Type option of item-matrix must not contain more than one '|' "

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                raise TraceabilityException("The value of the :type: option contains the '|' character,  but the option "

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                disp = 'Statistics: {cover} out of {total} covered: {pct}%'.format(cover=count_covered,

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    Formatting a regular string which could be a f-string
    Open

                raise TraceabilityException("The :intermediate: option is used, expected at least two relationships "

    Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

    There are no issues that match your filters.

    Category
    Status