rubocop 0.52.0 → 0.52.1

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.
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
@@ -60,7 +60,7 @@ module RuboCop
60
60
 
61
61
  def offensive?(line)
62
62
  line = line.lstrip
63
- line.start_with?(*KEYWORDS) &&
63
+ KEYWORDS.any? { |word| line =~ /^#{word}\s/ } &&
64
64
  ALLOWED_COMMENTS.none? { |c| line =~ /#\s*#{c}/ }
65
65
  end
66
66
 
@@ -137,7 +137,7 @@ module RuboCop
137
137
  add_offense(
138
138
  node,
139
139
  location: line_node.loc.expression,
140
- message: message_incorrect_line(line_node, sign, line_diff)
140
+ message: message_incorrect_line(line_node, sign, line_diff.abs)
141
141
  )
142
142
  end
143
143
  end
@@ -5,6 +5,13 @@ module RuboCop
5
5
  module Style
6
6
  # Use a consistent style for named format string tokens.
7
7
  #
8
+ # **Note:**
9
+ # `unannotated` style cop only works for strings
10
+ # which are passed as arguments to those methods:
11
+ # `sprintf`, `format`, `%`.
12
+ # The reason is that *unannotated* format is very similar
13
+ # to encoded URLs or Date/Time formatting strings.
14
+ #
8
15
  # @example EnforcedStyle: annotated (default)
9
16
  #
10
17
  # # bad
@@ -35,6 +42,7 @@ module RuboCop
35
42
  include ConfigurableEnforcedStyle
36
43
 
37
44
  FIELD_CHARACTERS = Regexp.union(%w[A B E G X a b c d e f g i o p s u x])
45
+ FORMAT_STRING_METHODS = %i[sprintf format %].freeze
38
46
 
39
47
  STYLE_PATTERNS = {
40
48
  annotated: /(?<token>%<[^>]+>#{FIELD_CHARACTERS})/,
@@ -42,13 +50,12 @@ module RuboCop
42
50
  unannotated: /(?<token>%#{FIELD_CHARACTERS})/
43
51
  }.freeze
44
52
 
45
- TOKEN_PATTERN = Regexp.union(STYLE_PATTERNS.values)
46
-
47
53
  def on_str(node)
48
- return if node.each_ancestor(:xstr).any?
54
+ return if node.each_ancestor(:xstr, :regexp).any?
49
55
 
50
56
  tokens(node) do |detected_style, token_range|
51
- if detected_style == style
57
+ if detected_style == style ||
58
+ unannotated_format?(node, detected_style)
52
59
  correct_style_detected
53
60
  else
54
61
  style_detected(detected_style)
@@ -60,6 +67,19 @@ module RuboCop
60
67
 
61
68
  private
62
69
 
70
+ def includes_format_methods?(node)
71
+ root_node = node.ancestors.last
72
+ return unless root_node
73
+
74
+ root_node.descendants.any? do |desc_node|
75
+ FORMAT_STRING_METHODS.include?(desc_node.method_name)
76
+ end
77
+ end
78
+
79
+ def unannotated_format?(node, detected_style)
80
+ detected_style == :unannotated && !includes_format_methods?(node)
81
+ end
82
+
63
83
  def message(detected_style)
64
84
  "Prefer #{message_text(style)} over #{message_text(detected_style)}."
65
85
  end
@@ -8,6 +8,52 @@ module RuboCop
8
8
  # enable frozen string literals. Frozen string literals may be default
9
9
  # in Ruby 3.0. The comment will be added below a shebang and encoding
10
10
  # comment. The frozen string literal comment is only valid in Ruby 2.3+.
11
+ #
12
+ # @example EnforcedStyle: when_needed (default)
13
+ # # The `when_needed` style will add the frozen string literal comment
14
+ # # to files only when the `TargetRubyVersion` is set to 2.3+.
15
+ # # bad
16
+ # module Foo
17
+ # # ...
18
+ # end
19
+ #
20
+ # # good
21
+ # # frozen_string_literal: true
22
+ #
23
+ # module Foo
24
+ # # ...
25
+ # end
26
+ #
27
+ # @example EnforcedStyle: always
28
+ # # The `always` style will always add the frozen string literal comment
29
+ # # to a file, regardless of the Ruby version or if `freeze` or `<<` are
30
+ # # called on a string literal.
31
+ # # bad
32
+ # module Bar
33
+ # # ...
34
+ # end
35
+ #
36
+ # # good
37
+ # # frozen_string_literal: true
38
+ #
39
+ # module Bar
40
+ # # ...
41
+ # end
42
+ #
43
+ # @example EnforcedStyle: never
44
+ # # The `never` will enforce that the frozen string literal comment does
45
+ # # not exist in a file.
46
+ # # bad
47
+ # # frozen_string_literal: true
48
+ #
49
+ # module Baz
50
+ # # ...
51
+ # end
52
+ #
53
+ # # good
54
+ # module Baz
55
+ # # ...
56
+ # end
11
57
  class FrozenStringLiteralComment < Cop
12
58
  include ConfigurableEnforcedStyle
13
59
  include FrozenStringLiteral
@@ -173,11 +173,12 @@ module RuboCop
173
173
  range = range_between(key.source_range.begin_pos, op.end_pos)
174
174
  range = range_with_surrounding_space(range: range, side: :right)
175
175
 
176
- new_key = key.sym_type? ? key.value : key.source
177
-
178
176
  space = argument_without_space?(pair_node.parent) ? ' ' : ''
179
177
 
180
- corrector.replace(range, "#{space}#{new_key}: ")
178
+ corrector.replace(
179
+ range,
180
+ range.source.sub(/^:(.*\S)\s*=>\s*$/, space.to_s + '\1: ')
181
+ )
181
182
  end
182
183
 
183
184
  def argument_without_space?(node)
@@ -6,6 +6,20 @@ module RuboCop
6
6
  # Checks for if and unless statements that would fit on one line
7
7
  # if written as a modifier if/unless. The maximum line length is
8
8
  # configured in the `Metrics/LineLength` cop.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # if condition
13
+ # do_stuff(bar)
14
+ # end
15
+ #
16
+ # unless qux.empty?
17
+ # Foo.do_something
18
+ # end
19
+ #
20
+ # # good
21
+ # do_stuff(bar) if condition
22
+ # Foo.do_something unless qux.empty?
9
23
  class IfUnlessModifier < Cop
10
24
  include StatementModifier
11
25
 
@@ -5,6 +5,85 @@ module RuboCop
5
5
  module Style
6
6
  # This cops checks for parentheses around the arguments in method
7
7
  # definitions. Both instance and class/singleton methods are checked.
8
+ #
9
+ # @example EnforcedStyle: require_parentheses (default)
10
+ # # The `require_parentheses` style requires method definitions
11
+ # # to always use parentheses
12
+ #
13
+ # # bad
14
+ # def bar num1, num2
15
+ # num1 + num2
16
+ # end
17
+ #
18
+ # def foo descriptive_var_name,
19
+ # another_descriptive_var_name,
20
+ # last_descriptive_var_name
21
+ # do_something
22
+ # end
23
+ #
24
+ # # good
25
+ # def bar(num1, num2)
26
+ # num1 + num2
27
+ # end
28
+ #
29
+ # def foo(descriptive_var_name,
30
+ # another_descriptive_var_name,
31
+ # last_descriptive_var_name)
32
+ # do_something
33
+ # end
34
+ #
35
+ # @example EnforcedStyle: require_no_parentheses
36
+ # # The `require_no_parentheses` style requires method definitions
37
+ # # to never use parentheses
38
+ #
39
+ # # bad
40
+ # def bar(num1, num2)
41
+ # num1 + num2
42
+ # end
43
+ #
44
+ # def foo(descriptive_var_name,
45
+ # another_descriptive_var_name,
46
+ # last_descriptive_var_name)
47
+ # do_something
48
+ # end
49
+ #
50
+ # # good
51
+ # def bar num1, num2
52
+ # num1 + num2
53
+ # end
54
+ #
55
+ # def foo descriptive_var_name,
56
+ # another_descriptive_var_name,
57
+ # last_descriptive_var_name
58
+ # do_something
59
+ # end
60
+ #
61
+ # @example EnforcedStyle: require_no_parentheses_except_multiline
62
+ # # The `require_no_parentheses_except_multiline` style prefers no
63
+ # # parantheses when method definition arguments fit on single line,
64
+ # # but prefers parantheses when arguments span multiple lines.
65
+ #
66
+ # # bad
67
+ # def bar(num1, num2)
68
+ # num1 + num2
69
+ # end
70
+ #
71
+ # def foo descriptive_var_name,
72
+ # another_descriptive_var_name,
73
+ # last_descriptive_var_name
74
+ # do_something
75
+ # end
76
+ #
77
+ # # good
78
+ # def bar num1, num2
79
+ # num1 + num2
80
+ # end
81
+ #
82
+ # def foo(descriptive_var_name,
83
+ # another_descriptive_var_name,
84
+ # last_descriptive_var_name)
85
+ # do_something
86
+ # end
8
87
  class MethodDefParentheses < Cop
9
88
  include ConfigurableEnforcedStyle
10
89
 
@@ -53,8 +53,9 @@ module RuboCop
53
53
 
54
54
  def on_send(node)
55
55
  include_statement(node) do |statement|
56
- return if node.argument?
57
- return if accepted_include?(node)
56
+ return if node.argument? ||
57
+ accepted_include?(node) ||
58
+ belongs_to_class_or_module?(node)
58
59
 
59
60
  add_offense(node, message: format(MSG, statement: statement))
60
61
  end
@@ -65,6 +66,16 @@ module RuboCop
65
66
  def accepted_include?(node)
66
67
  node.parent && node.macro?
67
68
  end
69
+
70
+ def belongs_to_class_or_module?(node)
71
+ if !node.parent
72
+ false
73
+ else
74
+ return true if node.parent.class_type? || node.parent.module_type?
75
+
76
+ belongs_to_class_or_module?(node.parent)
77
+ end
78
+ end
68
79
  end
69
80
  end
70
81
  end
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # { result: 'ok' } if cond
17
17
  class MultilineIfModifier < Cop
18
18
  include StatementModifier
19
- include AutocorrectAlignment
19
+ include Alignment
20
20
 
21
21
  MSG = 'Favor a normal %<keyword>s-statement over a modifier' \
22
22
  ' clause in a multiline statement.'.freeze
@@ -4,6 +4,25 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # This cop checks for multi-line ternary op expressions.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # a = cond ?
11
+ # b : c
12
+ # a = cond ? b :
13
+ # c
14
+ # a = cond ?
15
+ # b :
16
+ # c
17
+ #
18
+ # # good
19
+ # a = cond ? b : c
20
+ # a =
21
+ # if cond
22
+ # b
23
+ # else
24
+ # c
25
+ # end
7
26
  class MultilineTernaryOperator < Cop
8
27
  MSG = 'Avoid multi-line ternary operators, ' \
9
28
  'use `if` or `unless` instead.'.freeze
@@ -80,7 +80,7 @@ module RuboCop
80
80
  end
81
81
 
82
82
  def autocorrect(node)
83
- negative_conditional_corrector(node)
83
+ ConditionCorrector.correct_negative_condition(node)
84
84
  end
85
85
 
86
86
  private
@@ -15,12 +15,14 @@ module RuboCop
15
15
  check_negative_conditional(node)
16
16
  end
17
17
 
18
- def message(node)
19
- format(MSG, inverse: node.inverse_keyword, current: node.keyword)
18
+ def autocorrect(node)
19
+ ConditionCorrector.correct_negative_condition(node)
20
20
  end
21
21
 
22
- def autocorrect(node)
23
- negative_conditional_corrector(node)
22
+ private
23
+
24
+ def message(node)
25
+ format(MSG, inverse: node.inverse_keyword, current: node.keyword)
24
26
  end
25
27
  end
26
28
  end
@@ -174,7 +174,7 @@ module RuboCop
174
174
 
175
175
  # An internal class for correcting parallel assignment
176
176
  class GenericCorrector
177
- include AutocorrectAlignment
177
+ include Alignment
178
178
 
179
179
  attr_reader :config, :node
180
180
 
@@ -37,6 +37,10 @@ module RuboCop
37
37
  end
38
38
  alias on_until on_while
39
39
 
40
+ def autocorrect(node)
41
+ ParenthesesCorrector.correct(node)
42
+ end
43
+
40
44
  private
41
45
 
42
46
  def_node_matcher :control_op_condition, <<-PATTERN
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # # good
26
26
  # x != y
27
27
  class RedundantConditional < Cop
28
- include AutocorrectAlignment
28
+ include Alignment
29
29
 
30
30
  COMPARISON_OPERATORS = RuboCop::AST::Node::COMPARISON_OPERATORS
31
31
 
@@ -31,6 +31,10 @@ module RuboCop
31
31
  check(node)
32
32
  end
33
33
 
34
+ def autocorrect(node)
35
+ ParenthesesCorrector.correct(node)
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def parens_allowed?(node)
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # handle_error
17
17
  # end
18
18
  class RescueModifier < Cop
19
- include AutocorrectAlignment
19
+ include Alignment
20
20
  include RescueNode
21
21
 
22
22
  MSG = 'Avoid using `rescue` in its modifier form.'.freeze
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # def @table.columns; end
19
19
  #
20
20
  class SingleLineMethods < Cop
21
- include AutocorrectAlignment
21
+ include Alignment
22
22
 
23
23
  MSG = 'Avoid single-line method definitions.'.freeze
24
24
 
@@ -54,6 +54,10 @@ module RuboCop
54
54
  ignore_node(node)
55
55
  end
56
56
 
57
+ def autocorrect(node)
58
+ StringLiteralCorrector.correct(node, style)
59
+ end
60
+
57
61
  private
58
62
 
59
63
  def all_string_literals?(nodes)
@@ -23,6 +23,10 @@ module RuboCop
23
23
  include ConfigurableEnforcedStyle
24
24
  include StringLiteralsHelp
25
25
 
26
+ def autocorrect(node)
27
+ StringLiteralCorrector.correct(node, style)
28
+ end
29
+
26
30
  private
27
31
 
28
32
  def message(*)
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # end
26
26
  #
27
27
  class TrailingBodyOnMethodDefinition < Cop
28
- include AutocorrectAlignment
28
+ include Alignment
29
29
 
30
30
  MSG = "Place the first line of a multi-line method definition's " \
31
31
  'body on its own line.'.freeze