rubocop 0.74.0 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +3 -2
 - data/config/default.yml +366 -318
 - data/lib/rubocop.rb +48 -32
 - data/lib/rubocop/ast/builder.rb +1 -0
 - data/lib/rubocop/ast/node.rb +5 -1
 - data/lib/rubocop/ast/node/block_node.rb +2 -0
 - data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +1 -12
 - data/lib/rubocop/ast/node/return_node.rb +24 -0
 - data/lib/rubocop/cli.rb +11 -227
 - data/lib/rubocop/cli/command.rb +21 -0
 - data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
 - data/lib/rubocop/cli/command/base.rb +33 -0
 - data/lib/rubocop/cli/command/execute_runner.rb +76 -0
 - data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
 - data/lib/rubocop/cli/command/show_cops.rb +73 -0
 - data/lib/rubocop/cli/command/version.rb +17 -0
 - data/lib/rubocop/cli/environment.rb +21 -0
 - data/lib/rubocop/comment_config.rb +5 -4
 - data/lib/rubocop/config.rb +12 -1
 - data/lib/rubocop/config_loader.rb +21 -3
 - data/lib/rubocop/config_loader_resolver.rb +4 -3
 - data/lib/rubocop/config_obsoletion.rb +85 -11
 - data/lib/rubocop/config_validator.rb +28 -19
 - data/lib/rubocop/cop/autocorrect_logic.rb +3 -3
 - data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
 - data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
 - data/lib/rubocop/cop/commissioner.rb +15 -7
 - data/lib/rubocop/cop/cop.rb +35 -9
 - data/lib/rubocop/cop/corrector.rb +8 -7
 - data/lib/rubocop/cop/correctors/alignment_corrector.rb +43 -17
 - data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
 - data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
 - data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
 - data/lib/rubocop/cop/generator.rb +3 -3
 - data/lib/rubocop/cop/generator/configuration_injector.rb +9 -4
 - data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
 - data/lib/rubocop/cop/internal_affairs.rb +1 -0
 - data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
 - data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
 - data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
 - data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +11 -2
 - data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
 - data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
 - data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
 - data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
 - data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
 - data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
 - data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
 - data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
 - data/lib/rubocop/cop/layout/extra_spacing.rb +1 -7
 - data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
 - data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
 - data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
 - data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
 - data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +8 -4
 - data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +6 -6
 - data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
 - data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
 - data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
 - data/lib/rubocop/cop/layout/multiline_block_layout.rb +24 -2
 - data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
 - data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
 - data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
 - data/lib/rubocop/cop/layout/space_around_block_parameters.rb +5 -1
 - data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
 - data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
 - data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
 - data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
 - data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +8 -5
 - data/lib/rubocop/cop/layout/space_inside_block_braces.rb +7 -0
 - data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
 - data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -0
 - data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
 - data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
 - data/lib/rubocop/cop/lint/assignment_in_condition.rb +17 -4
 - data/lib/rubocop/cop/lint/debugger.rb +1 -1
 - data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
 - data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
 - data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
 - data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
 - data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +10 -36
 - data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
 - data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
 - data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
 - data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
 - data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
 - data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
 - data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
 - data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
 - data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
 - data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
 - data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
 - data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
 - data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
 - data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +91 -0
 - data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
 - data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
 - data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
 - data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
 - data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
 - data/lib/rubocop/cop/lint/void.rb +7 -26
 - data/lib/rubocop/cop/message_annotator.rb +16 -7
 - data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
 - data/lib/rubocop/cop/metrics/method_length.rb +1 -1
 - data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
 - data/lib/rubocop/cop/migration/department_name.rb +44 -0
 - data/lib/rubocop/cop/mixin/alignment.rb +2 -2
 - data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
 - data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
 - data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
 - data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
 - data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
 - data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
 - data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
 - data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
 - data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
 - data/lib/rubocop/cop/naming/file_name.rb +12 -5
 - data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
 - data/lib/rubocop/cop/naming/method_name.rb +12 -1
 - data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +3 -3
 - data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
 - data/lib/rubocop/cop/naming/variable_name.rb +1 -0
 - data/lib/rubocop/cop/offense.rb +29 -7
 - data/lib/rubocop/cop/registry.rb +22 -1
 - data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
 - data/lib/rubocop/cop/style/alias.rb +1 -1
 - data/lib/rubocop/cop/style/array_join.rb +1 -1
 - data/lib/rubocop/cop/style/attr.rb +10 -2
 - data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
 - data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +35 -16
 - data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
 - data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
 - data/lib/rubocop/cop/style/commented_keyword.rb +8 -2
 - data/lib/rubocop/cop/style/conditional_assignment.rb +6 -6
 - data/lib/rubocop/cop/style/copyright.rb +11 -7
 - data/lib/rubocop/cop/style/documentation_method.rb +44 -0
 - data/lib/rubocop/cop/style/double_cop_disable_directive.rb +10 -4
 - data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
 - data/lib/rubocop/cop/style/empty_literal.rb +2 -2
 - data/lib/rubocop/cop/style/empty_method.rb +5 -5
 - data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
 - data/lib/rubocop/cop/style/even_odd.rb +1 -1
 - data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
 - data/lib/rubocop/cop/style/format_string.rb +10 -7
 - data/lib/rubocop/cop/style/format_string_token.rb +19 -68
 - data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +28 -33
 - data/lib/rubocop/cop/style/guard_clause.rb +3 -2
 - data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
 - data/lib/rubocop/cop/style/if_unless_modifier.rb +93 -15
 - data/lib/rubocop/cop/style/infinite_loop.rb +6 -5
 - data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
 - data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
 - data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
 - data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +25 -25
 - data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
 - data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
 - data/lib/rubocop/cop/style/mixin_usage.rb +11 -1
 - data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
 - data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
 - data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
 - data/lib/rubocop/cop/style/nested_modifier.rb +22 -4
 - data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
 - data/lib/rubocop/cop/style/next.rb +5 -5
 - data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
 - data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
 - data/lib/rubocop/cop/style/option_hash.rb +3 -3
 - data/lib/rubocop/cop/style/or_assignment.rb +6 -1
 - data/lib/rubocop/cop/style/parentheses_around_condition.rb +14 -0
 - data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
 - data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
 - data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
 - data/lib/rubocop/cop/style/redundant_parentheses.rb +16 -7
 - data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
 - data/lib/rubocop/cop/style/redundant_return.rb +39 -29
 - data/lib/rubocop/cop/style/redundant_self.rb +18 -1
 - data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
 - data/lib/rubocop/cop/style/rescue_modifier.rb +24 -0
 - data/lib/rubocop/cop/style/safe_navigation.rb +23 -3
 - data/lib/rubocop/cop/style/semicolon.rb +13 -2
 - data/lib/rubocop/cop/style/single_line_methods.rb +8 -1
 - data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
 - data/lib/rubocop/cop/style/ternary_parentheses.rb +19 -0
 - data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
 - data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
 - data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
 - data/lib/rubocop/cop/team.rb +5 -0
 - data/lib/rubocop/cop/util.rb +1 -1
 - data/lib/rubocop/cop/utils/format_string.rb +120 -0
 - data/lib/rubocop/cop/variable_force.rb +7 -5
 - data/lib/rubocop/cop/variable_force/variable.rb +15 -2
 - data/lib/rubocop/core_ext/string.rb +0 -24
 - data/lib/rubocop/formatter/base_formatter.rb +2 -2
 - data/lib/rubocop/formatter/clang_style_formatter.rb +9 -6
 - data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -9
 - data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
 - data/lib/rubocop/formatter/formatter_set.rb +16 -15
 - data/lib/rubocop/formatter/json_formatter.rb +6 -5
 - data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
 - data/lib/rubocop/formatter/simple_text_formatter.rb +16 -4
 - data/lib/rubocop/formatter/tap_formatter.rb +18 -7
 - data/lib/rubocop/magic_comment.rb +4 -0
 - data/lib/rubocop/node_pattern.rb +4 -2
 - data/lib/rubocop/options.rb +21 -26
 - data/lib/rubocop/processed_source.rb +1 -1
 - data/lib/rubocop/rake_task.rb +1 -0
 - data/lib/rubocop/result_cache.rb +24 -8
 - data/lib/rubocop/runner.rb +60 -33
 - data/lib/rubocop/target_finder.rb +12 -6
 - data/lib/rubocop/version.rb +1 -1
 - metadata +48 -33
 - data/lib/rubocop/cop/mixin/ignored_method_patterns.rb +0 -19
 - data/lib/rubocop/cop/mixin/safe_mode.rb +0 -22
 
