rubocop-rails 2.15.2 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +120 -0
  3. data/config/obsoletion.yml +10 -0
  4. data/lib/rubocop/cop/mixin/active_record_helper.rb +1 -4
  5. data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +1 -3
  6. data/lib/rubocop/cop/mixin/index_method.rb +5 -15
  7. data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +99 -0
  8. data/lib/rubocop/cop/rails/action_controller_test_case.rb +1 -1
  9. data/lib/rubocop/cop/rails/action_filter.rb +1 -1
  10. data/lib/rubocop/cop/rails/action_order.rb +81 -0
  11. data/lib/rubocop/cop/rails/active_record_aliases.rb +1 -4
  12. data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
  13. data/lib/rubocop/cop/rails/active_support_on_load.rb +70 -0
  14. data/lib/rubocop/cop/rails/add_column_index.rb +1 -4
  15. data/lib/rubocop/cop/rails/blank.rb +1 -2
  16. data/lib/rubocop/cop/rails/bulk_change_table.rb +6 -20
  17. data/lib/rubocop/cop/rails/compact_blank.rb +5 -1
  18. data/lib/rubocop/cop/rails/content_tag.rb +3 -4
  19. data/lib/rubocop/cop/rails/date.rb +4 -9
  20. data/lib/rubocop/cop/rails/delegate.rb +2 -5
  21. data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +17 -13
  22. data/lib/rubocop/cop/rails/dot_separated_keys.rb +1 -1
  23. data/lib/rubocop/cop/rails/dynamic_find_by.rb +8 -6
  24. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +4 -0
  25. data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -5
  26. data/lib/rubocop/cop/rails/environment_comparison.rb +1 -2
  27. data/lib/rubocop/cop/rails/file_path.rb +2 -4
  28. data/lib/rubocop/cop/rails/find_each.rb +8 -2
  29. data/lib/rubocop/cop/rails/freeze_time.rb +74 -0
  30. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +1 -3
  31. data/lib/rubocop/cop/rails/http_positional_arguments.rb +4 -9
  32. data/lib/rubocop/cop/rails/http_status.rb +11 -11
  33. data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
  34. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +3 -10
  35. data/lib/rubocop/cop/rails/inverse_of.rb +3 -6
  36. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +2 -6
  37. data/lib/rubocop/cop/rails/link_to_blank.rb +1 -4
  38. data/lib/rubocop/cop/rails/output.rb +2 -5
  39. data/lib/rubocop/cop/rails/pluck.rb +8 -7
  40. data/lib/rubocop/cop/rails/pluralization_grammar.rb +1 -2
  41. data/lib/rubocop/cop/rails/presence.rb +21 -12
  42. data/lib/rubocop/cop/rails/present.rb +3 -6
  43. data/lib/rubocop/cop/rails/rake_environment.rb +1 -1
  44. data/lib/rubocop/cop/rails/redundant_allow_nil.rb +2 -4
  45. data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
  46. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +3 -3
  47. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +30 -26
  48. data/lib/rubocop/cop/rails/reflection_class_name.rb +17 -0
  49. data/lib/rubocop/cop/rails/refute_methods.rb +1 -5
  50. data/lib/rubocop/cop/rails/relative_date_constant.rb +2 -5
  51. data/lib/rubocop/cop/rails/request_referer.rb +1 -2
  52. data/lib/rubocop/cop/rails/reversible_migration.rb +10 -33
  53. data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +1 -2
  54. data/lib/rubocop/cop/rails/root_pathname_methods.rb +214 -0
  55. data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -3
  56. data/lib/rubocop/cop/rails/save_bang.rb +10 -22
  57. data/lib/rubocop/cop/rails/short_i18n.rb +1 -4
  58. data/lib/rubocop/cop/rails/skips_model_validations.rb +1 -2
  59. data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +1 -5
  60. data/lib/rubocop/cop/rails/time_zone.rb +10 -21
  61. data/lib/rubocop/cop/rails/to_s_with_argument.rb +41 -0
  62. data/lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb +49 -0
  63. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -6
  64. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -3
  65. data/lib/rubocop/cop/rails/unknown_env.rb +2 -4
  66. data/lib/rubocop/cop/rails/validation.rb +4 -12
  67. data/lib/rubocop/cop/rails/where_missing.rb +111 -0
  68. data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
  69. data/lib/rubocop/cop/rails_cops.rb +10 -0
  70. data/lib/rubocop/rails/version.rb +1 -1
  71. data/lib/rubocop-rails.rb +10 -0
  72. metadata +16 -8
  73. data/bin/console +0 -11
  74. data/bin/setup +0 -7
