rubocop 0.52.0 → 0.52.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -5
  3. data/config/default.yml +1 -11
  4. data/config/disabled.yml +5 -0
  5. data/config/enabled.yml +6 -8
  6. data/lib/rubocop.rb +13 -2
  7. data/lib/rubocop/ast/node.rb +23 -15
  8. data/lib/rubocop/cli.rb +25 -2
  9. data/lib/rubocop/config.rb +23 -8
  10. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
  11. data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
  12. data/lib/rubocop/cop/commissioner.rb +1 -1
  13. data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
  14. data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
  15. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
  16. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
  17. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
  18. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
  19. data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
  20. data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
  21. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
  22. data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
  23. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  24. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
  25. data/lib/rubocop/cop/generator.rb +18 -87
  26. data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
  27. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  28. data/lib/rubocop/cop/layout/align_array.rb +5 -1
  29. data/lib/rubocop/cop/layout/align_hash.rb +1 -1
  30. data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
  31. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  32. data/lib/rubocop/cop/layout/class_structure.rb +2 -2
  33. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
  34. data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
  35. data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
  36. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
  37. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
  38. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
  39. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
  40. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
  41. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
  42. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
  43. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
  44. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
  45. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
  46. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
  47. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
  48. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
  49. data/lib/rubocop/cop/layout/indent_array.rb +6 -2
  50. data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
  51. data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
  52. data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
  53. data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
  54. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
  55. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
  56. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
  57. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
  58. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
  59. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
  60. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
  61. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
  62. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
  63. data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
  64. data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
  65. data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
  66. data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
  67. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
  68. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
  69. data/lib/rubocop/cop/layout/tab.rb +1 -1
  70. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  71. data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
  72. data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
  73. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  74. data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
  75. data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
  76. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
  77. data/lib/rubocop/cop/mixin/alignment.rb +70 -0
  78. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
  79. data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
  80. data/lib/rubocop/cop/mixin/code_length.rb +2 -0
  81. data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
  82. data/lib/rubocop/cop/mixin/def_node.rb +3 -1
  83. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  84. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
  85. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
  86. data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
  87. data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
  88. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
  89. data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
  90. data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
  91. data/lib/rubocop/cop/mixin/match_range.rb +2 -0
  92. data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
  93. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  94. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
  95. data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
  96. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
  97. data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
  98. data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
  99. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
  100. data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
  101. data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
  102. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
  103. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
  104. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
  105. data/lib/rubocop/cop/mixin/string_help.rb +2 -0
  106. data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
  107. data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
  108. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
  109. data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
  110. data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
  111. data/lib/rubocop/cop/rails/action_filter.rb +3 -2
  112. data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
  113. data/lib/rubocop/cop/rails/application_job.rb +6 -0
  114. data/lib/rubocop/cop/rails/application_record.rb +6 -0
  115. data/lib/rubocop/cop/rails/blank.rb +10 -9
  116. data/lib/rubocop/cop/rails/date.rb +22 -14
  117. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  118. data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
  119. data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
  120. data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
  121. data/lib/rubocop/cop/rails/file_path.rb +1 -1
  122. data/lib/rubocop/cop/rails/find_by.rb +2 -2
  123. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
  124. data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
  125. data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
  126. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
  127. data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
  128. data/lib/rubocop/cop/rails/presence.rb +31 -18
  129. data/lib/rubocop/cop/rails/present.rb +11 -8
  130. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
  131. data/lib/rubocop/cop/rails/request_referer.rb +2 -3
  132. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
  133. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
  134. data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
  135. data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
  136. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  137. data/lib/rubocop/cop/style/format_string_token.rb +24 -4
  138. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
  139. data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
  140. data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
  141. data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
  142. data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
  143. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  144. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
  145. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  146. data/lib/rubocop/cop/style/negated_while.rb +6 -4
  147. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  148. data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
  149. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  150. data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
  151. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  152. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  153. data/lib/rubocop/cop/style/string_literals.rb +4 -0
  154. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
  155. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
  156. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
  157. data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
  158. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
  159. data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
  160. data/lib/rubocop/options.rb +33 -10
  161. data/lib/rubocop/path_util.rb +7 -0
  162. data/lib/rubocop/token.rb +4 -0
  163. data/lib/rubocop/version.rb +1 -1
  164. metadata +14 -4
  165. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
  166. data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # This default style is called 'special_inside_parentheses'. Alternative
