ComplianceAsCode/content

View on GitHub

Showing 1,039 of 1,039 total issues

Rename field "status"
Open

        self.status = status
Severity: Major
Found in ssg/controls.py by sonar-python

It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.

Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.

Noncompliant Code Example

class Foo:
  foo = ''

  def getFoo(self):
    ...

foo = Foo()
foo.getFoo() # what does this return?

Compliant Solution

class Foo:
  name = ''

  def getName(self):
    ...

foo = Foo()
foo.getName()

Merge this if statement with the enclosing one.
Open

            if file_contents[line_num][0:sec_len] == sec_id:
Severity: Major
Found in ssg/rule_yaml.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:
    # ...

Merge this if statement with the enclosing one.
Open

            if pkg_manager in PKG_MANAGER_TO_CONFIG_FILE:
Severity: Major
Found in ssg/products.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:
    # ...

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

def has_duplicated_subkeys(file_path, file_contents, sections):
Severity: Critical
Found in ssg/rule_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

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

    def simplify(self, sort=True):
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

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

def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, reference,
                    excludes, controls_manager=None):
Severity: Major
Found in utils/refchecker.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 23 to the 15 allowed.
Open

def move_patches_up_to_date_to_source_data_stream_component(datastreamtree):
Severity: Critical
Found in build-scripts/compose_ds.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

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

    def __init__(self, env_yaml, resolved_rules_dir, templates_dir,
                 remediations_dir, checks_dir, platforms_dir, cpe_items_dir):
Severity: Major
Found in ssg/templates.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 17 to the 15 allowed.
Open

def new_stig_overlay(xccdftree, ssgtree, outfile, quiet):
Severity: Critical
Found in utils/create-stig-overlay.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 "createNodeRuleFunc" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def createNodeRuleFunc(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):
    ...

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

def main():
Severity: Critical
Found in build-scripts/verify_references.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 27 to the 15 allowed.
Open

    def translate(self, tree, store_defname=False):
Severity: Critical
Found in ssg/id_translate.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 143 to the 15 allowed.
Open

    def parse(self, expr, simplify=False):
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 21 to the 15 allowed.
Open

def ssg_xccdf_stigid_mapping(ssgtree):
Severity: Critical
Found in utils/create-stig-overlay.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 not os.path.isdir(group_path):
Severity: Major
Found in utils/add_kubernetes_rule.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:
    # ...

Merge this if statement with the enclosing one.
Open

                if (disa_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:
    # ...

Merge this if statement with the enclosing one.
Open

                if re.search(ref_exp, ref.text):
Severity: Major
Found in ssg/build_derivatives.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:
    # ...

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

def get_profile_choices_for_input(input_tree, benchmark_id, tailoring_tree):
Severity: Critical
Found in ssg/xccdf.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 remove or fill this block of code.
Open

            pass
Severity: Major
Found in ssg/controls.py by sonar-python

Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

Noncompliant Code Example

for i in range(3):
    pass

Exceptions

When a block contains a comment, this block is not considered to be empty.

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

    def _start_operation(self, ast, operation, precedence):
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

Severity
Category
Status
Source
Language