@@ -184,13 +184,9 @@ module RuboCop
184
184
  # @return [String]
185
185
  def message(methods, parent)
186
186
  if methods.size == 1
187
- format(MSG,
188
- action: "`#{methods[0]}` is",
189
- type: parent.type)
187
+ format(MSG, action: "`#{methods[0]}` is", type: parent.type)
190
188
  else
191
- format(MSG,
192
- action: "`#{methods.join('`, `')}` are",
193
- type: parent.type)
189
+ format(MSG, action: "`#{methods.join('`, `')}` are", type: parent.type)
194
190
  end
195
191
  end
196
192
  end
@@ -68,10 +68,7 @@ module RuboCop
68
68
 
69
69
  def append_to_rel(rel_node, corrector)
70
70
  existing_rel = rel_node.children.last.value
71
- str_range = rel_node.children.last.loc.expression.adjust(
72
- begin_pos: 1,
73
- end_pos: -1
74
- )
71
+ str_range = rel_node.children.last.loc.expression.adjust(begin_pos: 1, end_pos: -1)
75
72
  corrector.replace(str_range, "#{existing_rel} noopener")
76
73
  end
77
74
 
@@ -21,11 +21,8 @@ module RuboCop
21
21
  include RangeHelp
22
22
  extend AutoCorrector
23
23
 
24
- MSG = 'Do not write to stdout. ' \
25
- "Use Rails's logger if you want to log."
26
- RESTRICT_ON_SEND = %i[
27
- ap p pp pretty_print print puts binwrite syswrite write write_nonblock
28
- ].freeze
24
+ MSG = "Do not write to stdout. Use Rails's logger if you want to log."
25
+ RESTRICT_ON_SEND = %i[ap p pp pretty_print print puts binwrite syswrite write write_nonblock].freeze
29
26
 
30
27
  def_node_matcher :output?, <<~PATTERN
31
28
  (send nil? {:ap :p :pp :pretty_print :print :puts} ...)
@@ -21,16 +21,16 @@ module RuboCop
21
21
  extend AutoCorrector
22
22
  extend TargetRailsVersion
23
23
 
24
- MSG = 'Prefer `pluck(:%<value>s)` over `%<current>s`.'
24
+ MSG = 'Prefer `%<replacement>s` over `%<current>s`.'
25
25
 
26
26
  minimum_target_rails_version 5.0
27
27
 
28
28
  def_node_matcher :pluck_candidate?, <<~PATTERN
29
- ({block numblock} (send _ {:map :collect}) $_argument (send (lvar $_element) :[] (sym $_value)))
29
+ ({block numblock} (send _ {:map :collect}) $_argument (send (lvar $_element) :[] $_key))
30
30
  PATTERN
31
31
 
32
32
  def on_block(node)
33
- pluck_candidate?(node) do |argument, element, value|
33
+ pluck_candidate?(node) do |argument, element, key|
34
34
  match = if node.block_type?
35
35
  argument.children.first.source.to_sym == element
36
36
  else # numblock
@@ -38,10 +38,11 @@ module RuboCop
38
38
  end
39
39
  next unless match
40
40
 
41
- message = message(value, node)
41
+ replacement = "pluck(#{key.source})"
42
+ message = message(replacement, node)
42
43
 
43
44
  add_offense(offense_range(node), message: message) do |corrector|
44
- corrector.replace(offense_range(node), "pluck(:#{value})")
45
+ corrector.replace(offense_range(node), replacement)
45
46
  end
46
47
  end
47
48
  end
@@ -53,10 +54,10 @@ module RuboCop
53
54
  node.send_node.loc.selector.join(node.loc.end)
54
55
  end
55
56
 
56
- def message(value, node)
57
+ def message(replacement, node)
57
58
  current = offense_range(node).source
58
59
 
59
- format(MSG, value: value, current: current)
60
+ format(MSG, replacement: replacement, current: current)
60
61
  end
61
62
  end
62
63
  end
@@ -94,8 +94,7 @@ module RuboCop
94
94
  end
95
95
 
96
96
  def duration_method?(method_name)
97
- SINGULAR_DURATION_METHODS.key?(method_name) ||
98
- PLURAL_DURATION_METHODS.key?(method_name)
97
+ SINGULAR_DURATION_METHODS.key?(method_name) || PLURAL_DURATION_METHODS.key?(method_name)
99
98
  end