| 
         @@ -55,8 +55,8 @@ module RuboCop 
     | 
|
| 
       55 
55 
     | 
    
         
             
                      source
         
     | 
| 
       56 
56 
     | 
    
         
             
                        .comments
         
     | 
| 
       57 
57 
     | 
    
         
             
                        .take_while { |comment| comment.loc.line < source.ast.loc.line }
         
     | 
| 
       58 
     | 
    
         
            -
                        . 
     | 
| 
       59 
     | 
    
         
            -
                        . 
     | 
| 
      
 58 
     | 
    
         
            +
                        .reverse
         
     | 
| 
      
 59 
     | 
    
         
            +
                        .find { |comment| MagicComment.parse(comment.text).any? }
         
     | 
| 
       60 
60 
     | 
    
         
             
                    end
         
     | 
| 
       61 
61 
     | 
    
         
             
                  end
         
     | 
| 
       62 
62 
     | 
    
         
             
                end
         
     | 
| 
         @@ -36,7 +36,7 @@ module RuboCop 
     | 
|
| 
       36 
36 
     | 
    
         
             
                  #
         
     | 
| 
       37 
37 
     | 
    
         
             
                  #   end
         
     | 
| 
       38 
38 
     | 
    
         
             
                  #
         
     | 
| 
       39 
     | 
    
         
            -
                  # @example  
     | 
| 
      
 39 
     | 
    
         
            +
                  # @example EnforcedStyle: beginning_only
         
     | 
| 
       40 
40 
     | 
    
         
             
                  #   # good
         
     | 
| 
       41 
41 
     | 
    
         
             
                  #
         
     | 
| 
       42 
42 
     | 
    
         
             
                  #   class Foo
         
     | 
| 
         @@ -46,7 +46,7 @@ module RuboCop 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  #     end
         
     | 
| 
       47 
47 
     | 
    
         
             
                  #   end
         
     | 
| 
       48 
48 
     | 
    
         
             
                  #
         
     | 
| 
       49 
     | 
    
         
            -
                  # @example  
     | 
| 
      
 49 
     | 
    
         
            +
                  # @example EnforcedStyle: ending_only
         
     | 
| 
       50 
50 
     | 
    
         
             
                  #   # good
         
     | 
| 
       51 
51 
     | 
    
         
             
                  #
         
     | 
| 
       52 
52 
     | 
    
         
             
                  #   class Foo
         
     | 
| 
         @@ -45,9 +45,7 @@ module RuboCop 
     | 
|
| 
       45 
45 
     | 
    
         
             
                    MSG_MISSING = 'Carriage return character missing.'
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                    def investigate(processed_source)
         
     | 
| 
       48 
     | 
    
         
            -
                       
     | 
| 
       49 
     | 
    
         
            -
                      last_line =
         
     | 
| 
       50 
     | 
    
         
            -
                        last_token ? last_token.line : processed_source.lines.length
         
     | 
| 
      
 48 
     | 
    
         
            +
                      last_line = last_line(processed_source)
         
     | 
| 
       51 
49 
     | 
    
         | 
| 
       52 
50 
     | 
    
         
             
                      processed_source.raw_source.each_line.with_index do |line, index|
         
     | 
| 
       53 
51 
     | 
    
         
             
                        break if index >= last_line
         
     | 
| 
         @@ -81,6 +79,13 @@ module RuboCop 
     | 
|
| 
       81 
79 
     | 
    
         
             
                      else MSG_MISSING if line !~ /\r$/
         
     | 
| 
       82 
80 
     | 
    
         
             
                      end
         
     | 
| 
       83 
81 
     | 
    
         
             
                    end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    private
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                    def last_line(processed_source)
         
     | 
| 
      
 86 
     | 
    
         
            +
                      last_token = processed_source.tokens.last
         
     | 
| 
      
 87 
     | 
    
         
            +
                      last_token ? last_token.line : processed_source.lines.length
         
     | 
| 
      
 88 
     | 
    
         
            +
                    end
         
     | 
| 
       84 
89 
     | 
    
         
             
                  end
         
     | 
| 
       85 
90 
     | 
    
         
             
                end
         
     | 
| 
       86 
91 
     | 
    
         
             
              end
         
     | 
| 
         @@ -82,9 +82,7 @@ module RuboCop 
     | 
|
| 
       82 
