metanorma/metanorma-utils

View on GitHub

Showing 8 of 8 total issues

Method current_location has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

      def current_location(node)
        if node.nil? then ""
        elsif node.respond_to?(:id) && !node.id.nil? then "ID #{node.id}"
        elsif node.respond_to?(:id) && node.id.nil? && node.respond_to?(:parent)
          while !node.nil? && node.id.nil?
Severity: Minor
Found in lib/utils/log.rb - About 4 hrs 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

Method set_nested_value has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

      def set_nested_value(hash, keys, new_val)
        key = keys[0]
        if keys.length == 1
          hash[key] = if hash[key].is_a?(::Array) then (hash[key] << new_val)
                      else hash[key].nil? ? new_val : [hash[key], new_val]
Severity: Minor
Found in lib/utils/main.rb - About 3 hrs 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

Method current_location has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def current_location(node)
        if node.nil? then ""
        elsif node.respond_to?(:id) && !node.id.nil? then "ID #{node.id}"
        elsif node.respond_to?(:id) && node.id.nil? && node.respond_to?(:parent)
          while !node.nil? && node.id.nil?
Severity: Minor
Found in lib/utils/log.rb - About 1 hr to fix

    Method break_up_long_str has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def break_up_long_str(text, threshold = LONGSTR_THRESHOLD, nopunct = LONGSTR_NOPUNCT)
            /^\s*$/.match?(text) and return text
            text.split(/(?=(?:\s|-))/).map do |w|
              if /^\s*$/.match(text) || (w.size < threshold) then w
              else
    Severity: Minor
    Found in lib/utils/main.rb - 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

    Avoid deeply nested control flow statements.
    Open

                return "Section: #{node.title}" if node.respond_to?(:context) &&
                  node&.context == :section
    Severity: Major
    Found in lib/utils/log.rb - About 45 mins to fix

      Method to_ncname has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def to_ncname(tag, asciionly: true)
              asciionly and tag = HTMLEntities.new.encode(tag, :basic,
                                                          :hexadecimal)
              start = tag[0]
              ret1 = if %r([#{NAMECHAR}#])o.match?(start)
      Severity: Minor
      Found in lib/utils/xml.rb - About 35 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

      Method deep_merge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def deep_merge(second)
              merger = proc { |_, v1, v2|
                if ::Hash === v1 && ::Hash === v2
                  v1.merge(v2, &merger)
                elsif ::Array === v1 && ::Array === v2
      Severity: Minor
      Found in lib/utils/hash_transform_keys.rb - About 35 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

      Method external_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def external_path(path)
              win = !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) ||
                       (RUBY_PLATFORM =~ /mswin|mingw/))
              if win
                path.gsub!(%{/}, "\\")
      Severity: Minor
      Found in lib/utils/main.rb - About 25 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