100
99
  end
101
100
  end
@@ -93,7 +93,7 @@ module RuboCop
93
93
 
94
94
  def register_offense(node, receiver, other)
95
95
  add_offense(node, message: message(node, receiver, other)) do |corrector|
96
- corrector.replace(node.source_range, replacement(receiver, other))
96
+ corrector.replace(node.source_range, replacement(receiver, other, node.left_sibling))
97
97
  end
98
98
  end
99
99
 
@@ -106,12 +106,20 @@ module RuboCop
106
106
  end
107
107
 
108
108
  def message(node, receiver, other)
109
- format(MSG,
110
- prefer: replacement(receiver, other),
111
- current: node.source)
109
+ prefer = replacement(receiver, other, node.left_sibling).gsub(/^\s*|\n/, '')
110
+ current = current(node).gsub(/^\s*|\n/, '')
111
+ format(MSG, prefer: prefer, current: current)
112
112
  end
113
113
 
114
- def replacement(receiver, other)
114
+ def current(node)
115
+ if node.source.include?("\n")
116
+ "#{node.loc.keyword.with(end_pos: node.condition.loc.selector.end_pos).source} ... end"
117
+ else
118
+ node.source
119
+ end
120
+ end
121
+
122
+ def replacement(receiver, other, left_sibling)
115
123
  or_source = if other&.send_type?
116
124
  build_source_for_or_method(other)
117
125
  elsif other.nil? || other.nil_type?
@@ -120,23 +128,24 @@ module RuboCop
120
128
  " || #{other.source}"
121
129
  end
122
130
 
123
- "#{receiver.source}.presence" + or_source
131
+ replaced = "#{receiver.source}.presence#{or_source}"
132
+ left_sibling ? "(#{replaced})" : replaced
124
133
  end
125
134
 
126
135
  def build_source_for_or_method(other)
127
- if other.parenthesized? || other.method?('[]') || !other.arguments?
136
+ if other.parenthesized? || other.method?('[]') || other.arithmetic_operation? || !other.arguments?
128
137
  " || #{other.source}"
129
138
  else
130
- method = range_between(
131
- other.source_range.begin_pos,
132
- other.first_argument.source_range.begin_pos - 1
133
- ).source
134
-
139
+ method = method_range(other).source
135
140
  arguments = other.arguments.map(&:source).join(', ')
136
141
 
137
142
  " || #{method}(#{arguments})"
138
143
  end
139
144
  end
145
+
146
+ def method_range(node)
147
+ range_between(node.source_range.begin_pos, node.first_argument.source_range.begin_pos - 1)
148
+ end
140
149
  end
141
150
  end
142
151
  end
@@ -47,10 +47,8 @@ module RuboCop
47
47
  extend AutoCorrector
48
48
 
49
49
  MSG_NOT_BLANK = 'Use `%<prefer>s` instead of `%<current>s`.'
50
- MSG_EXISTS_AND_NOT_EMPTY = 'Use `%<prefer>s` instead of ' \
51
- '`%<current>s`.'
52
- MSG_UNLESS_BLANK = 'Use `if %<prefer>s` instead of ' \
53
- '`%<current>s`.'
50
+ MSG_EXISTS_AND_NOT_EMPTY = 'Use `%<prefer>s` instead of `%<current>s`.'
51
+ MSG_UNLESS_BLANK = 'Use `if %<prefer>s` instead of `%<current>s`.'
54
52
  RESTRICT_ON_SEND = %i[!].freeze
55
53
 
56
54
  def_node_matcher :exists_and_not_empty?, <<~PATTERN
@@ -118,8 +116,7 @@ module RuboCop
118
116
 
119
117
  unless_blank?(node) do |method_call, receiver|
120
118
  range = unless_condition(node, method_call)
121
- msg = format(MSG_UNLESS_BLANK, prefer: replacement(receiver),
122
- current: range.source)
119
+ msg = format(MSG_UNLESS_BLANK, prefer: replacement(receiver), current: range.source)
123
120
  add_offense(range, message: msg) do |corrector|
124
121
  autocorrect(corrector, node)
125
122
  end
@@ -39,7 +39,7 @@ module RuboCop
39
39
  (block $(send nil? :task ...) ...)
40
40
  PATTERN
41
41
 
42
- def on_block(node)
42
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
43
43
  task_definition?(node) do |task_method|
