codeclimate/codeclimate

View on GitHub

Showing 63 of 64 total issues

File html_formatter.rb has 322 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "redcarpet"

module CC
  module Analyzer
    module Formatters
Severity: Minor
Found in lib/cc/analyzer/formatters/html_formatter.rb - About 3 hrs to fix

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

          def run(options = [])
            started = Time.now
    
            command = docker_run_command(options)
            Analyzer.logger.debug("docker run: #{command.inspect}")
    Severity: Minor
    Found in lib/cc/analyzer/container.rb - About 1 hr to fix

      Method check_validity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

                def check_validity
                  if location["lines"]
                    self.error = "location.lines is not valid: #{JSON.dump(location["lines"])}" unless valid_lines?(location["lines"])
                  elsif location["positions"]
                    self.error = "location.positions is not valid: #{JSON.dump(location["positions"])}" unless valid_positions?(location["positions"])
      Severity: Minor
      Found in lib/cc/analyzer/issue_validations/location_format_validation.rb - About 55 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 upconvert_legacy_yaml! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def upconvert_legacy_yaml!
              config.delete("ratings")
      
              if config.key?("engines")
                config["plugins"] ||= config.delete("engines")
      Severity: Minor
      Found in lib/cc/config/yaml_adapter.rb - About 55 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 check has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def check
              return unless global_config.check_version? && version_check_is_due?
      
              print_new_version_message if outdated?
      
      
      Severity: Minor
      Found in lib/cc/cli/version_checker.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 validate_exclude_pattern has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def validate_exclude_pattern(key, legacy: false)
                types =
                  if legacy
                    [Array, String]
                  else
      Severity: Minor
      Found in lib/cc/config/validation/file_validator.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 validate_path has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def validate_path(path)
                if path.nil? || path.length.zero?
                  errors << "fetch section's 'path' cannot be empty"
                else
                  pathname = Pathname.new(path)
      Severity: Minor
      Found in lib/cc/config/validation/fetch_validator.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 run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def run
              formatter.started
      
              config.engines.each do |engine|
                next unless engine.enabled?
      Severity: Minor
      Found in lib/cc/analyzer/bridge.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 apply_default_engines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def apply_default_engines
              config["plugins"] ||= {}
      
              ENGINES.each do |name, channel|
                config["plugins"][name] ||= {}
      Severity: Minor
      Found in lib/cc/config/default_adapter.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

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

              def validate_key_type(key, types)
                if types.is_a?(Class)
                  return validate_key_type(key, [types])
                elsif data.key?(key)
                  unless types.include?(data[key].class)
      Severity: Minor
      Found in lib/cc/config/validation/hash_validations.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

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

            def to_offset(line, column, offset = 0)
              source.each_line.with_index do |source_line, index|
                offset +=
                  if line == index
                    column
      Severity: Minor
      Found in lib/cc/analyzer/source_extractor.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

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

              def remove(head = nil, *tail)
                return if head.nil? && tail.empty?
                populate_direct_children
      
                if (child = children[head])
      Severity: Minor
      Found in lib/cc/workspace/path_tree/dir_node.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

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

            def process_args
              while (arg = @args.shift)
                case arg
                when "-f", "--format"
                  @formatter = Formatters.resolve(@args.shift).new(filesystem)
      Severity: Minor
      Found in lib/cc/cli/analyze.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

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

              def key_type_error_message(key, types)
                if types.one?
                  klass_name = types[0].to_s.downcase
                  article =
                    if klass_name[0] == "a"
      Severity: Minor
      Found in lib/cc/config/validation/hash_validations.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

      When using method_missing, fall back on super.
      Open

            def method_missing(*)
              yield if block_given?
            end
      Severity: Minor
      Found in lib/cc/analyzer.rb by rubocop

      This cop checks for the presence of method_missing without falling back on super.

      Example:

      #bad
      def method_missing(name, *args)
        # ...
      end
      
      #good
      
      def method_missing(name, *args)
        # ...
        super
      end

      When using method_missing, fall back on super.
      Open

            def method_missing(*)
              yield if block_given?
            end
      Severity: Minor
      Found in lib/cc/analyzer.rb by rubocop

      This cop checks for the presence of method_missing without falling back on super.

      Example:

      #bad
      def method_missing(name, *args)
        # ...
      end
      
      #good
      
      def method_missing(name, *args)
        # ...
        super
      end

      Do not use empty case condition, instead use an if expression.
      Open

              case
      Severity: Minor
      Found in lib/cc/analyzer/issue_sorter.rb by rubocop

      This cop checks for case statements with an empty condition.

      Example:

      # bad:
      case
      when x == 0
        puts 'x is 0'
      when y == 0
        puts 'y is 0'
      else
        puts 'neither is 0'
      end
      
      # good:
      if x == 0
        puts 'x is 0'
      elsif y == 0
        puts 'y is 0'
      else
        puts 'neither is 0'
      end
      
      # good: (the case condition node is not empty)
      case n
      when 0
        puts 'zero'
      when 1
        puts 'one'
      else
        puts 'more'
      end

      Use double pipes || instead.
      Open

              if position["line"]
                position["line"]
              else
                @source_buffer.decompose_position(position["offset"]).first
              end

      This cop checks for unnecessary conditional expressions.

      Example:

      # bad
      a = b ? b : c
      
      # good
      a = b || c

      Example:

      # bad
      if b
        b
      else
        c
      end
      
      # good
      b || c
      
      # good
      if b
        b
      elsif cond
        c
      end

      Use e instead of ex.
      Open

            rescue => ex
      Severity: Minor
      Found in lib/cc/cli/runner.rb by rubocop

      This cop makes sure that rescued exceptions variables are named as expected.

      The PreferredName config option takes a String. It represents the required name of the variable. Its default is e.

      Example: PreferredName: e (default)

      # bad
      begin
        # do something
      rescue MyException => exception
        # do something
      end
      
      # good
      begin
        # do something
      rescue MyException => e
        # do something
      end

      Example: PreferredName: exception

      # bad
      begin
        # do something
      rescue MyException => e
        # do something
      end
      
      # good
      begin
        # do something
      rescue MyException => exception
        # do something
      end

      case condition requires an else-clause.
      Open

                case arg
                when "--registry" then @registry_path = @args.shift
                when "--registry-prefix" then @registry_prefix = @args.shift
                end
      Severity: Minor
      Found in lib/cc/cli/validate_config.rb by rubocop

      Checks for if expressions that do not have an else branch.

      Supported styles are: if, case, both.

      Example: EnforcedStyle: if

      # warn when an `if` expression is missing an `else` branch.
      
      # bad
      if condition
        statement
      end
      
      # good
      if condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end
      
      # good
      case var
      when condition
        statement
      end
      
      # good
      case var
      when condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end

      Example: EnforcedStyle: case

      # warn when a `case` expression is missing an `else` branch.
      
      # bad
      case var
      when condition
        statement
      end
      
      # good
      case var
      when condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end
      
      # good
      if condition
        statement
      end
      
      # good
      if condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end

      Example: EnforcedStyle: both (default)

      # warn when an `if` or `case` expression is missing an `else` branch.
      
      # bad
      if condition
        statement
      end
      
      # bad
      case var
      when condition
        statement
      end
      
      # good
      if condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end
      
      # good
      case var
      when condition
        statement
      else
        # the content of `else` branch will be determined by Style/EmptyElse
      end
      Severity
      Category
      Status
      Source
      Language