20
20
  # styles are 'consistent' and 'align_brackets'. Here are examples:
21
21
  #
22
- # @example EnforcedStyle: special_inside_parentheses
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
25
  # # element are on seprate lines is indented one step (two spaces) more
@@ -80,7 +80,7 @@ module RuboCop
80
80
  # :completely_different
81
81
  # ]
82
82
  class IndentArray < Cop
83
- include AutocorrectAlignment
83
+ include Alignment
84
84
  include ConfigurableEnforcedStyle
85
85
  include ArrayHashIndentation
86
86
 
@@ -97,6 +97,10 @@ module RuboCop
97
97
  end
98
98
  end
99
99
 
100
+ def autocorrect(node)
101
+ AlignmentCorrector.correct(processed_source, node, @column_delta)
102
+ end
103
+
100
104
  private
101
105
 
102
106
  def brace_alignment_style
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # other cops such as `IndentationConsistency` and `EndAlignment`.
24
24
  class IndentAssignment < Cop
25
25
  include CheckAssignment
26
- include AutocorrectAlignment
26
+ include Alignment
27
27
 
28
28
  MSG = 'Indent the first line of the right-hand-side of a ' \
29
29
  'multi-line assignment.'.freeze
@@ -31,11 +31,15 @@ module RuboCop
31
31
  def check_assignment(node, rhs)
32
32
  return unless rhs
33
33
  return unless node.loc.operator
34
- return if node.loc.operator.line == rhs.loc.line
34
+ return if node.loc.operator.line == rhs.first_line
35
35
 
36
36
  base = display_column(node.source_range)
37
37
  check_alignment([rhs], base + configured_indentation_width)
38
38
  end
39
+
40
+ def autocorrect(node)
41
+ AlignmentCorrector.correct(processed_source, node, column_delta)
42
+ end
39
43
  end
40
44
  end
41
45
  end
@@ -78,7 +78,7 @@ module RuboCop
78
78
  # completely: :different
79
79
  # }
80
80
  class IndentHash < Cop
81
- include AutocorrectAlignment
81
+ include Alignment
82
82
  include ConfigurableEnforcedStyle
83
83
  include ArrayHashIndentation
84
84
 
@@ -95,6 +95,10 @@ module RuboCop
95
95
  end
96
96
  end
97
97
 
98
+ def autocorrect(node)
99
+ AlignmentCorrector.correct(processed_source, node, @column_delta)
100
+ end
101
+
98
102
  private
99
103
 
100
104
  def brace_alignment_style
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # end
15
15
  # end
16
16
  class IndentationConsistency < Cop
17
- include AutocorrectAlignment
17
+ include Alignment
18
18
  include ConfigurableEnforcedStyle
19
19
 
20
20
  MSG = 'Inconsistent indentation detected.'.freeze
@@ -27,6 +27,10 @@ module RuboCop
27
27
  check(node)
28
28
  end
29
29
 
30
+ def autocorrect(node)
31
+ AlignmentCorrector.correct(processed_source, node, column_delta)
32
+ end
33
+
30
34
  private
31
35
 
32
36
  def check(node)
@@ -44,7 +44,7 @@ module RuboCop
44
44
  # end
45
45
  class IndentationWidth < Cop
46
46
  include EndKeywordAlignment
47
- include AutocorrectAlignment
47
+ include Alignment
48
48
  include CheckAssignment
49
49
  include IgnoredPattern
50
50
 
@@ -141,6 +141,10 @@ module RuboCop
141
141
  check_if(node, node.body, node.else_branch, base.loc)
142
142
  end
143
143
 
144
+ def autocorrect(node)
145
+ AlignmentCorrector.correct(processed_source, node, @column_delta)
146
+ end
147
+
144
148
  private
145
149
 
146
150
  def check_members(base, members)
@@ -108,6 +108,10 @@ module RuboCop
108
108
  def on_array(node)
109
109
  check_brace_layout(node)