44
44
  return if task_name(task_method) == :default
45
45
  return if with_dependencies?(task_method)
@@ -30,11 +30,9 @@ module RuboCop
30
30
  include RangeHelp
31
31
  extend AutoCorrector
32
32
 
33
- MSG_SAME =
34
- '`allow_nil` is redundant when `allow_blank` has the same value.'
33
+ MSG_SAME = '`allow_nil` is redundant when `allow_blank` has the same value.'
35
34
 
36
- MSG_ALLOW_NIL_FALSE =
37
- '`allow_nil: false` is redundant when `allow_blank` is true.'
35
+ MSG_ALLOW_NIL_FALSE = '`allow_nil: false` is redundant when `allow_blank` is true.'
38
36
 
39
37
  RESTRICT_ON_SEND = %i[validates].freeze
40
38
 
@@ -41,7 +41,7 @@ module RuboCop
41
41
  association_with_foreign_key(node) do |type, name, options, foreign_key_pair, foreign_key|
42
42
  if redundant?(node, type, name, options, foreign_key)
43
43
  add_offense(foreign_key_pair.loc.expression) do |corrector|
44
- range = range_with_surrounding_space(range: foreign_key_pair.source_range, side: :left)
44
+ range = range_with_surrounding_space(foreign_key_pair.source_range, side: :left)
45
45
  range = range_with_surrounding_comma(range, :left)
46
46
 
47
47
  corrector.remove(range)
@@ -143,7 +143,7 @@ module RuboCop
143
143
  def_node_matcher :belongs_to_without_fk?, <<~PATTERN
144
144
  {
145
145
  (send nil? :belongs_to (sym %1)) # belongs_to :user
146
- (send nil? :belongs_to (sym %1) !hash) # belongs_to :user, -> { not_deleted }
146
+ (send nil? :belongs_to (sym %1) !hash ...) # belongs_to :user, -> { not_deleted }
147
147
  (send nil? :belongs_to (sym %1) !(hash <(pair (sym :foreign_key) _) ...>))
148
148
  }
149
149
  PATTERN
@@ -217,7 +217,7 @@ module RuboCop
217
217
  keys.each do |key|
218
218
  key_node = node.arguments.find { |arg| arg.value == key }
219
219
  key_range = range_with_surrounding_space(
220
- range: range_with_surrounding_comma(key_node.source_range, :right),
220
+ range_with_surrounding_comma(key_node.source_range, :right),
221
221
  side: :right
222
222
  )
223
223
  corrector.remove(key_range)
@@ -226,7 +226,7 @@ module RuboCop
226
226
 
227
227
  def remove_presence_option(corrector, presence)
228
228
  range = range_with_surrounding_comma(
229
- range_with_surrounding_space(range: presence.source_range, side: :left),
229
+ range_with_surrounding_space(presence.source_range, side: :left),
230
230
  :left
231
231
  )
232
232
  corrector.remove(range)
@@ -60,15 +60,6 @@ module RuboCop
60
60
 
61
61
  MSG = 'Redundant receiver in `with_options`.'
62
62
 
63
- def_node_matcher :with_options?, <<~PATTERN
64
- (block
65
- (send nil? :with_options
66
- (...))
67
- (args
68
- $_arg)
69
- $_body)
70
- PATTERN
71
-
72
63
  def_node_search :all_block_nodes_in, <<~PATTERN
73
64
  (block ...)
74
65
  PATTERN
@@ -78,29 +69,42 @@ module RuboCop
78
69
  PATTERN
79
70
 
80
71
  def on_block(node)
81
- with_options?(node) do |arg, body|
82
- return if body.nil?
83
- return unless all_block_nodes_in(body).count.zero?
84
-
85
- send_nodes = all_send_nodes_in(body)
86
-
87
- if send_nodes.all? { |n| same_value?(arg, n.receiver) }
88
- send_nodes.each do |send_node|
89
- receiver = send_node.receiver
90
- add_offense(receiver.source_range) do |corrector|
91
- autocorrect(corrector, send_node)
92
- end
93
- end
72
+ return unless node.method?(:with_options)
73
+ return unless (body = node.body)
74
+ return unless all_block_nodes_in(body).count.zero?
75
+
76
+ send_nodes = all_send_nodes_in(body)
77
+ return unless redundant_receiver?(send_nodes, node)
78
+
79
+ send_nodes.each do |send_node|
80
+ receiver = send_node.receiver
81
+ add_offense(receiver.source_range) do |corrector|
82
+ autocorrect(corrector, send_node, node)
94
83
  end
