codeclimate/codeclimate

View on GitHub

Showing 72 of 73 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_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 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 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 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

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

      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

      #to_json requires an optional argument to be parsable via JSON.generate(obj).
      Open

            def to_json
              if issue?
                as_issue.to_json
              elsif measurement?
                Measurement.new(name, raw_output).to_json
      Severity: Minor
      Found in lib/cc/analyzer/engine_output.rb by rubocop

      This cop checks to make sure #to_json includes an optional argument. When overriding #to_json, callers may invoke JSON generation via JSON.generate(your_obj). Since JSON#generate allows for an optional argument, your method should too.

      Example:

      # bad
      def to_json
      end
      
      # good
      def to_json(*_args)
      end

      Put empty method definitions on a single line.
      Open

              def failed(_output)
              end

      This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

      Note: A method definition is not considered empty if it contains comments.

      Example: EnforcedStyle: compact (default)

      # bad
      def foo(bar)
      end
      
      def self.foo(bar)
      end
      
      # good
      def foo(bar); end
      
      def foo(bar)
        # baz
      end
      
      def self.foo(bar); end

      Example: EnforcedStyle: expanded

      # bad
      def foo(bar); end
      
      def self.foo(bar); end
      
      # good
      def foo(bar)
      end
      
      def self.foo(bar)
      end

      Variable value used in void context.
      Open

              value
      Severity: Minor
      Found in lib/cc/cli/global_cache.rb by rubocop

      This cop checks for operators, variables, literals, and nonmutating methods used in void context.

      Example:

      # bad
      
      def some_method
        some_num * 10
        do_something
      end

      Example:

      # bad
      
      def some_method(some_var)
        some_var
        do_something
      end

      Example:

      # bad, when CheckForMethodsWithNoSideEffects is set true
      
      def some_method(some_array)
        some_array.sort
        do_something(some_array)
      end

      Example:

      # good
      
      def some_method
        do_something
        some_num * 10
      end

      Example:

      # good
      
      def some_method(some_var)
        do_something
        some_var
      end

      Example:

      # good, when CheckForMethodsWithNoSideEffects is set true
      
      def some_method(some_array)
        some_array.sort!
        do_something(some_array)
      end

      When using method_missing, define respond_to_missing?.
      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 also defining respond_to_missing?.

      Example:

      #bad
      def method_missing(name, *args)
        # ...
      end
      
      #good
      def respond_to_missing?(name, include_private)
        # ...
      end
      
      def method_missing(name, *args)
        # ...
      end

      Put empty method definitions on a single line.
      Open

              def started
              end

      This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

      Note: A method definition is not considered empty if it contains comments.

      Example: EnforcedStyle: compact (default)

      # bad
      def foo(bar)
      end
      
      def self.foo(bar)
      end
      
      # good
      def foo(bar); end
      
      def foo(bar)
        # baz
      end
      
      def self.foo(bar); end

      Example: EnforcedStyle: expanded

      # bad
      def foo(bar); end
      
      def self.foo(bar); end
      
      # good
      def foo(bar)
      end
      
      def self.foo(bar)
      end
      Severity
      Category
      Status
      Source
      Language