110
110
  end
111
+
112
+ def autocorrect(node)
113
+ MultilineLiteralBraceCorrector.correct(processed_source, node)
114
+ end
111
115
  end
112
116
  end
113
117
  end
@@ -44,7 +44,7 @@ module RuboCop
44
44
  def check_assignment(node, rhs)
45
45
  return unless rhs
46
46
  return unless supported_types.include?(rhs.type)
47
- return if rhs.loc.first_line == rhs.loc.last_line
47
+ return if rhs.first_line == rhs.last_line
48
48
 
49
49
  case style
50
50
  when :new_line
@@ -55,13 +55,13 @@ module RuboCop
55
55
  end
56
56
 
57
57
  def check_new_line_offense(node, rhs)
58
- return unless node.loc.operator.line == rhs.loc.line
58
+ return unless node.loc.operator.line == rhs.first_line
59
59
 
60
60
  add_offense(node, message: NEW_LINE_OFFENSE)
61
61
  end
62
62
 
63
63
  def check_same_line_offense(node, rhs)
64
- return unless node.loc.operator.line != rhs.loc.line
64
+ return unless node.loc.operator.line != rhs.first_line
65
65
 
66
66
  add_offense(node, message: SAME_LINE_OFFENSE)
67
67
  end
@@ -48,7 +48,7 @@ module RuboCop
48
48
  add_offense_for_expression(node, node.arguments, ARG_MSG)
49
49
  end
50
50
 
51
- return unless node.body && node.loc.begin.line == node.body.loc.line
51
+ return unless node.body && node.loc.begin.line == node.body.first_line
52
52
 
53
53
  add_offense_for_expression(node, node.body, MSG)
54
54
  end
@@ -64,7 +64,7 @@ module RuboCop
64
64
 
65
65
  expr_before_body ||= node.loc.begin
66
66
 
67
- if expr_before_body.line == node.body.loc.line
67
+ if expr_before_body.line == node.body.first_line
68
68
  autocorrect_body(corrector, node, node.body)
69
69
  end
70
70
  end
@@ -112,6 +112,10 @@ module RuboCop
112
112
  def on_hash(node)
113
113
  check_brace_layout(node)
114
114
  end
115
+
116
+ def autocorrect(node)
117
+ MultilineLiteralBraceCorrector.correct(processed_source, node)
118
+ end
115
119
  end
116
120
  end
117
121
  end
@@ -76,6 +76,10 @@ module RuboCop
76
76
  check_brace_layout(node)
77
77
  end
78
78
 
79
+ def autocorrect(node)
80
+ MultilineLiteralBraceCorrector.correct(processed_source, node)
81
+ end
82
+
79
83
  private
80
84
 
81
85
  def children(node)
@@ -48,7 +48,7 @@ module RuboCop
48
48
  # .c
49
49
  class MultilineMethodCallIndentation < Cop
50
50
  include ConfigurableEnforcedStyle
51
- include AutocorrectAlignment
51
+ include Alignment
52
52
  include MultilineExpressionIndentation
53
53
 
54
54
  def validate_config
@@ -61,6 +61,10 @@ module RuboCop
61
61
  '`EnforcedStyle` is `indented`.'
62
62
  end
63
63
 
64
+ def autocorrect(node)
65
+ AlignmentCorrector.correct(processed_source, node, @column_delta)
66
+ end
67
+
64
68
  private
65
69
 
66
70
  def relevant_node?(send_node)
@@ -191,7 +195,7 @@ module RuboCop
191
195
  node = node.parent
192
196
  node = node.parent until node.loc.dot
193
197
 
194
- return if node.loc.dot.line != node.loc.line
198
+ return if node.loc.dot.line != node.first_line
195
199
  node
196
200
  end
197
201
 
@@ -80,6 +80,10 @@ module RuboCop
80
80
  check_brace_layout(node.arguments)
81
81
  end
82
82
  alias on_defs on_def
83
+
84
+ def autocorrect(node)
85
+ MultilineLiteralBraceCorrector.correct(processed_source, node)
86
+ end
83
87
  end
84
88
  end
85
89
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # end
21
21
  class MultilineOperationIndentation < Cop