95
84
  end
96
85
  end
97
86
 
87
+ alias on_numblock on_block
88
+
98
89
  private
99
90
 
100
- def autocorrect(corrector, node)
101
- corrector.remove(node.receiver.source_range)
102
- corrector.remove(node.loc.dot)
103
- corrector.remove(block_argument_range(node))
91
+ def autocorrect(corrector, send_node, node)
92
+ corrector.remove(send_node.receiver.source_range)
93
+ corrector.remove(send_node.loc.dot)
94
+ corrector.remove(block_argument_range(send_node)) unless node.numblock_type?
95
+ end
96
+
97
+ def redundant_receiver?(send_nodes, node)
98
+ proc = if node.numblock_type?
99
+ ->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
100
+ else
101
+ return false if node.arguments.empty?
102
+
103
+ arg = node.arguments.first
104
+ ->(n) { same_value?(arg, n.receiver) }
105
+ end
106
+
107
+ send_nodes.all?(&proc)
104
108
  end
105
109
 
106
110
  def block_argument_range(node)
@@ -34,12 +34,29 @@ module RuboCop
34
34
 
35
35
  def on_send(node)
36
36
  association_with_reflection(node) do |reflection_class_name|
37
+ return if reflection_class_name.value.send_type? && reflection_class_name.value.receiver.nil?
38
+ return if reflection_class_name.value.lvar_type? && str_assigned?(reflection_class_name)
39
+
37
40
  add_offense(reflection_class_name.loc.expression)
38
41
  end
39
42
  end
40
43
 
41
44
  private
42
45
 
46
+ def str_assigned?(reflection_class_name)
47
+ lvar = reflection_class_name.value.source
48
+
49
+ reflection_class_name.ancestors.each do |nodes|
50
+ return true if nodes.each_child_node(:lvasgn).detect do |node|
51
+ lhs, rhs = *node
52
+
53
+ lhs.to_s == lvar && ALLOWED_REFLECTION_CLASS_TYPES.include?(rhs.type)
54
+ end
55
+ end
56
+
57
+ false
58
+ end
59
+
43
60
  def reflection_class_value?(class_value)
44
61
  if class_value.send_type?
45
62
  !class_value.method?(:to_s) || class_value.receiver&.const_type?
@@ -81,11 +81,7 @@ module RuboCop
81
81
  end
82
82
 
83
83
  def offense_message(method_name)
84
- format(
85
- MSG,
86
- bad_method: method_name,
87
- good_method: convert_good_method(method_name)
88
- )
84
+ format(MSG, bad_method: method_name, good_method: convert_good_method(method_name))
89
85
  end
90
86
 
91
87
  def convert_good_method(bad_method)
@@ -34,8 +34,7 @@ module RuboCop
34
34
  include RangeHelp
35
35
  extend AutoCorrector
36
36
 
37
- MSG = 'Do not assign `%<method_name>s` to constants as it ' \
38
- 'will be evaluated only once.'
37
+ MSG = 'Do not assign `%<method_name>s` to constants as it will be evaluated only once.'
39
38
  RELATIVE_DATE_METHODS = %i[since from_now after ago until before yesterday tomorrow].to_set.freeze
40
39
 
41
40
  def on_casgn(node)
@@ -77,9 +76,7 @@ module RuboCop
77
76
  return unless scope.nil?
78
77
 
79
78
  indent = ' ' * node.loc.column
80
- new_code = ["def self.#{const_name.downcase}",
81
- "#{indent}#{value.source}",
82
- 'end'].join("\n#{indent}")
79
+ new_code = ["def self.#{const_name.downcase}", "#{indent}#{value.source}", 'end'].join("\n#{indent}")
83
80
 
84
81
  corrector.replace(node.source_range, new_code)
85
82
  end
@@ -23,8 +23,7 @@ module RuboCop
23
23
  include ConfigurableEnforcedStyle
24
24
  extend AutoCorrector
25
25
 
26
- MSG = 'Use `request.%<prefer>s` instead of ' \
27
- '`request.%<current>s`.'
26
+ MSG = 'Use `request.%<prefer>s` instead of `request.%<current>s`.'
28
27
  RESTRICT_ON_SEND = %i[referer referrer].freeze
29
28
 
30
29
  def_node_matcher :referer?, <<~PATTERN