82 
     | 
    
         
             
                                      token2.text.start_with?('#')
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
                      extra_space_range(token1, token2) do |range|
         
     | 
| 
       85 
     | 
    
         
            -
                        # Unary + doesn't appear as a token and needs special handling.
         
     | 
| 
       86 
85 
     | 
    
         
             
                        next if ignored_range?(ast, range.begin_pos)
         
     | 
| 
       87 
     | 
    
         
            -
                        next if unary_plus_non_offense?(range)
         
     | 
| 
       88 
86 
     | 
    
         | 
| 
       89 
87 
     | 
    
         
             
                        add_offense(range, location: range, message: MSG_UNNECESSARY)
         
     | 
| 
       90 
88 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -114,13 +112,9 @@ module RuboCop 
     | 
|
| 
       114 
112 
     | 
    
         
             
                      ignored_ranges(ast).any? { |r| r.include?(start_pos) }
         
     | 
| 
       115 
113 
     | 
    
         
             
                    end
         
     | 
| 
       116 
114 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
                    def unary_plus_non_offense?(range)
         
     | 
| 
       118 
     | 
    
         
            -
                      range.resize(range.size + 1).source =~ /^ ?\+$/
         
     | 
| 
       119 
     | 
    
         
            -
                    end
         
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
115 
     | 
    
         
             
                    # Returns an array of ranges that should not be reported. It's the
         
     | 
| 
       122 
116 
     | 
    
         
             
                    # extra spaces between the keys and values in a multiline hash,
         
     | 
| 
       123 
     | 
    
         
            -
                    # since those are handled by the  
     | 
| 
      
 117 
     | 
    
         
            +
                    # since those are handled by the Layout/HashAlignment cop.
         
     | 
| 
       124 
118 
     | 
    
         
             
                    def ignored_ranges(ast)
         
     | 
| 
       125 
119 
     | 
    
         
             
                      return [] unless ast
         
     | 
| 
       126 
120 
     | 
    
         | 
| 
         @@ -2,14 +2,14 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module RuboCop
         
     | 
| 
       4 
4 
     | 
    
         
             
              module Cop
         
     | 
| 
       5 
     | 
    
         
            -
                # rubocop:disable  
     | 
| 
      
 5 
     | 
    
         
            +
                # rubocop:disable Layout/LineLength
         
     | 
| 
       6 
6 
     | 
    
         
             
                module Layout
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # This cop checks the indentation of the first argument in a method call.
         
     | 
| 
       8 
     | 
    
         
            -
                  # Arguments after the first one are checked by Layout/ 
     | 
| 
      
 8 
     | 
    
         
            +
                  # Arguments after the first one are checked by Layout/ArgumentAlignment,
         
     | 
| 
       9 
9 
     | 
    
         
             
                  # not by this cop.
         
     | 
| 
       10 
10 
     | 
    
         
             
                  #
         
     | 
| 
       11 
11 
     | 
    
         
             
                  # For indenting the first parameter of method *definitions*, check out
         
     | 
| 
       12 
     | 
    
         
            -
                  # Layout/ 
     | 
| 
      
 12 
     | 
    
         
            +
                  # Layout/FirstParameterIndentation.
         
     | 
| 
       13 
13 
     | 
    
         
             
                  #
         
     | 
| 
       14 
14 
     | 
    
         
             
                  # @example
         
     | 
| 
       15 
15 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -142,8 +142,8 @@ module RuboCop 
     | 
|
| 
       142 
142 
     | 
    
         
             
                  #     nested_first_param),
         
     | 
| 
       143 
143 
     | 
    
         
             
                  #   second_param
         
     | 
| 
       144 
144 
     | 
    
         
             
                  #
         
     | 
| 
       145 
     | 
    
         
            -
                  class  
     | 
| 
       146 
     | 
    
         
            -
                    # rubocop:enable  
     | 
| 
      
 145 
     | 
    
         
            +
                  class FirstArgumentIndentation < Cop
         
     | 
| 
      
 146 
     | 
    
         
            +
                    # rubocop:enable Layout/LineLength
         
     | 
| 
       147 
147 
     | 
    
         
             
                    include Alignment
         
     | 
| 
       148 
148 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       149 
149 
     | 
    
         
             
                    include RangeHelp
         
     | 
| 
         @@ -228,19 +228,21 @@ module RuboCop 
     | 
|
| 
       228 
228 
     | 
    
         
             
                    # containing the previous line that's not a comment line or a blank
         
     | 
| 
       229 
229 
     | 
    
         
             
                    # line.
         
     | 
| 
       230 
230 
     | 
    
         
             
                    def previous_code_line(line_number)
         
     | 
| 
       231 
     | 
    
         
            -
                      @comment_lines ||=
         
     | 
| 
       232 
     | 
    
         
            -
                        processed_source
         
     | 
| 
       233 
     | 
    
         
            -
                        .comments
         
     | 
| 
       234 
     | 
    
         
            -
                        .select { |c| begins_its_line?(c.loc.expression) }
         
     | 
| 
       235 
     | 
    
         
            -
                        .map { |c| c.loc.line }
         
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
231 
     | 
    
         
             
                      line = ''
         
     | 
| 
       238 
     | 
    
         
            -
                      while line.blank? ||  
     | 
| 
      
 232 
     | 
    
         
            +
                      while line.blank? || comment_lines.include?(line_number)
         
     | 
| 
       239 
233 
     | 
    
         
             
                        line_number -= 1
         
     | 
| 
       240 
234 
     | 
    
         
             
                        line = processed_source.lines[line_number - 1]
         
     | 
| 
       241 
235 
     | 
    
         
             
                      end
         
     | 
| 
       242 
236 
     | 
    
         
             
                      line
         
     | 
| 
       243 
237 
     | 
    
         
             
                    end
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
                    def comment_lines
         
     | 
| 
      
 240 
     | 
    
         
            +
                      @comment_lines ||=
         
     | 
| 
      
 241 
     | 
    
         
            +
                        processed_source
         
     | 
| 
      
 242 
     | 
    
         
            +
                        .comments
         
     | 
| 
      
 243 
     | 
    
         
            +
                        .select { |c| begins_its_line?(c.loc.expression) }
         
     | 
| 
      
 244 
     | 
    
         
            +
                        .map { |c| c.loc.line }
         
     | 
| 
      
 245 
     | 
    
         
            +
                    end
         
     | 
| 
       244 
246 
     | 
    
         
             
                  end
         
     | 
| 
       245 
247 
     | 
    
         
             
                end
         
     | 