22
22
  include ConfigurableEnforcedStyle
23
- include AutocorrectAlignment
23
+ include Alignment
24
24
  include MultilineExpressionIndentation
25
25
 
26
26
  def on_and(node)
@@ -40,6 +40,10 @@ module RuboCop
40
40
  '`EnforcedStyle` is `indented`.'
41
41
  end
42
42
 
43
+ def autocorrect(node)
44
+ AlignmentCorrector.correct(processed_source, node, @column_delta)
45
+ end
46
+
43
47
  private
44
48
 
45
49
  def relevant_node?(node)
@@ -54,7 +58,7 @@ module RuboCop
54
58
 
55
59
  def offending_range(node, lhs, rhs, given_style)
56
60
  return false unless begins_its_line?(rhs)
57
- return false if lhs.loc.line == rhs.line # Needed for unary op.
61
+ return false if lhs.first_line == rhs.line # Needed for unary op.
58
62
  return false if not_for_this_cop?(node)
59
63
 
60
64
  correct_column = if should_align?(node, rhs, given_style)
@@ -86,7 +86,9 @@ module RuboCop
86
86
  end
87
87
 
88
88
  def ancestor_node(node)
89
- node.each_ancestor(:kwbegin, :def, :defs, :class, :module).first
89
+ types = %i[kwbegin def defs class module]
90
+ types << :block if target_ruby_version >= 2.5
91
+ node.each_ancestor(*types).first
90
92
  end
91
93
  end
92
94
  end
@@ -17,6 +17,10 @@ module RuboCop
17
17
  class SpaceAfterComma < Cop
18
18
  include SpaceAfterPunctuation
19
19
 
20
+ def autocorrect(comma)
21
+ PunctuationCorrector.add_space(comma)
22
+ end
23
+
20
24
  def space_style_before_rcurly
21
25
  cfg = config.for_cop('Layout/SpaceInsideHashLiteralBraces')
22
26
  cfg['EnforcedStyle'] || 'space'
@@ -14,6 +14,10 @@ module RuboCop
14
14
  class SpaceAfterSemicolon < Cop
15
15
  include SpaceAfterPunctuation
16
16
 
17
+ def autocorrect(semicolon)
18
+ PunctuationCorrector.add_space(semicolon)
19
+ end
20
+
17
21
  def space_style_before_rcurly
18
22
  cfg = config.for_cop('Layout/SpaceInsideBlockBraces')
19
23
  cfg['EnforcedStyle'] || 'space'
@@ -18,6 +18,10 @@ module RuboCop
18
18
  class SpaceBeforeComma < Cop
19
19
  include SpaceBeforePunctuation
20
20
 
21
+ def autocorrect(space)
22
+ PunctuationCorrector.remove_space(space)
23
+ end
24
+
21
25
  def kind(token)
22
26
  'comma' if token.comma?
23
27
  end
@@ -14,6 +14,10 @@ module RuboCop
14
14
  class SpaceBeforeSemicolon < Cop
15
15
  include SpaceBeforePunctuation
16
16
 
17
+ def autocorrect(space)
18
+ PunctuationCorrector.remove_space(space)
19
+ end
20
+
17
21
  def kind(token)
18
22
  'semicolon' if token.semicolon?
19
23
  end
@@ -63,9 +63,10 @@ module RuboCop
63
63
  if empty_brackets?(left, right)
64
64
  empty_corrections(corrector, left, right)
65
65
  elsif style == :no_space
66
- no_space_corrector(corrector, left, right)
66
+ SpaceCorrector.remove_space(processed_source, corrector,
67
+ left, right)
67
68
  elsif style == :space
68
- space_corrector(corrector, left, right)
69
+ SpaceCorrector.add_space(processed_source, corrector, left, right)
69
70
  else
70
71
  compact_corrections(corrector, node, left, right)
71
72
  end
@@ -39,7 +39,7 @@ module RuboCop
39
39
  return if node.multiline?
40
40
  return unless left_ref_bracket(node)
41
41
  left_token = left_ref_bracket(node)
42
- right_token = right_ref_bracket(node, left_token)
42
+ right_token = closing_bracket(node, left_token)
43
43
 
