codeclimate/codeclimate

View on GitHub

Showing 96 of 98 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 28 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 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_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 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 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 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

      Use %i or %I for an array of symbols.
      Open

                Kernel.system("docker", "kill", @name, [:out, :err] => File::NULL)
      Severity: Minor
      Found in lib/cc/analyzer/container.rb by rubocop

      Checks for array literals made up of symbols that are not using the %i() syntax.

      Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax, perhaps because they support a version of Ruby lower than 2.0.

      Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

      Example: EnforcedStyle: percent (default)

      # good
      %i[foo bar baz]
      
      # bad
      [:foo, :bar, :baz]

      Example: EnforcedStyle: brackets

      # good
      [:foo, :bar, :baz]
      
      # bad
      %i[foo bar baz]

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

                  collection.flat_map do |issue|

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

      Methods that can be either procedural or functional and cannot be categorised from their usage alone is ignored. lambda, proc, and it are their defaults. Additional methods can be added to the IgnoredMethods.

      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

      Example: IgnoredMethods: ['lambda', 'proc', 'it' ] (default)

      # good
      foo = lambda do |x|
        puts "Hello, #{x}"
      end
      
      foo = lambda do |x|
        x * 100
      end

      Omit the hash value.
      Open

                  channel: channel,
      Severity: Minor
      Found in lib/cc/cli/analyze.rb by rubocop

      Checks hash literal syntax.

      It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

      A separate offense is registered for each problematic pair.

      The supported styles are:

      • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
      • hash_rockets - forces use of hash rockets for all hashes
      • nomixedkeys - simply checks for hashes with mixed syntaxes
      • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

      This cop has EnforcedShorthandSyntax option. It can enforce either the use of the explicit hash value syntax or the use of Ruby 3.1's hash value shorthand syntax.

      The supported styles are:

      • always - forces use of the 3.1 syntax (e.g. {foo:})
      • never - forces use of explicit hash literal value
      • either - accepts both shorthand and explicit use of hash literal value

      Example: EnforcedStyle: ruby19 (default)

      # bad
      {:a => 2}
      {b: 1, :c => 2}
      
      # good
      {a: 2, b: 1}
      {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
      {d: 1, 'e' => 2} # technically not forbidden

      Example: EnforcedStyle: hash_rockets

      # bad
      {a: 1, b: 2}
      {c: 1, 'd' => 5}
      
      # good
      {:a => 1, :b => 2}

      Example: EnforcedStyle: nomixedkeys

      # bad
      {:a => 1, b: 2}
      {c: 1, 'd' => 2}
      
      # good
      {:a => 1, :b => 2}
      {c: 1, d: 2}

      Example: EnforcedStyle: ruby19nomixed_keys

      # bad
      {:a => 1, :b => 2}
      {c: 2, 'd' => 3} # should just use hash rockets
      
      # good
      {a: 1, b: 2}
      {:c => 3, 'd' => 4}

      Example: EnforcedShorthandSyntax: always (default)

      # bad
      {foo: foo, bar: bar}
      
      # good
      {foo:, bar:}

      Example: EnforcedShorthandSyntax: never

      # bad
      {foo:, bar:}
      
      # good
      {foo: foo, bar: bar}

      Example: EnforcedShorthandSyntax: either

      # good
      {foo: foo, bar: bar}
      
      # good
      {foo:, bar:}

      Variable value used in void context.
      Open

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

      Checks for operators, variables, literals, and nonmutating methods used in void context.

      Example: CheckForMethodsWithNoSideEffects: false (default)

      # bad
      def some_method
        some_num * 10
        do_something
      end
      
      def some_method(some_var)
        some_var
        do_something
      end

      Example: CheckForMethodsWithNoSideEffects: true

      # bad
      def some_method(some_array)
        some_array.sort
        do_something(some_array)
      end
      
      # good
      def some_method
        do_something
        some_num * 10
      end
      
      def some_method(some_var)
        do_something
        some_var
      end
      
      def some_method(some_array)
        some_array.sort!
        do_something(some_array)
      end

      Add empty line after guard clause.
      Open

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

      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

      Expressions don't expand in single quotes, use double quotes for that.
      Open

          'test -n "$DOCKER_HOST" -a "$DOCKER_HOST" != "unix:///var/run/docker.sock"' > /dev/null 2>&1 \
      Severity: Minor
      Found in codeclimate-wrapper by shellcheck

      Expressions don't expand in single quotes, use double quotes for that.

      Problematic code:

      name=World
      echo 'Hello $name'

      Correct code:

      name=World
      echo "Hello $name"

      Rationale:

      Single quotes prevent expansion of everything, including variables and command substitution.

      If you want to use the values of variables and such, use double quotes instead.

      Note that if you have other items that needs single quoting, you can use both in a single word:

      echo '$1 USD is '"$rate GBP"

      Exceptions

      If you want $stuff to be a literal dollar sign followed by the characters "stuff", you can [[ignore]] this message.

      ShellCheck tries to be smart about it, and won't warn when this is used with awk, perl and similar, but there are some inherent ambiguities like 'I have $1 in my wallet', which could be "one dollar" or "whatever's in the first parameter".

      In the particular case of sed, ShellCheck uses additional heuristics to try to separate cases like 's/$foo/bar/' (failing to replace the variable $foo) with from the false positives like '$d' (delete last line). If you're still triggering these, consider being more generous with your spaces: use $ { s/foo/bar; } instead of ${s/foo/bar/;}

      Notice

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

      Severity
      Category
      Status
      Source
      Language