ComplianceAsCode/content

View on GitHub

Showing 229 of 962 total issues

Function preprocess has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

def preprocess(data, lang):
    data["zero_comparison_operation"] = data.get("zero_comparison_operation", None)

    if "greater" in data["operation"]:
        if data["zero_comparison_operation"]:
Severity: Minor
Found in shared/templates/accounts_password/template.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 main has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def main():
    parser = argparse.ArgumentParser(
        prog="add_kubernetes_rule.py",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=textwrap.dedent(PROG_DESC))
Severity: Minor
Found in utils/add_kubernetes_rule.py - About 1 hr to fix

    Function find_section_lines has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def find_section_lines(file_contents, sec):
        """
        Parses the given file_contents as YAML to find the section with the given identifier.
        Note that this does not call into the yaml library and thus correctly handles jinja
        macros at the expense of not being a strictly valid yaml parsing.
    Severity: Minor
    Found in ssg/rule_yaml.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 main has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def main():
        args = parse_args()
    
        disa_xccdftree = ET.parse(args.disa_xccdf_filename)
    
    
    Severity: Minor
    Found in utils/create-stig-overlay.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 handle_control has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    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:
        if len(control.selections) > 0 and use_rule_content(control, prefer_controls):
            rows = list()
    Severity: Minor
    Found in utils/create_srg_export.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 preprocess has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def preprocess(data, lang):
        data["sysctlid"] = ssg.utils.escape_id(data["sysctlvar"])
        if not data.get("sysctlval"):
            data["sysctlval"] = ""
        ipv6_flag = "P"
    Severity: Minor
    Found in shared/templates/sysctl/template.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_section_lines has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def find_section_lines(file_contents, sec):
        # Hack to find a global key ("section"/sec) in a YAML-like file.
        # All indented lines until the next global key are included in the range.
        # For example:
        #
    Severity: Minor
    Found in utils/fix_rules.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 normalize_passed_arguments has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def normalize_passed_arguments(options):
        targets = []
        for target in options.target:
            if ',' in target:
                targets.extend(target.split(","))
    Severity: Minor
    Found in tests/automatus.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 _subs has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
    Open

        def _subs(self, substitutions, default, simplify):
            """
            Return an expression where all subterms equal to a key expression are
            substituted by the corresponding value expression using a mapping of:
            {expr->expr to substitute.}
    Severity: Minor
    Found in ssg/ext/boolean/boolean.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 validate_identifiers has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
    Open

        def validate_identifiers(self, yaml_file):
            if self.identifiers is None:
                raise ValueError("Empty identifier section in file %s" % yaml_file)
    
            # Validate all identifiers are non-empty:
    Severity: Minor
    Found in ssg/build_yaml.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 _parse_parameters has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
    Open

        def _parse_parameters(self):
            """Parse parameters from script header"""
            params = {
                'profiles': [],
                'templates': [],
    Severity: Minor
    Found in tests/ssg_test_suite/rule.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 get_platform_rules has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def get_platform_rules(product, json_path, resolved_rules_dir, build_root):
        platform_rules = list()
        if resolved_rules_dir:
            rules_path = os.path.join(build_root, product, 'rules')
            for file in os.listdir(rules_path):
    Severity: Minor
    Found in utils/create_scap_delta_tailoring.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 expand_xccdf_subs has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def expand_xccdf_subs(fix, remediation_type):
        """Expand the respective populate keywords of each
        remediation type with an <xccdf:sub> element
    
        This routine translates any instance of the '`type`-populate' keyword in
    Severity: Minor
    Found in ssg/build_remediations.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 inject_package_facts_task has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

        def inject_package_facts_task(self, parsed_snippet):
            """ Injects a package_facts task only if
                the snippet has a task with a when clause with ansible_facts.packages,
                and the snippet doesn't already have a package_facts task
            """
    Severity: Minor
    Found in ssg/build_remediations.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 run_stage has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

        def run_stage(self, stage):
            self.stage = stage
    
            self._make_verbose_path()
            self._make_report_path()
    Severity: Minor
    Found in tests/ssg_test_suite/oscap.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 _get_rules_to_test has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

        def _get_rules_to_test(self):
            """
            Returns:
                List of named tuples Rule having these fields:
                    directory -- absolute path to the rule "tests" subdirectory
    Severity: Minor
    Found in tests/ssg_test_suite/rule.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 preprocess has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def preprocess(data, lang):
        ensure_file_paths_and_file_regexes_are_correctly_defined(data)
    
        data["allow_stricter_permissions"] = parse_template_boolean_value(data, parameter="allow_stricter_permissions", default_value=True)
    
    
    Severity: Minor
    Found in shared/templates/file_permissions/template.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 remove_section_keys has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def remove_section_keys(file_contents, yaml_contents, section, removed_keys):
        # Remove a series of keys from a section. Refuses to operate if there is more
        # than one instance of the section. If the section is empty (because all keys
        # are removed), then the section is also removed. Otherwise, only matching keys
        # are removed. Note that all instances of the keys will be removed, if it appears
    Severity: Minor
    Found in utils/fix_rules.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 compare_checks has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
    Open

        def compare_checks(self, old_rule, new_rule, system, identifier):
            check_system_uri = self.check_system_map[system]["uri"]
            old_check = old_rule.get_check_element(check_system_uri)
            new_check = new_rule.get_check_element(check_system_uri)
            if (old_check is None and new_check is not None):
    Severity: Minor
    Found in ssg/content_diff.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 process_input_dict has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
    Open

        def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
            """
            Take the contents of the definition as a dictionary, and
            add defaults or raise errors if a required member is not present.
    
    
    Severity: Minor
    Found in ssg/entities/common.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

    Severity
    Category
    Status
    Source
    Language