rubocop-hq/rubocop

View on GitHub

Showing 652 of 652 total issues

Avoid too many return statements within this method.
Open

          return if begin_node.chained?
Severity: Major
Found in lib/rubocop/cop/style/redundant_parentheses.rb - About 30 mins to fix

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

          def report_offense(file, offense)
            output.printf(
              "# %<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
              path: cyan(smart_path(file)),
              line: offense.line,
    Severity: Minor
    Found in lib/rubocop/formatter/tap_formatter.rb and 1 other location - About 30 mins to fix
    lib/rubocop/formatter/clang_style_formatter.rb on lines 17..30

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

    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_offense(file, offense)
            output.printf(
              "%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
              path: cyan(smart_path(file)),
              line: offense.line,
    Severity: Minor
    Found in lib/rubocop/formatter/clang_style_formatter.rb and 1 other location - About 30 mins to fix
    lib/rubocop/formatter/tap_formatter.rb on lines 46..59

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

    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

      module Cop
        module Layout
          # Checks for a line break before the first element in a
          # multi-line hash.
          #
    Severity: Minor
    Found in lib/rubocop/cop/layout/first_hash_element_line_break.rb and 1 other location - About 30 mins to fix
    lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb on lines 4..72

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

    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

      module Cop
        module Layout
          # Ensures that each parameter in a multi-line method definition
          # starts on a separate line.
          #
    lib/rubocop/cop/layout/first_hash_element_line_break.rb on lines 4..63

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

    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 move_assignment_inside_condition(corrector, node)
                column = node.source_range.column
                *_var, condition = *node
                assignment = assignment(node)
    
    
    Severity: Minor
    Found in lib/rubocop/cop/style/conditional_assignment.rb and 1 other location - About 25 mins to fix
    lib/rubocop/cop/style/conditional_assignment.rb on lines 619..627

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

    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 move_assignment_inside_condition(corrector, node)
                column = node.source_range.column
                *_var, condition = *node
                assignment = assignment(node)
    
    
    Severity: Minor
    Found in lib/rubocop/cop/style/conditional_assignment.rb and 1 other location - About 25 mins to fix
    lib/rubocop/cop/style/conditional_assignment.rb on lines 568..576

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

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

          def offenses(path, text)
            diagnostic_options = {
              stdin: text, force_exclusion: true, formatters: ['json'], format: 'json'
            }
            diagnostic_options[:only] = config_only_options if @lint_mode || @layout_mode
    Severity: Minor
    Found in lib/rubocop/lsp/runtime.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_ancestor_method_dispatch_node has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_ancestor_method_dispatch_node(node)
            return unless (ancestor = node.parent.parent)
            return unless ancestor.call_type? || ancestor.super_type? || ancestor.yield_type?
            return if brackets?(ancestor)
    
    
    Severity: Minor
    Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.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 last_line_heredoc? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def last_line_heredoc?(node, parent = nil)
            parent ||= node
    
            if node.respond_to?(:loc) &&
               node.loc.respond_to?(:heredoc_end) &&
    Severity: Minor
    Found in lib/rubocop/cop/mixin/multiline_literal_brace_layout.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 autocorrect_enabled? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def autocorrect_enabled?
            # allow turning off autocorrect on a cop by cop basis
            return true unless cop_config
    
            # `false` is the same as `disabled` for backward compatibility.
    Severity: Minor
    Found in lib/rubocop/cop/autocorrect_logic.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 traverse_files_upwards has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def traverse_files_upwards(filename, start_dir, stop_dir)
          Pathname.new(start_dir).expand_path.ascend do |dir|
            file = dir + filename
            yield(file.to_s) if file.exist?
    
    
    Severity: Minor
    Found in lib/rubocop/file_finder.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 (attrs = node.attribute_accessor?)
    
              attrs.last.each do |name_item|
                name = attr_name(name_item)
    Severity: Minor
    Found in lib/rubocop/cop/naming/method_name.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_defined? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def on_defined?(node)
              arg = node.first_argument
              return false unless arg.ivar_type?
    
              method_node, method_name = find_definition(node)
    Severity: Minor
    Found in lib/rubocop/cop/naming/memoized_instance_variable_name.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 should_union? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def should_union?(derived_hash, base_hash, root_mode, key)
          return false unless base_hash[key].is_a?(Array)
    
          derived_mode = derived_hash['inherit_mode']
          return false if should_override?(derived_mode, key)
    Severity: Minor
    Found in lib/rubocop/config_loader_resolver.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 output_cop_comments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
            output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?
    
            cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
            default_cfg = default_config(cop_name)
    Severity: Minor
    Found in lib/rubocop/formatter/disabled_config_formatter.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 issue_offenses has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def issue_offenses(node, range, name)
            forbidden_offense(node, range, name) if forbidden_names.include?(name)
            case_offense(node, range) if uppercase?(name)
            length_offense(node, range) unless long_enough?(name)
            return if allow_nums
    Severity: Minor
    Found in lib/rubocop/cop/mixin/uncommunicative_name.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 each_argument_node has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def each_argument_node(node, type)
            left_parenthesis = node.loc.begin
    
            return unless left_parenthesis
    
    
    Severity: Minor
    Found in lib/rubocop/cop/mixin/multiline_element_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 part_of_assignment_rhs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def part_of_assignment_rhs(node, candidate)
            rhs_node = node.each_ancestor.find do |ancestor|
              break if disqualified_rhs?(candidate, ancestor)
    
              valid_rhs?(candidate, ancestor)
    Severity: Minor
    Found in lib/rubocop/cop/mixin/multiline_expression_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 directive_offense_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def directive_offense_type(directive, actual_name)
              return :missing_directive unless directive
    
              return :wrong_scope if wrong_scope(directive, actual_name)
              return :no_scope if no_scope(directive, actual_name)
    Severity: Minor
    Found in lib/rubocop/cop/internal_affairs/node_matcher_directive.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