| 
       246 
248 
     | 
    
         
             
              end
         
     | 
    
        data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb}
    RENAMED
    
    | 
         @@ -5,7 +5,7 @@ module RuboCop 
     | 
|
| 
       5 
5 
     | 
    
         
             
                module Layout
         
     | 
| 
       6 
6 
     | 
    
         
             
                  # This cop checks the indentation of the first element in an array literal
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # where the opening bracket and the first element are on separate lines.
         
     | 
| 
       8 
     | 
    
         
            -
                  # The other elements' indentations are handled by the  
     | 
| 
      
 8 
     | 
    
         
            +
                  # The other elements' indentations are handled by the ArrayAlignment cop.
         
     | 
| 
       9 
9 
     | 
    
         
             
                  #
         
     | 
| 
       10 
10 
     | 
    
         
             
                  # By default, array literals that are arguments in a method call with
         
     | 
| 
       11 
11 
     | 
    
         
             
                  # parentheses, and where the opening square bracket of the array is on the
         
     | 
| 
         @@ -22,7 +22,7 @@ module RuboCop 
     | 
|
| 
       22 
22 
     | 
    
         
             
                  # @example EnforcedStyle: special_inside_parentheses (default)
         
     | 
| 
       23 
23 
     | 
    
         
             
                  #   # The `special_inside_parentheses` style enforces that the first
         
     | 
| 
       24 
24 
     | 
    
         
             
                  #   # element in an array literal where the opening bracket and first
         
     | 
| 
       25 
     | 
    
         
            -
                  #   # element are on  
     | 
| 
      
 25 
     | 
    
         
            +
                  #   # element are on separate lines is indented one step (two spaces) more
         
     | 
| 
       26 
26 
     | 
    
         
             
                  #   # than the position inside the opening parenthesis.
         
     | 
| 
       27 
27 
     | 
    
         
             
                  #
         
     | 
| 
       28 
28 
     | 
    
         
             
                  #   #bad
         
     | 
| 
         @@ -44,7 +44,7 @@ module RuboCop 
     | 
|
| 
       44 
44 
     | 
    
         
             
                  # @example EnforcedStyle: consistent
         
     | 
| 
       45 
45 
     | 
    
         
             
                  #   # The `consistent` style enforces that the first element in an array
         
     | 
| 
       46 
46 
     | 
    
         
             
                  #   # literal where the opening bracket and the first element are on
         
     | 
| 
       47 
     | 
    
         
            -
                  #   #  
     | 
| 
      
 47 
     | 
    
         
            +
                  #   # separate lines is indented the same as an array literal which is not
         
     | 
| 
       48 
48 
     | 
    
         
             
                  #   # defined inside a method call.
         
     | 
| 
       49 
49 
     | 
    
         
             
                  #
         
     | 
| 
       50 
50 
     | 
    
         
             
                  #   #bad
         
     | 
| 
         @@ -79,7 +79,7 @@ module RuboCop 
     | 
|
| 
       79 
79 
     | 
    
         
             
                  #   and_now_for_something = [
         
     | 
| 
       80 
80 
     | 
    
         
             
                  #                             :completely_different
         
     | 
| 
       81 
81 
     | 
    
         
             
                  #                           ]
         
     | 
| 
       82 
     | 
    
         
            -
                  class  
     | 
| 
      
 82 
     | 
    
         
            +
                  class FirstArrayElementIndentation < Cop
         
     | 
| 
       83 
83 
     | 
    
         
             
                    include Alignment
         
     | 
| 
       84 
84 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       85 
85 
     | 
    
         
             
                    include MultilineElementIndentation
         
     | 
    
        data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb}
    RENAMED
    
    | 
         @@ -5,7 +5,7 @@ module RuboCop 
     | 
|
| 
       5 
5 
     | 
    
         
             
                module Layout
         
     | 
| 
       6 
6 
     | 
    
         
             
                  # This cop checks the indentation of the first key in a hash literal
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # where the opening brace and the first key are on separate lines. The
         
     | 
| 
       8 
     | 
    
         
            -
                  # other keys' indentations are handled by the  
     | 
| 
      
 8 
     | 
    
         
            +
                  # other keys' indentations are handled by the HashAlignment cop.
         
     | 
| 
       9 
9 
     | 
    
         
             
                  #
         
     | 
| 
       10 
10 
     | 
    
         
             
                  # By default, Hash literals that are arguments in a method call with
         
     | 
| 
       11 
11 
     | 
    
         
             
                  # parentheses, and where the opening curly brace of the hash is on the
         
     | 
| 
         @@ -77,7 +77,7 @@ module RuboCop 
     | 
|
| 
       77 
77 
     | 
    
         
             
                  #   and_now_for_something = {
         
     | 
| 
       78 
78 
     | 
    
         
             
                  #                             completely: :different
         
     | 
| 
       79 
79 
     | 
    
         
             
                  #                           }
         
     | 
| 
       80 
     | 
    
         
            -
                  class  
     | 
| 
      
 80 
     | 
    
         
            +
                  class FirstHashElementIndentation < Cop
         
     | 
| 
       81 
81 
     | 
    
         
             
                    include Alignment
         
     | 
| 
       82 
82 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       83 
83 
     | 
    
         
             
                    include MultilineElementIndentation
         
     | 
| 
         @@ -113,7 +113,7 @@ module RuboCop 
     | 
|
| 
       113 
113 
     | 
    
         
             
                      first_pair = hash_node.pairs.first
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                      if first_pair
         
     | 
| 
       116 
     | 
    
         
            -
                        return if first_pair. 
     | 
| 
      
 116 
     | 
    
         
            +
                        return if first_pair.first_line == left_brace.line
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                        if separator_style?(first_pair)
         
     | 
| 
       119 
