cloudamatic/mu

View on GitHub
modules/mu/config/doc_helpers.rb

Summary

Maintainability
C
1 day
Test Coverage

Assignment Branch Condition size for printSchema is too high. [218/75]
Open

    def self.printSchema(kitten_rb, class_hierarchy, schema, in_array = false, required = false, prefix: nil)
      return if schema.nil?

      if schema["type"] == "object"
        printme = []
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for docSchema is too high. [154.9/75]
Open

    def self.docSchema
      docschema = Marshal.load(Marshal.dump(@@schema))
      only_children = {}
      MU::Cloud.resource_types.each_pair { |classname, attrs|
        MU::Cloud.supportedClouds.each { |cloud|
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method printSchema has a Cognitive Complexity of 135 (exceeds 75 allowed). Consider refactoring.
Open

    def self.printSchema(kitten_rb, class_hierarchy, schema, in_array = false, required = false, prefix: nil)
      return if schema.nil?

      if schema["type"] == "object"
        printme = []
Severity: Minor
Found in modules/mu/config/doc_helpers.rb - About 1 day 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

Assignment Branch Condition size for printMuYamlSchema is too high. [130.3/75]
Open

    def self.printMuYamlSchema(muyaml_rb, class_hierarchy, schema, in_array = false, required = false)
      return if schema.nil?
      if schema["subtree"]
        printme = Array.new
        # order sub-elements by whether they're required, so we can use YARD's
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for printSchema is too high. [52/35]
Open

    def self.printSchema(kitten_rb, class_hierarchy, schema, in_array = false, required = false, prefix: nil)
      return if schema.nil?

      if schema["type"] == "object"
        printme = []
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for printSchema is too high. [45/30]
Open

    def self.printSchema(kitten_rb, class_hierarchy, schema, in_array = false, required = false, prefix: nil)
      return if schema.nil?

      if schema["type"] == "object"
        printme = []
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for printMuYamlSchema is too high. [31/30]
Open

    def self.printMuYamlSchema(muyaml_rb, class_hierarchy, schema, in_array = false, required = false)
      return if schema.nil?
      if schema["subtree"]
        printme = Array.new
        # order sub-elements by whether they're required, so we can use YARD's
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for printMuYamlSchema is too high. [36/35]
Open

    def self.printMuYamlSchema(muyaml_rb, class_hierarchy, schema, in_array = false, required = false)
      return if schema.nil?
      if schema["subtree"]
        printme = Array.new
        # order sub-elements by whether they're required, so we can use YARD's
Severity: Minor
Found in modules/mu/config/doc_helpers.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Avoid deeply nested control flow statements.
Open

                if File.exist?(example_path)
                  example = "#\n# Examples:\n#\n"
                  # XXX these variables are all parameters from the BoKs in
                  # modules/tests. A really clever implementation would read
                  # and parse them to get default values, perhaps, instead of
Severity: Major
Found in modules/mu/config/doc_helpers.rb - About 45 mins to fix

    Avoid too many return statements within this method.
    Open

            return docstring
    Severity: Major
    Found in modules/mu/config/doc_helpers.rb - About 30 mins to fix

      Avoid more than 4 levels of block nesting.
      Open

                      if File.exist?(example_path)
                        example = "#\n# Examples:\n#\n"
                        # XXX these variables are all parameters from the BoKs in
                        # modules/tests. A really clever implementation would read
                        # and parse them to get default values, perhaps, instead of
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks for excessive nesting of conditional and looping constructs.

      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

      The maximum level of nesting allowed is configurable.

      Use each_value instead of values.each.
      Open

              MU::Cloud.resource_types.values.each { |attrs|
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks for uses of each_key and each_value Hash methods.

      Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

      Example:

      # bad
      hash.keys.each { |k| p k }
      hash.values.each { |v| p v }
      hash.each { |k, _v| p k }
      hash.each { |_k, v| p v }
      
      # good
      hash.each_key { |k| p k }
      hash.each_value { |v| p v }

      Use =~ in places where the MatchData returned by #match will not be used.
      Open

                    docschema["properties"][attrs[:cfg_plural]]["items"]["properties"][key]["description"] += "\n"+(cfg["description"].match(/^#/) ? "" : "# ")+cfg["description"]
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

      Example:

      # bad
      do_something if str.match(/regex/)
      while regex.match('str')
        do_something
      end
      
      # good
      method(str =~ /regex/)
      return value unless regex =~ 'str'

      Use each_key instead of keys.each.
      Open

                cfg["properties"].keys.each { |key|
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks for uses of each_key and each_value Hash methods.

      Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

      Example:

      # bad
      hash.keys.each { |k| p k }
      hash.values.each { |v| p v }
      hash.each { |k, _v| p k }
      hash.each { |_k, v| p v }
      
      # good
      hash.each_key { |k| p k }
      hash.each_value { |v| p v }

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

              printme.each { |lines|
                if !lines.nil? and lines.is_a?(String)
                  lines.lines.each { |line|
                    muyaml_rb.puts ["\t"].cycle(tabs).to_a.join('') + line
                  }
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb and 1 other location - About 20 mins to fix
      modules/mu/config/doc_helpers.rb on lines 310..315

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

      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

              printme.each { |lines|
                if !lines.nil? and lines.is_a?(String)
                  lines.lines.each { |line|
                    kitten_rb.puts ["\t"].cycle(tabs).to_a.join('') + line
                  }
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb and 1 other location - About 20 mins to fix
      modules/mu/config/doc_helpers.rb on lines 436..441

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

      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

      end at 481, 8 is not aligned with if at 477, 15.
      Open

              end
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks whether the end keywords are aligned properly.

      Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

      If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

      If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

      If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

      Example: EnforcedStyleAlignWith: keyword (default)

      # bad
      
      variable = if true
          end
      
      # good
      
      variable = if true
                 end

      Example: EnforcedStyleAlignWith: variable

      # bad
      
      variable = if true
          end
      
      # good
      
      variable = if true
      end

      Example: EnforcedStyleAlignWith: startofline

      # bad
      
      variable = if true
          end
      
      # good
      
      puts(if true
      end)

      The use of eval is a serious security risk.
      Open

            mu_yaml_schema = eval(%Q{
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks for the use of Kernel#eval and Binding#eval.

      Example:

      # bad
      
      eval(something)
      binding.eval(something)

      Redundant use of Object#to_s in interpolation.
      Open

                    MU.log "Munging #{cloud}-specific #{classname.to_s} schema into BasketofKittens => #{attrs[:cfg_plural]} => #{key}", MU::DEBUG, details: docschema["properties"][attrs[:cfg_plural]]["items"]["properties"][key]
      Severity: Minor
      Found in modules/mu/config/doc_helpers.rb by rubocop

      This cop checks for string conversion in string interpolation, which is redundant.

      Example:

      # bad
      
      "result is #{something.to_s}"

      Example:

      # good
      
      "result is #{something}"

      There are no issues that match your filters.

      Category
      Status