ComplianceAsCode/content

View on GitHub

Showing 1,039 of 1,039 total issues

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

def clusterTestFunc(args):
Severity: Critical
Found in utils/add_kubernetes_rule.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

Rename function "testFunc" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def testFunc(args):
Severity: Major
Found in utils/add_kubernetes_rule.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Merge this if statement with the enclosing one.
Open

        if os.path.isdir(language_fixes_from_templates_dir):

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

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

def add_reference_elements(element, references, ref_uri_dict):
Severity: Critical
Found in ssg/build_yaml.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

Either merge this branch with the identical one on line "57" or change one of the implementations.
Open

                value = list(options.values())[0]
Severity: Major
Found in ssg/playbook_builder.py by sonar-python

Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

Noncompliant Code Example

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_thing()  # Noncompliant; duplicates first condition
else:
    do_the_rest()

b = 4 if a > 12 else 4

Compliant Solution

if (0 <= a < 10) or (20 <= a < 50):
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
else:
    do_the_rest()

b = 4

or

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_third_thing()
else:
    do_the_rest()

b = 8 if a > 12 else 4

Merge this if statement with the enclosing one.
Open

                    if prev_token_type not in (TOKEN_NOT, TOKEN_AND, TOKEN_OR, TOKEN_LPAR):
Severity: Major
Found in ssg/ext/boolean/boolean.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Function "handle_control" has 8 parameters, which is greater than the 7 authorized.
Open

def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
                   rule_json: dict, srgs: dict, used_rules: list, root_path: str,
                   prefer_controls: bool) -> list:
Severity: Major
Found in utils/create_srg_export.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

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

def createPlatformRuleFunc(args):
Severity: Critical
Found in utils/add_kubernetes_rule.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

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

def remove_idents(tree_root, namespace, prod="RHEL"):
Severity: Critical
Found in ssg/build_derivatives.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

Merge this if statement with the enclosing one.
Open

            if self.is_benchmark():
Severity: Major
Found in ssg/xml.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Method "__init__" has 8 parameters, which is greater than the 7 authorized.
Open

    def __init__(self, old_content, new_content, rule_id, show_diffs, rule_diffs,
                 only_rules, output_dir):
Severity: Major
Found in ssg/content_diff.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

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

    def show_profile_stats(self, profile, options):
Severity: Critical
Found in ssg/build_profile.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

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

    def _subs(self, substitutions, default, simplify):
Severity: Critical
Found in ssg/ext/boolean/boolean.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

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

    def absorb(self, args):
Severity: Critical
Found in ssg/ext/boolean/boolean.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

Rename function "createTestProfile" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def createTestProfile(rule):
Severity: Major
Found in utils/add_kubernetes_rule.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Method "__init__" has 9 parameters, which is greater than the 7 authorized.
Open

    def __init__(self, TRUE_class=None, FALSE_class=None, Symbol_class=None, Function_class=None,
                 NOT_class=None, AND_class=None, OR_class=None,
                 allowed_in_token=('.', ':', '_')):
Severity: Major
Found in ssg/ext/boolean/boolean.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

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

    def tokenize(self, expr):
Severity: Critical
Found in ssg/ext/boolean/boolean.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

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

def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
Severity: Critical
Found in utils/create_srg_export.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

Merge this if statement with the enclosing one.
Open

                if (nist_ref_href in ref_href_list) and (rule.get("id") not in profile_ruleids):

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

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

    def _collect_items_to_load(self, guide_directory):
Severity: Critical
Found in ssg/build_yaml.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

Severity
Category
Status
Source
Language