bbatsov/rubocop

View on GitHub

Showing 669 of 669 total issues

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

        def groupable_accessor?(node)
          return true unless (previous_expression = node.left_siblings.last)

          # Accessors with Sorbet `sig { ... }` blocks shouldn't be groupable.
          if previous_expression.block_type?
Severity: Minor
Found in lib/rubocop/cop/style/accessor_grouping.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

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

        def bad_method?(block)
          if active_support_extensions_enabled?
            bad_method_with_active_support?(block) do |key_arg, send_node|
              if send_node.method?(:in?) && send_node.receiver&.source != key_arg.source
                return false
Severity: Minor
Found in lib/rubocop/cop/style/hash_except.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

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

        def preferred_method(operator, lhs, rhs, if_branch, else_branch)
          if lhs == if_branch && rhs == else_branch
            GRATER_OPERATORS.include?(operator) ? 'max' : 'min'
          elsif lhs == else_branch && rhs == if_branch
            LESS_OPERATORS.include?(operator) ? 'max' : 'min'
Severity: Minor
Found in lib/rubocop/cop/style/min_max_comparison.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

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

        def on_new_investigation
          processed_source.comments.each_with_index do |comment, index|
            next unless first_comment_line?(processed_source.comments, index) ||
                        inline_comment?(comment)

Severity: Minor
Found in lib/rubocop/cop/style/comment_annotation.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

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

        def single_argument(node)
          first_argument = node.first_argument
          if first_argument.hash_type?
            register_offense_for_hash(node, first_argument)
          elsif first_argument.splat_type?
Severity: Minor
Found in lib/rubocop/cop/style/hash_conversion.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

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

        def class_name(class_node, node)
          if class_name_method?(node.children.first.method_name)
            if (receiver = class_node.receiver) && class_name_method?(class_node.method_name)
              return receiver.source
            end
Severity: Minor
Found in lib/rubocop/cop/style/class_equality_comparison.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

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

        def register_semicolon(line, column, after_expression, token_before_semicolon = nil)
          range = source_range(processed_source.buffer, line, column)

          add_offense(range) do |corrector|
            if after_expression
Severity: Minor
Found in lib/rubocop/cop/style/semicolon.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

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

        def on_super(super_node)
          def_node = super_node.ancestors.find do |node|
            # When defining dynamic methods, implicitly calling `super` is not possible.
            # Since there is a possibility of delegation to `define_method`,
            # `super` used within the block is always allowed.
Severity: Minor
Found in lib/rubocop/cop/style/super_arguments.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

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

        def on_block(node)
          each_with_object_block_candidate?(node) do |method, args, body|
            _, method_name, method_arg = *method
            return if simple_method_arg?(method_arg)

Severity: Minor
Found in lib/rubocop/cop/style/each_with_object.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

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

        def argument_newline?(node)
          node = node.to_a.last if node.assignment?
          return false if node.parenthesized_call?

          node = node.children.first if node.root? && node.begin_type?
Severity: Minor
Found in lib/rubocop/cop/style/redundant_line_continuation.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

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

        def on_module(node)
          return unless node.body&.begin_type?

          each_wrong_style(node.body.children) do |child_node|
            add_offense(child_node) do |corrector|
Severity: Minor
Found in lib/rubocop/cop/style/module_function.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

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

        def check(node, locations, begin_keyword = DO)
          locations.each do |loc|
            next unless node.loc.respond_to?(loc)

            range = node.loc.public_send(loc)
Severity: Minor
Found in lib/rubocop/cop/layout/space_around_keyword.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

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

        def check_nesting_level(node, max, current_level)
          if consider_node?(node)
            current_level += 1 if count_if_block?(node)
            if current_level > max
              self.max = current_level
Severity: Minor
Found in lib/rubocop/cop/metrics/block_nesting.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

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

        def on_send(node)
          map_candidate = node.children.first
          if (block_argument, condition, return_value = conditional_block(map_candidate))
            return unless node.method?(:compact) && node.arguments.empty?

Severity: Minor
Found in lib/rubocop/cop/style/map_compact_with_conditional_block.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

Method setup_subtasks has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def setup_subtasks(name, *args, &task_block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
      namespace(name) do
        # rubocop:todo Naming/InclusiveLanguage
        task(:auto_correct, *args) do
          require 'rainbow'
Severity: Minor
Found in lib/rubocop/rake_task.rb - About 1 hr to fix

    Method on_send has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def on_send(node)
              return if node.arguments.empty?
              return unless node.arguments.all?(&:array_type?)
    
              offense = offense_range(node)
    Severity: Minor
    Found in lib/rubocop/cop/style/concat_array_literals.rb - About 1 hr to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              def check_zero_length_comparison(node)
                zero_length_comparison = zero_length_comparison(node.parent)
                return unless zero_length_comparison
      
                lhs, opr, rhs = zero_length_comparison
      Severity: Major
      Found in lib/rubocop/cop/style/zero_length_predicate.rb and 1 other location - About 1 hr to fix
      lib/rubocop/cop/style/zero_length_predicate.rb on lines 80..91

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 48.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              def check_nonzero_length_comparison(node)
                nonzero_length_comparison = nonzero_length_comparison(node.parent)
                return unless nonzero_length_comparison
      
                lhs, opr, rhs = nonzero_length_comparison
      Severity: Major
      Found in lib/rubocop/cop/style/zero_length_predicate.rb and 1 other location - About 1 hr to fix
      lib/rubocop/cop/style/zero_length_predicate.rb on lines 65..76

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 48.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

              def partial_matcher!(expected)
                lambda do |namespace|
                  while namespace
                    return match?(expected) if namespace.cbase_type?
      
      
      Severity: Minor
      Found in lib/rubocop/cop/naming/file_name.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 profile_if_needed has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def profile_if_needed
            return yield unless @options[:profile]
      
            return STATUS_ERROR unless require_gem('stackprof')
      
      
      Severity: Minor
      Found in lib/rubocop/cli.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

      Severity
      Category
      Status
      Source
      Language