codeclimate/codeclimate

View on GitHub

Showing 64 of 65 total issues

File html_formatter.rb has 318 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 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_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 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 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 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 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 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 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

      Prefer {...} over do...end for functional blocks.
      Open

                      data.fetch("other_locations", []).map do |loc|

      Check for uses of braces or do/end around single line or multi-line blocks.

      Example: EnforcedStyle: linecountbased (default)

      # bad - single line block
      items.each do |item| item / 5 end
      
      # good - single line block
      items.each { |item| item / 5 }
      
      # bad - multi-line block
      things.map { |thing|
        something = thing.some_method
        process(something)
      }
      
      # good - multi-line block
      things.map do |thing|
        something = thing.some_method
        process(something)
      end

      Example: EnforcedStyle: semantic

      # Prefer `do...end` over `{...}` for procedural blocks.
      
      # return value is used/assigned
      # bad
      foo = map do |x|
        x
      end
      puts (map do |x|
        x
      end)
      
      # return value is not used out of scope
      # good
      map do |x|
        x
      end
      
      # Prefer `{...}` over `do...end` for functional blocks.
      
      # return value is not used out of scope
      # bad
      each { |x|
        x
      }
      
      # return value is used/assigned
      # good
      foo = map { |x|
        x
      }
      map { |x|
        x
      }.inspect
      
      # The AllowBracesOnProceduralOneLiners option is ignored unless the
      # EnforcedStyle is set to `semantic`. If so:
      
      # If the AllowBracesOnProceduralOneLiners option is unspecified, or
      # set to `false` or any other falsey value, then semantic purity is
      # maintained, so one-line procedural blocks must use do-end, not
      # braces.
      
      # bad
      collection.each { |element| puts element }
      
      # good
      collection.each do |element| puts element end
      
      # If the AllowBracesOnProceduralOneLiners option is set to `true`, or
      # any other truthy value, then one-line procedural blocks may use
      # either style. (There is no setting for requiring braces on them.)
      
      # good
      collection.each { |element| puts element }
      
      # also good
      collection.each do |element| puts element end

      Example: EnforcedStyle: bracesforchaining

      # bad
      words.each do |word|
        word.flip.flop
      end.join("-")
      
      # good
      words.each { |word|
        word.flip.flop
      }.join("-")

      Example: EnforcedStyle: always_braces

      # bad
      words.each do |word|
        word.flip.flop
      end
      
      # good
      words.each { |word|
        word.flip.flop
      }

      Example: BracesRequiredMethods: ['sig']

      # Methods listed in the BracesRequiredMethods list, such as 'sig'
      # in this example, will require `{...}` braces. This option takes
      # precedence over all other configurations except IgnoredMethods.
      
      # bad
      sig do
        params(
          foo: string,
        ).void
      end
      def bar(foo)
        puts foo
      end
      
      # good
      sig {
        params(
          foo: string,
        ).void
      }
      def bar(foo)
        puts foo
      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
      
      # 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
      
      # good
      begin
        # do something
      rescue MyException => _exception
        # do something
      end

      Add empty line after guard clause.
      Open

              return unless checks.present?
      Severity: Minor
      Found in lib/cc/config/checks_adapter.rb by rubocop

      This cop enforces empty line after guard clause

      Example:

      # bad
      def foo
        return if need_return?
        bar
      end
      
      # good
      def foo
        return if need_return?
      
        bar
      end
      
      # good
      def foo
        return if something?
        return if something_different?
      
        bar
      end
      
      # also good
      def foo
        if something?
          do_something
          return if need_return?
        end
      end

      Line length
      Open

        are currently installed, then installs any missing engines and checks for new images available for existing engines.
      Severity: Info
      Found in README.md by markdownlint

      MD013 - Line length

      Tags: line_length

      Aliases: line-length Parameters: linelength, codeblocks, tables (number; default 80, boolean; default true)

      This rule is triggered when there are lines that are longer than the configured line length (default: 80 characters). To fix this, split the line up into multiple lines.

      This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.

      You also have the option to exclude this rule for code blocks and tables. To do this, set the code_blocks and/or tables parameters to false.

      Code blocks are included in this rule by default since it is often a requirement for document readability, and tentatively compatible with code rules. Still, some languages do not lend themselves to short lines.

      Use single quotes, otherwise this expands now rather than when signalled.
      Open

          trap "rm -rf '$tmp_source_dir'" EXIT
      Severity: Minor
      Found in codeclimate-wrapper by shellcheck

      Use single quotes, otherwise this expands now rather than when signalled.

      Problematic code:

      trap "echo \"Finished on $(date)\"" EXIT

      Correct code:

      trap 'echo "Finished on $(date)"' EXIT

      Rationale:

      With double quotes, all parameter and command expansions will expand when the trap is defined rather than when it's executed.

      In the example, the message will contain the date on which the trap was declared, and not the date on which the script exits.

      Using single quotes will prevent expansion at declaration time, and save it for execution time.

      Exceptions

      If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message.

      Notice

      Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

      Put empty method definitions on a single line.
      Open

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