119 
     | 
    
         
             
                          check_based_on_longest_key(hash_node, left_brace,
         
     | 
| 
         @@ -149,7 +149,7 @@ module RuboCop 
     | 
|
| 
       149 
149 
     | 
    
         
             
                    def separator_style?(first_pair)
         
     | 
| 
       150 
150 
     | 
    
         
             
                      separator = first_pair.loc.operator
         
     | 
| 
       151 
151 
     | 
    
         
             
                      key = "Enforced#{separator.is?(':') ? 'Colon' : 'HashRocket'}Style"
         
     | 
| 
       152 
     | 
    
         
            -
                      config.for_cop('Layout/ 
     | 
| 
      
 152 
     | 
    
         
            +
                      config.for_cop('Layout/HashAlignment')[key] == 'separator'
         
     | 
| 
       153 
153 
     | 
    
         
             
                    end
         
     | 
| 
       154 
154 
     | 
    
         | 
| 
       155 
155 
     | 
    
         
             
                    def check_based_on_longest_key(hash_node, left_brace, left_parenthesis)
         
     | 
| 
         @@ -5,10 +5,10 @@ module RuboCop 
     | 
|
| 
       5 
5 
     | 
    
         
             
                module Layout
         
     | 
| 
       6 
6 
     | 
    
         
             
                  # This cop checks the indentation of the first parameter in a method
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # definition. Parameters after the first one are checked by
         
     | 
| 
       8 
     | 
    
         
            -
                  # Layout/ 
     | 
| 
      
 8 
     | 
    
         
            +
                  # Layout/ParameterAlignment, not by this cop.
         
     | 
| 
       9 
9 
     | 
    
         
             
                  #
         
     | 
| 
       10 
10 
     | 
    
         
             
                  # For indenting the first argument of method *calls*, check out
         
     | 
| 
       11 
     | 
    
         
            -
                  # Layout/ 
     | 
| 
      
 11 
     | 
    
         
            +
                  # Layout/FirstArgumentIndentation, which supports options related to
         
     | 
| 
       12 
12 
     | 
    
         
             
                  # nesting that are irrelevant for method *definitions*.
         
     | 
| 
       13 
13 
     | 
    
         
             
                  #
         
     | 
| 
       14 
14 
     | 
    
         
             
                  # @example
         
     | 
| 
         @@ -41,7 +41,7 @@ module RuboCop 
     | 
|
| 
       41 
41 
     | 
    
         
             
                  #   second_param)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  #     123
         
     | 
| 
       43 
43 
     | 
    
         
             
                  #   end
         
     | 
| 
       44 
     | 
    
         
            -
                  class  
     | 
| 
      
 44 
     | 
    
         
            +
                  class FirstParameterIndentation < Cop
         
     | 
| 
       45 
45 
     | 
    
         
             
                    include Alignment
         
     | 
| 
       46 
46 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       47 
47 
     | 
    
         
             
                    include MultilineElementIndentation
         
     | 
| 
         @@ -175,8 +175,8 @@ module RuboCop 
     | 
|
| 
       175 
175 
     | 
    
         
             
                  #   do_something({foo: 1,
         
     | 
| 
       176 
176 
     | 
    
         
             
                  #     bar: 2})
         
     | 
| 
       177 
177 
     | 
    
         
             
                  #
         
     | 
| 
       178 
     | 
    
         
            -
                  class  
     | 
| 
       179 
     | 
    
         
            -
                    include  
     | 
| 
      
 178 
     | 
    
         
            +
                  class HashAlignment < Cop
         
     | 
| 
      
 179 
     | 
    
         
            +
                    include HashAlignmentStyles
         
     | 
| 
       180 
180 
     | 
    
         
             
                    include RangeHelp
         
     | 
| 
       181 
181 
     | 
    
         | 
| 
       182 
182 
     | 
    
         
             
                    MSG = 'Align the elements of a hash literal if they span more than ' \
         
     | 
| 
         @@ -220,14 +220,18 @@ module RuboCop 
     | 
|
| 
       220 
220 
     | 
    
         | 
| 
       221 
221 
     | 
    
         
             
                    private
         
     | 
| 
       222 
222 
     | 
    
         | 
| 
      
 223 
     | 
    
         
            +
                    def reset!
         
     | 
| 
      
 224 
     | 
    
         
            +
                      self.offences_by = {}
         
     | 
| 
      
 225 
     | 
    
         
            +
                      self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
         
     | 
| 
      
 226 
     | 
    
         
            +
                    end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
       223 
228 
     | 
    
         
             
                    def double_splat?(node)
         
     | 
| 
       224 
229 
     | 
    
         
             
                      node.children.last.is_a?(Symbol)
         
     | 
| 
       225 
230 
     | 
    
         
             
                    end
         
     | 
| 
       226 
231 
     | 
    
         | 
| 
       227 
232 
     | 
    
         
             
                    def check_pairs(node)
         
     | 
| 
       228 
233 
     | 
    
         
             
                      first_pair = node.pairs.first
         
     | 
| 
       229 
     | 
    
         
            -
                       
     | 
| 
       230 
     | 
    
         
            -
                      self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
         
     | 
| 
      
 234 
     | 
    
         
            +
                      reset!
         
     | 
| 
       231 
235 
     | 
    
         | 
| 
       232 
236 
     | 
    
         
             
                      alignment_for(first_pair).each do |alignment|
         
     | 
| 
       233 
237 
     | 
    
         
             
                        delta = alignment.deltas_for_first_pair(first_pair, node)
         
     | 
| 
         @@ -8,9 +8,9 @@ module RuboCop 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  # In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you
         
     | 
| 
       9 
9 
     | 
    
         
             
                  # use the older rubies, you should introduce some library to your project
         
     | 
| 
       10 
10 
     | 
    
         
             
                  # (e.g. ActiveSupport, Powerpack or Unindent).
         
     | 
| 
       11 
     | 
    
         
            -
                  # Note: When ` 
     | 
| 
      
 11 
     | 
    
         
            +
                  # Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default),
         
     | 
| 
       12 
12 
     | 
    
         
             
                  #       this cop does not add any offenses for long here documents to
         
     | 
| 
       13 
     | 
    
         
            -
                  #       avoid ` 
     | 
| 
      
 13 
     | 
    
         
            +
                  #       avoid `Layout/LineLength`'s offenses.
         
     | 
| 
       14 
14 
     | 
    
         
             
                  #
         
     | 
| 
       15 
15 
     | 
    
         
             
                  # @example EnforcedStyle: squiggly (default)
         
     | 
| 
       16 
16 
     | 
    
         
             
                  #   # bad
         
     | 
| 
         @@ -49,7 +49,7 @@ module RuboCop 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  #     something
         
     | 
| 
       50 
50 
     | 
    
         
             
                  #   RUBY
         
     | 
| 
       51 
51 
     | 
    
         
             
                  #
         
     | 
| 
       52 
     | 
    
         
            -
                  class  
     | 
| 
      
 52 
     | 
    
         
            +
                  class HeredocIndentation < Cop
         
     | 
| 
       53 
53 
     | 
    
         
             
                    include Heredoc
         
     | 
| 
       54 
54 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
         @@ -159,11 +159,11 @@ module RuboCop 
     | 
|
| 
       159 
159 
     | 
    
         
             
                    end
         
     | 
| 
       160 
160 
     | 
    
         | 
| 
       161 
161 
     | 
    
         
             
                    def unlimited_heredoc_length?
         
     | 
| 
       162 
     | 
    
         
            -
                      config.for_cop(' 
     | 
| 
      
 162 
     | 
    
         
            +
                      config.for_cop('Layout/LineLength')['AllowHeredoc']
         
     | 
| 
       163 
163 
     | 
    
         
             
                    end
         
     | 
| 
       164 
164 
     | 
    
         | 
| 
       165 
165 
     | 
    
         
             
                    def max_line_length
         
     | 
| 
       166 
     | 
    
         
            -
                      config.for_cop(' 
     | 
| 
      
 166 
     | 
    
         
            +
                      config.for_cop('Layout/LineLength')['Max']
         
     | 
| 
       167 
167 
     | 
    
         
             
                    end
         
     | 
| 
       168 
168 
     | 
    
         | 
| 
       169 
169 
     | 
    
         
             
                    def correct_by_squiggly(node)
         
     | 
| 
         @@ -240,7 +240,7 @@ module RuboCop 
     | 
|
| 
       240 
240 
     | 
    
         
             
                    end
         
     | 
| 
       241 
241 
     | 
    
         | 
| 
       242 
242 
     | 
    
         
             
                    def indentation_width
         
     | 
| 
       243 
     | 
    
         
            -
                      @config.for_cop('IndentationWidth')['Width'] || 2
         
     | 
| 
      
 243 
     | 
    
         
            +
                      @config.for_cop('Layout/IndentationWidth')['Width'] || 2
         
     | 
| 
       244 
244 
     | 
    
         
             
                    end
         
     | 
| 
       245 
245 
     | 
    
         | 
| 
       246 
246 
     | 
    
         
             
                    def heredoc_body(node)
         
     | 
| 
         @@ -2,10 +2,9 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'uri'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            # rubocop:disable Metrics/ClassLength
         
     | 
| 
       6 
5 
     | 
    
         
             
            module RuboCop
         
     | 
| 
       7 
6 
     | 
    
         
             
              module Cop
         
     | 
| 
       8 
     | 
    
         
            -
                module  
     | 
| 
      
 7 
     | 
    
         
            +
                module Layout
         
     | 
| 
       9 
8 
     | 
    
         
             
                  # This cop checks the length of lines in the source code.
         
     | 
| 
       10 
9 
     | 
    
         
             
                  # The maximum length is configurable.
         
     | 
| 
       11 
10 
     | 
    
         
             
                  # The tab size is configured in the `IndentationWidth`
         
     | 
| 
         @@ -21,14 +20,14 @@ module RuboCop 
     | 
|
| 
       21 
20 
     | 
    
         
             
                  # If autocorrection is enabled, the following Layout cops
         
     | 
| 
       22 
21 
     | 
    
         
             
                  # are recommended to further format the broken lines.
         
     | 
| 
       23 
22 
     | 
    
         
             
                  #
         
     | 
| 
       24 
     | 
    
         
            -
                  #   -  
     | 
| 
       25 
     | 
    
         
            -
                  #   -  
     | 
| 
       26 
     | 
    
         
            -
                  #   - AlignParameters
         
     | 
| 
      
 23 
     | 
    
         
            +
                  #   - ParameterAlignment
         
     | 
| 
      
 24 
     | 
    
         
            +
                  #   - ArgumentAlignment
         
     | 
| 
       27 
25 
     | 
    
         
             
                  #   - ClosingParenthesisIndentation
         
     | 
| 
       28 
     | 
    
         
            -
                  #   -  
     | 
| 
       29 
     | 
    
         
            -
                  #   -  
     | 
| 
       30 
     | 
    
         
            -
                  #   -  
     | 
| 
       31 
     | 
    
         
            -
                  #   -  
     | 
| 
      
 26 
     | 
    
         
            +
                  #   - FirstArgumentIndentation
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #   - FirstArrayElementIndentation
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #   - FirstHashElementIndentation
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #   - FirstParameterIndentation
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #   - HashAlignment
         
     | 
| 
       32 
31 
     | 
    
         
             
                  #   - MultilineArrayLineBreaks
         
     | 
| 
       33 
32 
     | 
    
         
             
                  #   - MultilineHashBraceLayout
         
     | 
| 
       34 
33 
     | 
    
         
             
                  #   - MultilineHashKeyLineBreaks
         
     | 
| 
         @@ -58,6 +57,7 @@ module RuboCop 
     | 
|
| 
       58 
57 
     | 
    
         
             
                    include ConfigurableMax
         
     | 
| 
       59 
58 
     | 
    
         
             
                    include IgnoredPattern
         
     | 
| 
       60 
59 
     | 
    
         
             
                    include RangeHelp
         
     | 
| 
      
 60 
     | 
    
         
            +
                    include LineLengthHelp
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                    MSG = 'Line is too long. [%<length>d/%<max>d]'
         
     | 
| 
       63 
63 
     | 
    
         | 
| 
         @@ -68,6 +68,10 @@ module RuboCop 
     | 
|
| 
       68 
68 
     | 
    
         
             
                    alias on_hash on_potential_breakable_node
         
     | 
| 
       69 
69 
     | 
    
         
             
                    alias on_send on_potential_breakable_node
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
      
 71 
     | 
    
         
            +
                    def investigate(processed_source)
         
     | 
| 
      
 72 
     | 
    
         
            +
                      check_for_breakable_semicolons(processed_source)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
       71 
75 
     | 
    
         
             
                    def investigate_post_walk(processed_source)
         
     | 
| 
       72 
76 
     | 
    
         
             
                      processed_source.lines.each_with_index do |line, line_index|
         
     | 
| 
       73 
77 
     | 
    
         
             
                        check_line(line, line_index)
         
     | 
| 
         @@ -89,29 +93,41 @@ module RuboCop 
     | 
|
| 
       89 
93 
     | 
    
         
             
                      return if breakable_node.nil?
         
     | 
| 
       90 
94 
     | 
    
         | 
| 
       91 
95 
     | 
    
         
             
                      line_index = breakable_node.first_line - 1
         
     | 
| 
       92 
     | 
    
         
            -
                       
     | 
| 
       93 
     | 
    
         
            -
                    end
         
     | 
| 
      
 96 
     | 
    
         
            +
                      range = breakable_node.source_range
         
     | 
| 
       94 
97 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                       
     | 
| 
       97 
     | 
    
         
            -
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
                      existing = breakable_range_by_line_index[line_index]
         
     | 
| 
      
 99 
     | 
    
         
            +
                      return if existing
         
     | 
| 
       98 
100 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                      @heredocs ||= extract_heredocs(processed_source.ast)
         
     | 
| 
      
 101 
     | 
    
         
            +
                      breakable_range_by_line_index[line_index] = range
         
     | 
| 
       101 
102 
     | 
    
         
             
                    end
         
     | 
| 
       102 
103 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
                    def  
     | 
| 
       104 
     | 
    
         
            -
                       
     | 
| 
      
 104 
     | 
    
         
            +
                    def check_for_breakable_semicolons(processed_source)
         
     | 
| 
      
 105 
     | 
    
         
            +
                      tokens = processed_source.tokens.select { |t| t.type == :tSEMI }
         
     | 
| 
      
 106 
     | 
    
         
            +
                      tokens.reverse_each do |token|
         
     | 
| 
      
 107 
     | 
    
         
            +
                        range = breakable_range_after_semicolon(token)
         
     | 
| 
      
 108 
     | 
    
         
            +
                        breakable_range_by_line_index[range.line - 1] = range if range
         
     | 
| 
      
 109 
     | 
    
         
            +
                      end
         
     | 
| 
       105 
110 
     | 
    
         
             
                    end
         
     | 
| 
       106 
111 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                    def  
     | 
| 
       108 
     | 
    
         
            -
                       
     | 
| 
      
 112 
     | 
    
         
            +
                    def breakable_range_after_semicolon(semicolon_token)
         
     | 
| 
      
 113 
     | 
    
         
            +
                      range = semicolon_token.pos
         
     | 
| 
      
 114 
     | 
    
         
            +
                      end_pos = range.end_pos
         
     | 
| 
      
 115 
     | 
    
         
            +
                      next_range = range_between(end_pos, end_pos + 1)
         
     | 
| 
      
 116 
     | 
    
         
            +
                      return nil unless next_range.line == range.line
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                      next_char = next_range.source
         
     | 
| 
      
 119 
     | 
    
         
            +
                      return nil if /[\r\n]/ =~ next_char
         
     | 
| 
      
 120 
     | 
    
         
            +
                      return nil if next_char == ';'
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                      next_range
         
     | 
| 
      
 123 
     | 
    
         
            +
                    end
         
     | 
| 
       109 
124 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
                    def breakable_range_by_line_index
         
     | 
| 
      
 126 
     | 
    
         
            +
                      @breakable_range_by_line_index ||= {}
         
     | 
| 
       111 
127 
     | 
    
         
             
                    end
         
     | 
| 
       112 
128 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
                    def  
     | 
| 
       114 
     | 
    
         
            -
                       
     | 
| 
      
 129 
     | 
    
         
            +
                    def heredocs
         
     | 
| 
      
 130 
     | 
    
         
            +
                      @heredocs ||= extract_heredocs(processed_source.ast)
         
     | 
| 
       115 
131 
     | 
    
         
             
                    end
         
     | 
| 
       116 
132 
     | 
    
         | 
| 
       117 
133 
     | 
    
         
             
                    def highlight_start(line)
         
     | 
| 
         @@ -128,10 +144,7 @@ module RuboCop 
     | 
|
| 
       128 
144 
     | 
    
         
             
                      return check_uri_line(line, line_index) if allow_uri?
         
     | 
| 
       129 
145 
     | 
    
         | 
| 
       130 
146 
     | 
    
         
             
                      register_offense(
         
     | 
| 
       131 
     | 
    
         
            -
                         
     | 
| 
       132 
     | 
    
         
            -
                          processed_source.buffer, line_index,
         
     | 
| 
       133 
     | 
    
         
            -
                          highlight_start(line)...line_length(line)
         
     | 
| 
       134 
     | 
    
         
            -
                        ),
         
     | 
| 
      
 147 
     | 
    
         
            +
                        excess_range(nil, line, line_index),
         
     | 
| 
       135 
148 
     | 
    
         
             
                        line,
         
     | 
| 
       136 
149 
     | 
    
         
             
                        line_index
         
     | 
| 
       137 
150 
     | 
    
         
             
                      )
         
     | 
| 
         @@ -150,33 +163,12 @@ module RuboCop 
     | 
|
| 
       150 
163 
     | 
    
         
             
                    def register_offense(loc, line, line_index)
         
     | 
| 
       151 
164 
     | 
    
         
             
                      message = format(MSG, length: line_length(line), max: max)
         
     | 
| 
       152 
165 
     | 
    
         | 
| 
       153 
     | 
    
         
            -
                      breakable_range =  
     | 
| 
      
 166 
     | 
    
         
            +
                      breakable_range = breakable_range_by_line_index[line_index]
         
     | 
| 
       154 
167 
     | 
    
         
             
                      add_offense(breakable_range, location: loc, message: message) do
         
     | 
| 
       155 
168 
     | 
    
         
             
                        self.max = line_length(line)
         
     | 
| 
       156 
169 
     | 
    
         
             
                      end
         
     | 
| 
       157 
170 
     | 
    
         
             
                    end
         
     | 
| 
       158 
171 
     | 
    
         | 
| 
       159 
     | 
    
         
            -
                    def breakable_range(line, line_index)
         
     | 
| 
       160 
     | 
    
         
            -
                      return if line_in_heredoc?(line_index + 1)
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
                      semicolon_range = breakable_semicolon_range(line, line_index)
         
     | 
| 
       163 
     | 
    
         
            -
                      return semicolon_range if semicolon_range
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
                      breakable_node = breakable_nodes_by_line_index[line_index]
         
     | 
| 
       166 
     | 
    
         
            -
                      return breakable_node.source_range if breakable_node
         
     | 
| 
       167 
     | 
    
         
            -
                    end
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
                    def breakable_semicolon_range(line, line_index)
         
     | 
| 
       170 
     | 
    
         
            -
                      semicolon_separated_parts = line.split(';')
         
     | 
| 
       171 
     | 
    
         
            -
                      return if semicolon_separated_parts.length <= 1
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
                      column = semicolon_separated_parts.first.length + 1
         
     | 
| 
       174 
     | 
    
         
            -
                      range = source_range(processed_source.buffer, line_index, column, 1)
         
     | 
| 
       175 
     | 
    
         
            -
                      return if processed_source.commented?(range)
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                      range
         
     | 
| 
       178 
     | 
    
         
            -
                    end
         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
172 
     | 
    
         
             
                    def excess_range(uri_range, line, line_index)
         
     | 
| 
       181 
173 
     | 
    
         
             
                      excessive_position = if uri_range && uri_range.begin < max
         
     | 
| 
       182 
174 
     | 
    
         
             
                                             uri_range.end
         
     | 
| 
         @@ -225,53 +217,6 @@ module RuboCop 
     | 
|
| 
       225 
217 
     | 
    
         
             
                      end
         
     | 
| 
       226 
218 
     | 
    
         
             
                    end
         
     | 
| 
       227 
219 
     | 
    
         | 
| 
       228 
     | 
    
         
            -
                    def allow_uri?
         
     | 
| 
       229 
     | 
    
         
            -
                      cop_config['AllowURI']
         
     | 
| 
       230 
     | 
    
         
            -
                    end
         
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
                    def ignore_cop_directives?
         
     | 
| 
       233 
     | 
    
         
            -
                      cop_config['IgnoreCopDirectives']
         
     | 
| 
       234 
     | 
    
         
            -
                    end
         
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
                    def allowed_uri_position?(line, uri_range)
         
     | 
| 
       237 
     | 
    
         
            -
                      uri_range.begin < max &&
         
     | 
| 
       238 
     | 
    
         
            -
                        (uri_range.end == line_length(line) ||
         
     | 
| 
       239 
     | 
    
         
            -
                         uri_range.end == line_length(line) - 1)
         
     | 
| 
       240 
     | 
    
         
            -
                    end
         
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
                    def find_excessive_uri_range(line)
         
     | 
| 
       243 
     | 
    
         
            -
                      last_uri_match = match_uris(line).last
         
     | 
| 
       244 
     | 
    
         
            -
                      return nil unless last_uri_match
         
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
                      begin_position, end_position =
         
     | 
| 
       247 
     | 
    
         
            -
                        last_uri_match.offset(0).map do |pos|
         
     | 
| 
       248 
     | 
    
         
            -
                          pos + indentation_difference(line)
         
     | 
| 
       249 
     | 
    
         
            -
                        end
         
     | 
| 
       250 
     | 
    
         
            -
                      return nil if begin_position < max && end_position < max
         
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
                      begin_position...end_position
         
     | 
| 
       253 
     | 
    
         
            -
                    end
         
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
                    def match_uris(string)
         
     | 
| 
       256 
     | 
    
         
            -
                      matches = []
         
     | 
| 
       257 
     | 
    
         
            -
                      string.scan(uri_regexp) do
         
     | 
| 
       258 
     | 
    
         
            -
                        matches << $LAST_MATCH_INFO if valid_uri?($LAST_MATCH_INFO[0])
         
     | 
| 
       259 
     | 
    
         
            -
                      end
         
     | 
| 
       260 
     | 
    
         
            -
                      matches
         
     | 
| 
       261 
     | 
    
         
            -
                    end
         
     | 
| 
       262 
     | 
    
         
            -
             
     | 
| 
       263 
     | 
    
         
            -
                    def valid_uri?(uri_ish_string)
         
     | 
| 
       264 
     | 
    
         
            -
                      URI.parse(uri_ish_string)
         
     | 
| 
       265 
     | 
    
         
            -
                      true
         
     | 
| 
       266 
     | 
    
         
            -
                    rescue URI::InvalidURIError, NoMethodError
         
     | 
| 
       267 
     | 
    
         
            -
                      false
         
     | 
| 
       268 
     | 
    
         
            -
                    end
         
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
                    def uri_regexp
         
     | 
| 
       271 
     | 
    
         
            -
                      @uri_regexp ||=
         
     | 
| 
       272 
     | 
    
         
            -
                        URI::DEFAULT_PARSER.make_regexp(cop_config['URISchemes'])
         
     | 
| 
       273 
     | 
    
         
            -
                    end
         
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
220 
     | 
    
         
             
                    def check_directive_line(line, line_index)
         
     | 
| 
       276 
221 
     | 
    
         
             
                      return if line_length_without_directive(line) <= max
         
     | 
| 
       277 
222 
     | 
    
         | 
| 
         @@ -287,23 +232,6 @@ module RuboCop 
     | 
|
| 
       287 
232 
     | 
    
         
             
                      )
         
     | 
| 
       288 
233 
     | 
    
         
             
                    end
         
     | 
| 
       289 
234 
     | 
    
         | 
| 
       290 
     | 
    
         
            -
                    def directive_on_source_line?(line_index)
         
     | 
| 
       291 
     | 
    
         
            -
                      source_line_number = line_index + processed_source.buffer.first_line
         
     | 
| 
       292 
     | 
    
         
            -
                      comment =
         
     | 
| 
       293 
     | 
    
         
            -
                        processed_source
         
     | 
| 
       294 
     | 
    
         
            -
                        .comments
         
     | 
| 
       295 
     | 
    
         
            -
                        .detect { |e| e.location.line == source_line_number }
         
     | 
| 
       296 
     | 
    
         
            -
             
     | 
| 
       297 
     | 
    
         
            -
                      return false unless comment
         
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
       299 
     | 
    
         
            -
                      comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
         
     | 
| 
       300 
     | 
    
         
            -
                    end
         
     | 
| 
       301 
     | 
    
         
            -
             
     | 
| 
       302 
     | 
    
         
            -
                    def line_length_without_directive(line)
         
     | 
| 
       303 
     | 
    
         
            -
                      before_comment, = line.split(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
         
     | 
| 
       304 
     | 
    
         
            -
                      before_comment.rstrip.length
         
     | 
| 
       305 
     | 
    
         
            -
                    end
         
     | 
| 
       306 
     | 
    
         
            -
             
     | 
| 
       307 
235 
     | 
    
         
             
                    def check_uri_line(line, line_index)
         
     | 
| 
       308 
236 
     | 
    
         
             
                      uri_range = find_excessive_uri_range(line)
         
     | 
| 
       309 
237 
     | 
    
         
             
                      return if uri_range && allowed_uri_position?(line, uri_range)
         
     | 
| 
         @@ -318,4 +246,3 @@ module RuboCop 
     | 
|
| 
       318 
246 
     | 
    
         
             
                end
         
     | 
| 
       319 
247 
     | 
    
         
             
              end
         
     | 
| 
       320 
248 
     | 
    
         
             
            end
         
     | 
| 
       321 
     | 
    
         
            -
            # rubocop:enable Metrics/ClassLength
         
     |