ComplianceAsCode/content

View on GitHub
ssg/rule_dir_stats.py

Summary

Maintainability
D
2 days
Test Coverage
F
18%

Function walk_rules_parallel has a Cognitive Complexity of 23 (exceeds 7 allowed). Consider refactoring.
Open

def walk_rules_parallel(args, left_rules, right_rules, oval_func, remediation_func):
    """
    Walks two sets of known_rules (left_rules and right_rules) with identical
    keys and returns left_only, right_only, and common_only output from
    _walk_rule. If the outputted data for a rule when called on left_rules and
Severity: Minor
Found in ssg/rule_dir_stats.py - About 2 hrs 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 _walk_rule has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
Open

def _walk_rule(args, rule_obj, oval_func, remediation_func, verbose_output):
    """
    Walks a single rule and updates verbose_output if visited. Returns visited
    state as a boolean.

Severity: Minor
Found in ssg/rule_dir_stats.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 walk_rules_parallel has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

def walk_rules_parallel(args, left_rules, right_rules, oval_func, remediation_func):
Severity: Minor
Found in ssg/rule_dir_stats.py - About 35 mins to fix

    Function _walk_rule has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _walk_rule(args, rule_obj, oval_func, remediation_func, verbose_output):
    Severity: Minor
    Found in ssg/rule_dir_stats.py - About 35 mins to fix

      Function walk_rules_diff has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def walk_rules_diff(args, left_rules, right_rules, oval_func, remediation_func):
      Severity: Minor
      Found in ssg/rule_dir_stats.py - About 35 mins to fix

        Function product_names_remediation has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
        Open

        def product_names_remediation(rule_obj, r_type):
            """
            For a rule_obj, check the scope of the platforms versus the product name
            of the remediations of type r_type.
            """
        Severity: Minor
        Found in ssg/rule_dir_stats.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 filter_rule_ids has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
        Open

        def filter_rule_ids(all_keys, queries):
            """
            From a set of queries (a comma separated list of queries, where a query is either a
            rule id or a substring thereof), return the set of matching keys from all_keys. When
            queries is the literal string "all", return all of the keys.
        Severity: Minor
        Found in ssg/rule_dir_stats.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 product_names_oval has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
        Open

        def product_names_oval(rule_obj):
            """
            For a rule_obj, check the scope of the platforms versus the product name
            of the OVAL objects.
            """
        Severity: Minor
        Found in ssg/rule_dir_stats.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

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

        def walk_rules_parallel(args, left_rules, right_rules, oval_func, remediation_func):
        Severity: Critical
        Found in ssg/rule_dir_stats.py by sonar-python

        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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                for rule_id in sorted(verbose_output):
                    rule_output = verbose_output[rule_id]
                    _results = walk_rule_stats(rule_output)
        
                    affected_ovals += _results[0]
        Severity: Major
        Found in ssg/rule_dir_stats.py and 1 other location - About 7 hrs to fix
        ssg/rule_dir_stats.py on lines 182..192

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 121.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            for rule_id in sorted(verbose_output):
                rule_output = verbose_output[rule_id]
                results = walk_rule_stats(rule_output)
        
                affected_ovals += results[0]
        Severity: Major
        Found in ssg/rule_dir_stats.py and 1 other location - About 7 hrs to fix
        ssg/rule_dir_stats.py on lines 316..326

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 121.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Line too long (104 > 99 characters)
        Open

                        return "\trule_id:%s has a different product and %s remediation names: %s is not %s" % \
        Severity: Minor
        Found in ssg/rule_dir_stats.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        There are no issues that match your filters.

        Category
        Status