@@ -229,6 +229,8 @@ module RuboCop
229
229
  check_change_table_node(node.send_node, node.body)
230
230
  end
231
231
 
232
+ alias on_numblock on_block
233
+
232
234
  private
233
235
 
234
236
  def check_irreversible_schema_statement_node(node)
@@ -240,10 +242,7 @@ module RuboCop
240
242
  def check_drop_table_node(node)
241
243
  drop_table_call(node) do
242
244
  unless node.parent.block_type? || node.last_argument.block_pass_type?
243
- add_offense(
244
- node,
245
- message: format(MSG, action: 'drop_table(without block)')
246
- )
245
+ add_offense(node, message: format(MSG, action: 'drop_table(without block)'))
247
246
  end
248
247
  end
249
248
  end
@@ -251,22 +250,12 @@ module RuboCop
251
250
  def check_reversible_hash_node(node)
252
251
  return if reversible_change_table_call?(node)
253
252
 
254
- add_offense(
255
- node,
256
- message: format(
257
- MSG, action: "#{node.method_name}(without :from and :to)"
258
- )
259
- )
253
+ add_offense(node, message: format(MSG, action: "#{node.method_name}(without :from and :to)"))
260
254
  end
261
255
 
262
256
  def check_remove_column_node(node)
263
257
  remove_column_call(node) do |args|
264
- if args.to_a.size < 3
265
- add_offense(
266
- node,
267
- message: format(MSG, action: 'remove_column(without type)')
268
- )
269
- end
258
+ add_offense(node, message: format(MSG, action: 'remove_column(without type)')) if args.to_a.size < 3
270
259
  end
271
260
  end
272
261
 
@@ -295,10 +284,7 @@ module RuboCop
295
284
  unless all_hash_key?(args, :type) && target_rails_version >= 6.1
296
285
  action = target_rails_version >= 6.1 ? 'remove_columns(without type)' : 'remove_columns'
297
286
 
298
- add_offense(
299
- node,
300
- message: format(MSG, action: action)
301
- )
287
+ add_offense(node, message: format(MSG, action: action))
302
288
  end
303
289
  end
304
290
  end
@@ -306,18 +292,14 @@ module RuboCop
306
292
  def check_remove_index_node(node)
307
293
  remove_index_call(node) do |args|
308
294
  if args.hash_type? && !all_hash_key?(args, :column)
309
- add_offense(
310
- node,
311
- message: format(MSG, action: 'remove_index(without column)')
312
- )
295
+ add_offense(node, message: format(MSG, action: 'remove_index(without column)'))
313
296
  end
314
297
  end
315
298
  end
316
299
 
317
300
  def check_change_table_offense(receiver, node)
318
301
  method_name = node.method_name
319
- return if receiver != node.receiver &&
320
- reversible_change_table_call?(node)
302
+ return if receiver != node.receiver && reversible_change_table_call?(node)
321
303
 
322
304
  action = if method_name == :remove
323
305
  target_rails_version >= 6.1 ? 't.remove (without type)' : 't.remove'
@@ -325,10 +307,7 @@ module RuboCop
325
307
  "change_table(with #{method_name})"
326
308
  end
327
309
 
328
- add_offense(
329
- node,
330
- message: format(MSG, action: action)
331
- )
310
+ add_offense(node, message: format(MSG, action: action))
332
311
  end
333
312
 
334
313
  def reversible_change_table_call?(node)
@@ -353,9 +332,7 @@ module RuboCop
353
332
 
354
333
  def within_reversible_or_up_only_block?(node)
355
334
  node.each_ancestor(:block).any? do |ancestor|
356
- (ancestor.block_type? &&
357
- ancestor.send_node.method?(:reversible)) ||
358
- ancestor.send_node.method?(:up_only)
335
+ (ancestor.block_type? && ancestor.send_node.method?(:reversible)) || ancestor.send_node.method?(:up_only)
359
336
  end
360
337
  end
361
338
 
@@ -45,8 +45,7 @@ module RuboCop
45
45
  class ReversibleMigrationMethodDefinition < Base
46
46
  include MigrationsHelper
47
47
 
48
- MSG = 'Migrations must contain either a `change` method, or ' \
49
- 'both an `up` and a `down` method.'
48
+ MSG = 'Migrations must contain either a `change` method, or both an `up` and a `down` method.'
50
49
 
51
50
  def_node_matcher :change_method?, <<~PATTERN
52
51
  `(def :change (args) _)