44
44
  if style == :no_space
45
45
  no_space_offenses(node, left_token, right_token, MSG)
@@ -53,9 +53,10 @@ module RuboCop
53
53
  left, right = reference_brackets(node)
54
54
 
55
55
  if style == :no_space
56
- no_space_corrector(corrector, left, right)
56
+ SpaceCorrector.remove_space(processed_source, corrector,
57
+ left, right)
57
58
  else
58
- space_corrector(corrector, left, right)
59
+ SpaceCorrector.add_space(processed_source, corrector, left, right)
59
60
  end
60
61
  end
61
62
  end
@@ -64,16 +65,24 @@ module RuboCop
64
65
 
65
66
  def reference_brackets(node)
66
67
  left = left_ref_bracket(node)
67
- [left, right_ref_bracket(node, left)]
68
+ [left, closing_bracket(node, left)]
68
69
  end
69
70
 
70
71
  def left_ref_bracket(node)
71
72
  tokens(node).reverse.find(&:left_ref_bracket?)
72
73
  end
73
74
 
74
- def right_ref_bracket(node, token)
75
- i = tokens(node).index(token)
76
- tokens(node).slice(i..-1).find(&:right_bracket?)
75
+ def closing_bracket(node, opening_bracket)
76
+ i = tokens(node).index(opening_bracket)
77
+ inner_left_brackets_needing_closure = 0
78
+
79
+ tokens(node)[i..-1].each do |token|
80
+ inner_left_brackets_needing_closure += 1 if token.left_bracket?
81
+ inner_left_brackets_needing_closure -= 1 if token.right_bracket?
82
+ if inner_left_brackets_needing_closure.zero? && token.right_bracket?
83
+ return token
84
+ end
85
+ end
77
86
  end
78
87
  end
79
88
  end
@@ -7,7 +7,7 @@ module RuboCop
7
7
  module Layout
8
8
  # This cop checks for tabs inside the source code.
9
9
  class Tab < Cop
10
- include AutocorrectAlignment
10
+ include Alignment
11
11
 
12
12
  MSG = 'Tab detected.'.freeze
13
13
 
@@ -124,7 +124,7 @@ module RuboCop
124
124
  end
125
125
 
126
126
  def disqualified_parent?(parent, node)
127
- parent && parent.loc && parent.loc.line != node.loc.line &&
127
+ parent && parent.loc && parent.first_line != node.first_line &&
128
128
  !parent.masgn_type?
129
129
  end
130
130
 
@@ -62,9 +62,9 @@ module RuboCop
62
62
 
63
63
  def autocorrect(node)
64
64
  if style == :start_of_line && node.parent && node.parent.send_type?
65
- align(node, node.parent)
65
+ AlignmentCorrector.align_end(processed_source, node, node.parent)
66
66
  else
67
- align(node, node)
67
+ AlignmentCorrector.align_end(processed_source, node, node)
68
68
  end
69
69
  end
70
70
  end
@@ -82,7 +82,9 @@ module RuboCop
82
82
  end
83
83
 
84
84
  def autocorrect(node)
85
- align(node, alignment_node(node))
85
+ AlignmentCorrector.align_end(processed_source,
86
+ node,
87
+ alignment_node(node))
86
88
  end
87
89
 
88
90
  private
@@ -49,7 +49,7 @@ module RuboCop
49
49
  node.children.each_cons(2) do |child1, child2|
50
50
  # `'abc' 'def'` -> (dstr (str "abc") (str "def"))
51
51
  next unless string_literal?(child1) && string_literal?(child2)
52
- next unless child1.loc.last_line == child2.loc.line
52
+ next unless child1.last_line == child2.first_line
53
53
 
54
54
  # Make sure we don't flag a string literal which simply has
55
55
  # embedded newlines
@@ -39,6 +39,10 @@ module RuboCop
39
39
  class UnusedBlockArgument < Cop
40
40
  include UnusedArgument
41
41
 
42
+ def autocorrect(node)
43
+ UnusedArgCorrector.correct(processed_source, node)
44
+ end
45
+
42
46
  private
43
47
 
44
48
  def check_argument(variable)