ComplianceAsCode/content

View on GitHub

Showing 1,039 of 1,039 total issues

Function create_tailoring has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
Open

def create_tailoring(args):
    benchmark_root = ET.parse(args.manual).getroot()
    known_rules = get_implemented_stigs(args.product, args.root, args.build_config_yaml,
                                        args.reference, args.json, args.resolved_rules_dir,
                                        args.build_root)
Severity: Minor
Found in utils/create_scap_delta_tailoring.py - About 45 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

Avoid deeply nested control flow statements.
Open

                        if negated is None:
                            negated = arg
                        else:
                            negated = None
                            break
Severity: Major
Found in ssg/ext/boolean/boolean.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if arg in target.args:
                                pass
                            elif narg in target.args:
                                if remove is None:
                                    remove = narg
    Severity: Major
    Found in ssg/ext/boolean/boolean.py - About 45 mins to fix

      Function which has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
      Open

      def which(program):
          fpath, fname = os.path.split(program)
          if fpath:
              if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
                  return program
      Severity: Minor
      Found in utils/add_kubernetes_rule.py - About 45 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 remove_cce_reference has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
      Open

      def remove_cce_reference(tree_root, namespace):
          """
          Remove CCE identifiers from OVAL checks in XML tree
          """
          for definition in tree_root.findall(".//{%s}definition" % (namespace)):
      Severity: Minor
      Found in ssg/build_derivatives.py - About 45 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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, product_yaml_path, input_dir, output_dir, rules_dir, profiles_dir,
      Severity: Minor
      Found in ssg/playbook_builder.py - About 45 mins to fix

        Function get_all_resolved_profiles_by_id has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def get_all_resolved_profiles_by_id(
        Severity: Minor
        Found in build-scripts/compile_all.py - About 45 mins to fix

          Function get_profileruleids has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def get_profileruleids(xccdftree, profile_name):
              ruleids = []
          
              while profile_name:
                  profile = None
          Severity: Minor
          Found in build-scripts/verify_references.py - About 45 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 get_rule_dir_sces has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def get_rule_dir_sces(dir_path, product=None):
              """
              Get a list of SCEs contained in a rule directory.
          
              Only returns SCEs which exist.
          Severity: Minor
          Found in ssg/rules.py - About 45 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 shorten_relevant_ref has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def shorten_relevant_ref(ref_format, ref):
              match = re.match(ref_format, ref)
              if match:
                  groups = []
                  for refpart in match.groups():
          Severity: Minor
          Found in utils/tables/table_renderer.py - About 45 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

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

              if lang == "oval":
                  # replace . with _, this is used in test / object / state ids
                  data["sanitized_arg_name"] = ssg.utils.escape_id(data["arg_name"])
          Severity: Minor
          Found in shared/templates/grub2_bootloader_argument_absent/template.py and 1 other location - About 45 mins to fix
          shared/templates/mount_option_remote_filesystems/template.py on lines 14..15

          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 35.

          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 sub_elem in sub_elems:
                          sub_elem.tail = re.sub(r"[\s]+- CCE-.*", "", sub_elem.tail)
                          sub_elem.tail = re.sub(r"CCE-[0-9]*-[0-9]*", "", sub_elem.tail)
          Severity: Minor
          Found in ssg/build_derivatives.py and 1 other location - About 45 mins to fix
          ssg/build_derivatives.py on lines 174..176

          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 35.

          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

                  variables = set(
                      filter(lambda id_, ids=variables_ids_list: id_ not in ids, self.values.keys())
          Severity: Minor
          Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
          ssg/build_yaml.py on lines 838..838

          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 35.

          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

                          if not data['allow_stricter_permissions']:
                              mode_str = (
                                  "<unix:" + field + " datatype=\"boolean\">true</unix:"
                                  + field + ">\n" + mode_str)
          Severity: Minor
          Found in shared/templates/file_permissions/template.py and 1 other location - About 45 mins to fix
          shared/templates/file_permissions/template.py on lines 61..69

          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 35.

          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

          Function has_invalid_cce has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def has_invalid_cce(rule_path, rule, rule_lines):
              if 'identifiers' in rule and rule['identifiers'] is not None:
                  for i_type, i_value in rule['identifiers'].items():
                      if i_type[0:3] == 'cce':
                          if not cce.is_cce_value_valid("CCE-" + str(i_value)):
          Severity: Minor
          Found in utils/fix_rules.py - About 45 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 fix_file_prompt has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def fix_file_prompt(path, product_yaml, func, args):
              file_contents = open(path, 'r').read().split("\n")
          
              new_file_contents = _fixed_file_contents(path, file_contents, product_yaml, func)
              changes = file_contents != new_file_contents
          Severity: Minor
          Found in utils/fix_rules.py - About 45 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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(
          Severity: Minor
          Found in utils/oscal/cd_generator.py - About 45 mins to fix

            Function fix_prefix_cce has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
            Open

            def fix_prefix_cce(file_contents, yaml_contents):
                section = 'identifiers'
            
                prefixed_identifiers = []
            
            
            Severity: Minor
            Found in utils/fix_rules.py - About 45 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

            Avoid deeply nested control flow statements.
            Open

                                if len(file_contents[line_num]) > 0 and file_contents[line_num][0] != ' ':
                                    break
                                line_num += 1
            Severity: Major
            Found in utils/fix_rules.py - About 45 mins to fix

              Function add_platform_to_benchmark has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
              Open

              def add_platform_to_benchmark(root, cpe_regex):
                  benchmark_query = ".//ds:component/xccdf-1.2:Benchmark"
                  benchmarks = root.findall(benchmark_query, PREFIX_TO_NS)
                  if not benchmarks:
                      msg = (
              Severity: Minor
              Found in tests/ssg_test_suite/xml_operations.py - About 45 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

              Severity
              Category
              Status
              Source
              Language