bbatsov/rubocop

View on GitHub

Showing 655 of 655 total issues

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

        def check_assignment(node, rhs)
          # If there are method calls chained to the right hand side of the
          # assignment, we let rhs be the receiver of those method calls before
          # we check if it's an if/unless/while/until.
          return unless (rhs = first_part_of_call_chain(rhs))
Severity: Minor
Found in lib/rubocop/cop/layout/end_alignment.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 on_dstr has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_dstr(node)
          # Quick check if we possibly have line continuations.
          return unless node.source.include?('\\')

          end_of_first_line = node.source_range.begin_pos - node.source_range.column
Severity: Minor
Found in lib/rubocop/cop/layout/line_continuation_leading_space.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 on_dstr has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_dstr(node)
          return unless strings_concatenated_with_backslash?(node)

          children = node.children
          return if children.empty?
Severity: Minor
Found in lib/rubocop/cop/layout/line_end_string_concatenation_indentation.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 extract_heredocs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def extract_heredocs(ast)
          return [] unless ast

          heredocs = []
          ast.each_node(:str, :dstr, :xstr) do |node|
Severity: Minor
Found in lib/rubocop/cop/layout/trailing_whitespace.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 on_send has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_send(node)
          return unless arrow_lambda_with_args?(node)

          if style == :require_space && !space_after_arrow?(node)
            lambda_node = range_of_offense(node)
Severity: Minor
Found in lib/rubocop/cop/layout/space_in_lambda_literal.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 on_casgn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_casgn(node)
          parent = node.parent

          if parent&.assignment?
            block_node = parent.children[1]
Severity: Minor
Found in lib/rubocop/cop/metrics/class_length.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 offense_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def offense_message(type, operator, with_space, right_operand)
          if should_not_have_surrounding_space?(operator, right_operand)
            return if with_space.is?(operator.source)

            "Space around operator `#{operator.source}` detected."
Severity: Minor
Found in lib/rubocop/cop/layout/space_around_operators.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 on_block has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_block(node)
          return if node.keywords?

          # Do not register an offense for multi-line braces when specifying
          # `EnforcedStyle: no_space`. It will conflict with autocorrection
Severity: Minor
Found in lib/rubocop/cop/layout/space_before_block_braces.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 find_variable has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def find_variable(name)
          name = name.to_sym

          scope_stack.reverse_each do |scope|
            variable = scope.variables[name]
Severity: Minor
Found in lib/rubocop/cop/variable_force/variable_table.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 on_send has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_send(node)
          return if double_splat?(node)
          return unless node.arguments?

          last_argument = node.last_argument
Severity: Minor
Found in lib/rubocop/cop/layout/hash_alignment.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 offending_range has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def offending_range(node, lhs, rhs, given_style)
          return false unless begins_its_line?(rhs)
          return false if not_for_this_cop?(node)

          correct_column = if should_align?(node, rhs, given_style)
Severity: Minor
Found in lib/rubocop/cop/layout/multiline_operation_indentation.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 select_check_member has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def select_check_member(member)
          return unless member

          if access_modifier?(member.children.first)
            return if access_modifier_indentation_style == 'outdent'
Severity: Minor
Found in lib/rubocop/cop/layout/indentation_width.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 offense_range has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def offense_range(node, begin_pos)
          if reference_variable_with_brackets?(node)
            receiver_end_pos = node.receiver.source_range.end_pos
            selector_begin_pos = node.loc.selector.begin_pos
            return if receiver_end_pos >= selector_begin_pos
Severity: Minor
Found in lib/rubocop/cop/layout/space_before_brackets.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 on_if has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def on_if(node, base = nil)
          return if ignored_node?(node)
          return unless node.else? && begins_its_line?(node.loc.else)

          check_alignment(base_range_of_if(node, base), node.loc.else)
Severity: Minor
Found in lib/rubocop/cop/layout/else_alignment.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 incorrect_style_detected has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def incorrect_style_detected(token1, token2,
                                     expect_space, is_empty_braces)
          brace = (token1.left_brace? ? token1 : token2).pos
          range = expect_space ? brace : space_range(brace)
          detected_style = expect_space ? 'no_space' : 'space'
Severity: Minor
Found in lib/rubocop/cop/layout/space_inside_hash_literal_braces.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 belong_to_inner_scope? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def belong_to_inner_scope?(target_node)
          return false if !target_node.parent || target_node.parent.equal?(node)
          return false unless SCOPE_TYPES.include?(target_node.parent.type)

          indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
Severity: Minor
Found in lib/rubocop/cop/variable_force/scope.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

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

      def report_highlighted_area(highlighted_area)
        space_area  = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
        source_area = highlighted_area.source
        output.puts("# #{' ' * Unicode::DisplayWidth.of(space_area)}" \
                    "#{'^' * Unicode::DisplayWidth.of(source_area)}")
Severity: Minor
Found in lib/rubocop/formatter/tap_formatter.rb and 1 other location - About 25 mins to fix
lib/rubocop/formatter/clang_style_formatter.rb on lines 47..51

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

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 report_highlighted_area(highlighted_area)
        space_area  = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
        source_area = highlighted_area.source
        output.puts("#{' ' * Unicode::DisplayWidth.of(space_area)}" \
                    "#{'^' * Unicode::DisplayWidth.of(source_area)}")
Severity: Minor
Found in lib/rubocop/formatter/clang_style_formatter.rb and 1 other location - About 25 mins to fix
lib/rubocop/formatter/tap_formatter.rb on lines 39..43

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

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 maybe_print_corrected_source has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def maybe_print_corrected_source
          # Integration tools (like RubyMine) expect to have only the JSON result
          # when specifying JSON format. Similar HTML and JUnit are targeted as well.
          # See: https://github.com/rubocop/rubocop/issues/8673
          return if INTEGRATION_FORMATTERS.include?(@options[:format])
Severity: Minor
Found in lib/rubocop/cli/command/execute_runner.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 add_inheritance_from_auto_generated_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def add_inheritance_from_auto_generated_file(config_file)
          file_string = " #{relative_path_to_todo_from_options_config}"

          config_file ||= ConfigFinder::DOTFILE

Severity: Minor
Found in lib/rubocop/cli/command/auto_generate_config.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

Severity
Category
Status
Source
Language