rubocop-rails 2.20.2 → 2.21.2

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/config/default.yml +58 -6
  4. data/lib/rubocop/cop/mixin/index_method.rb +2 -2
  5. data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +1 -1
  6. data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
  7. data/lib/rubocop/cop/rails/bulk_change_table.rb +20 -3
  8. data/lib/rubocop/cop/rails/dangerous_column_names.rb +439 -0
  9. data/lib/rubocop/cop/rails/date.rb +1 -1
  10. data/lib/rubocop/cop/rails/duplicate_association.rb +3 -0
  11. data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -3
  12. data/lib/rubocop/cop/rails/file_path.rb +4 -1
  13. data/lib/rubocop/cop/rails/freeze_time.rb +1 -1
  14. data/lib/rubocop/cop/rails/http_status.rb +4 -3
  15. data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +63 -13
  16. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +7 -8
  17. data/lib/rubocop/cop/rails/rake_environment.rb +20 -4
  18. data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +168 -0
  19. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
  20. data/lib/rubocop/cop/rails/root_pathname_methods.rb +38 -4
  21. data/lib/rubocop/cop/rails/save_bang.rb +2 -2
  22. data/lib/rubocop/cop/rails/schema_comment.rb +16 -10
  23. data/lib/rubocop/cop/rails/select_map.rb +78 -0
  24. data/lib/rubocop/cop/rails/time_zone.rb +12 -5
  25. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +29 -10
  26. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
  27. data/lib/rubocop/cop/rails/unused_render_content.rb +67 -0
  28. data/lib/rubocop/cop/rails/where_exists.rb +0 -1
  29. data/lib/rubocop/cop/rails_cops.rb +4 -0
  30. data/lib/rubocop/rails/schema_loader.rb +1 -1
  31. data/lib/rubocop/rails/version.rb +1 -1
  32. data/lib/rubocop-rails.rb +8 -0
  33. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 227ce5b698e456412c24917c5644b2a938531440ab8c64e2b5036d6f2857a548
4
- data.tar.gz: 41c6157da73215cca0b5d56ffa254711c2f9f4f5399c8aa3d85ac7c719958b28
3
+ metadata.gz: 0e154e69d10b43226db08e454d992d724dc7504d54cac804e597156ee5cf13e5
4
+ data.tar.gz: 60d4697e076620a134f48eff2f81be7b2004fd824796b1a1b15f5822239e3ce3
5
5
  SHA512:
6
- metadata.gz: afafd2f9293f4592cc914fdb42c6742900681574d5d0a27dc2031eddb3446b419ac04a77a149e0169ab89a0bb7afe4e0481b3ff889631345a0227b0d24a2c185
7
- data.tar.gz: a90108eed94c1cedbe1b9a059b60cae51465cffd5a8612f56a0548182b6f992e3e626125e4a4f2f74ceda491a91cdcacb0bd8206ebf94d7d245841572639b556
6
+ metadata.gz: f0aa0f69a7aa3b90d1e402ab26bdf5a4d03680080d9b06ba157cd92f3c5c290f821e81d4a99636009e17ec4ea2de0cfd405cea00134ebccd4323d424fb790ec8
7
+ data.tar.gz: 6b6ddbe47c1b112638cc3693464d9509f589a6683317b0bb30925a27788e39351a3a10853ecf286b419d3ec3b17e13aee9fd09ae07581d209635f0a56a44065b
data/README.md CHANGED
@@ -72,7 +72,9 @@ module YourCoolApp
72
72
  class Application < Rails::Application
73
73
  config.generators.after_generate do |files|
74
74
  parsable_files = files.filter { |file| file.end_with?('.rb') }
75
- system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
75
+ unless parsable_files.empty?
76
+ system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
77
+ end
76
78
  end
77
79
  end
78
80
  end
data/config/default.yml CHANGED
@@ -61,6 +61,18 @@ Lint/RedundantSafeNavigation:
61
61
  - presence
62
62
  - present?
63
63
 
64
+ Lint/SafeNavigationChain:
65
+ # Add `presence_in` method to the default of the RuboCop core:
66
+ # https://github.com/rubocop/rubocop/blob/v1.56.0/config/default.yml#L2265-L2271
67
+ AllowedMethods:
68
+ - present?
69
+ - blank?
70
+ - presence
71
+ - presence_in
72
+ - try
73
+ - try!
74
+ - in?
75
+
64
76
  Rails:
65
77
  Enabled: true
66
78
  DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
@@ -296,6 +308,15 @@ Rails/CreateTableWithTimestamps:
296
308
  - db/**/*_create_active_storage_tables.active_storage.rb
297
309
  - db/**/*_create_active_storage_variant_records.active_storage.rb
298
310
 
311
+ Rails/DangerousColumnNames:
312
+ Description: >-
313
+ Avoid dangerous column names.
314
+ Enabled: pending
315
+ Severity: warning
316
+ VersionAdded: '2.21'
317
+ Include:
318
+ - 'db/**/*.rb'
319
+
299
320
  Rails/Date:
300
321
  Description: >-
301
322
  Checks the correct usage of date aware methods,
@@ -463,10 +484,8 @@ Rails/FindBy:
463
484
  StyleGuide: 'https://rails.rubystyle.guide#find_by'
464
485
  Enabled: true
465
486
  VersionAdded: '0.30'
466
- VersionChanged: '2.11'
487
+ VersionChanged: '2.21'
467
488
  IgnoreWhereFirst: true
468
- Include:
469
- - app/models/**/*.rb
470
489
 
471
490
  Rails/FindById:
472
491
  Description: >-
@@ -482,9 +501,7 @@ Rails/FindEach:
482
501
  Enabled: true
483
502
  Safe: false
484
503
  VersionAdded: '0.30'
485
- VersionChanged: '2.19'
486
- Include:
487
- - app/models/**/*.rb
504
+ VersionChanged: '2.21'
488
505
  AllowedMethods:
489
506
  # Methods that don't work well with `find_each`.
490
507
  - order
@@ -547,6 +564,10 @@ Rails/I18nLazyLookup:
547
564
  Reference: 'https://guides.rubyonrails.org/i18n.html#lazy-lookup'
548
565
  Enabled: pending
549
566
  VersionAdded: '2.14'
567
+ EnforcedStyle: lazy
568
+ SupportedStyles:
569
+ - lazy
570
+ - explicit
550
571
  Include:
551
572
  - 'app/controllers/**/*.rb'
552
573
 
@@ -775,6 +796,16 @@ Rails/ReadWriteAttribute:
775
796
  Include:
776
797
  - app/models/**/*.rb
777
798
 
799
+ Rails/RedundantActiveRecordAllMethod:
800
+ Description: Detect redundant `all` used as a receiver for Active Record query methods.
801
+ StyleGuide: 'https://rails.rubystyle.guide/#redundant-all'
802
+ Enabled: pending
803
+ Safe: false
804
+ AllowedReceivers:
805
+ - ActionMailer::Preview
806
+ - ActiveSupport::TimeZone
807
+ VersionAdded: '2.21'
808
+
778
809
  Rails/RedundantAllowNil:
779
810
  Description: >-
780
811
  Finds redundant use of `allow_nil` when `allow_blank` is set to
@@ -955,6 +986,12 @@ Rails/ScopeArgs:
955
986
  Include:
956
987
  - app/models/**/*.rb
957
988
 
989
+ Rails/SelectMap:
990
+ Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
991
+ Enabled: pending
992
+ Safe: false
993
+ VersionAdded: '2.21'
994
+
958
995
  Rails/ShortI18n:
959
996
  Description: 'Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.'
960
997
  StyleGuide: 'https://rails.rubystyle.guide/#short-i18n'
@@ -1083,6 +1120,7 @@ Rails/TransactionExitStatement:
1083
1120
  - https://github.com/rails/rails/commit/15aa4200e083
1084
1121
  Enabled: pending
1085
1122
  VersionAdded: '2.14'
1123
+ TransactionMethods: []
1086
1124
 
1087
1125
  Rails/UniqBeforePluck:
1088
1126
  Description: 'Prefer the use of uniq or distinct before pluck.'
@@ -1120,6 +1158,12 @@ Rails/UnusedIgnoredColumns:
1120
1158
  Include:
1121
1159
  - app/models/**/*.rb
1122
1160
 
1161
+ Rails/UnusedRenderContent:
1162
+ Description: 'Do not specify body content for a response with a non-content status code.'
1163
+ Enabled: pending
1164
+ Severity: warning
1165
+ VersionAdded: '2.21'
1166
+
1123
1167
  Rails/Validation:
1124
1168
  Description: 'Use validates :attribute, hash of validations.'
1125
1169
  Enabled: true
@@ -1175,6 +1219,14 @@ Style/FormatStringToken:
1175
1219
  AllowedMethods:
1176
1220
  - redirect
1177
1221
 
1222
+ Style/InvertibleUnlessCondition:
1223
+ InverseMethods:
1224
+ # Active Support defines some common inverse methods. They are listed below:
1225
+ :present?: :blank?
1226
+ :blank?: :present?
1227
+ :include?: :exclude?
1228
+ :exclude?: :include?
1229
+
1178
1230
  Style/SymbolProc:
1179
1231
  AllowedMethods:
1180
1232
  - define_method
@@ -102,7 +102,7 @@ module RuboCop
102
102
  end
103
103
 
104
104
  # Internal helper class to hold match data
105
- Captures = Struct.new(
105
+ Captures = ::Struct.new(
106
106
  :transformed_argname,
107
107
  :transforming_body_expr
108
108
  ) do
@@ -112,7 +112,7 @@ module RuboCop
112
112
  end
113
113
 
114
114
  # Internal helper class to hold autocorrect data
115
- Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do
115
+ Autocorrection = ::Struct.new(:match, :block_node, :leading, :trailing) do
116
116
  def self.from_each_with_object(node, match)
117
117
  new(match, node, 0, 0)
118
118
  end
@@ -85,7 +85,7 @@ module RuboCop
85
85
 
86
86
  def inherit_action_controller_base?(node)
87
87
  class_node = find_ancestor(node, type: :class)
88
- return unless class_node
88
+ return false unless class_node
89
89
 
90
90
  action_controller?(class_node)
91
91
  end
@@ -3,8 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # Using `ActionController::TestCase`` is discouraged and should be replaced by
7
- # `ActionDispatch::IntegrationTest``. Controller tests are too close to the
6
+ # Using `ActionController::TestCase` is discouraged and should be replaced by
7
+ # `ActionDispatch::IntegrationTest`. Controller tests are too close to the
8
8
  # internals of a controller whereas integration tests mimic the browser/user.
9
9
  #
10
10
  # @safety
@@ -12,7 +12,8 @@ module RuboCop
12
12
  # The `bulk` option is only supported on the MySQL and
13
13
  # the PostgreSQL (5.2 later) adapter; thus it will
14
14
  # automatically detect an adapter from `development` environment
15
- # in `config/database.yml` when the `Database` option is not set.
15
+ # in `config/database.yml` or the environment variable `DATABASE_URL`
16
+ # when the `Database` option is not set.
16
17
  # If the adapter is not `mysql2` or `postgresql`,
17
18
  # this Cop ignores offenses.
18
19
  #
@@ -175,13 +176,13 @@ module RuboCop
175
176
  end
176
177
 
177
178
  def database
178
- cop_config['Database'] || database_from_yaml
179
+ cop_config['Database'] || database_from_yaml || database_from_env
179
180
  end
180
181
 
181
182
  def database_from_yaml
182
183
  return nil unless database_yaml
183
184
 
184
- case database_yaml['adapter']
185
+ case database_adapter
185
186
  when 'mysql2'
186
187
  MYSQL
187
188
  when 'postgresql'
@@ -189,6 +190,10 @@ module RuboCop
189
190
  end
190
191
  end
191
192
 
193
+ def database_adapter
194
+ database_yaml['adapter'] || database_yaml.first.last['adapter']
195
+ end
196
+
192
197
  def database_yaml
193
198
  return nil unless File.exist?('config/database.yml')
194
199
 
@@ -207,6 +212,18 @@ module RuboCop
207
212
  nil
208
213
  end
209
214
 
215
+ def database_from_env
216
+ url = ENV['DATABASE_URL'].presence
217
+ return nil unless url
218
+
219
+ case url
220
+ when %r{\Amysql2://}
221
+ MYSQL
222
+ when %r{\Apostgres(ql)?://}
223
+ POSTGRESQL
224
+ end
225
+ end
226
+
210
227
  def support_bulk_alter?
211
228
  case database
212
229
  when MYSQL
@@ -0,0 +1,439 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ # Avoid dangerous column names.
7
+ #
8
+ # Some column names are considered dangerous because they would overwrite methods already defined.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # add_column :users, :save
13
+ #
14
+ # # good
15
+ # add_column :users, :saved
16
+ class DangerousColumnNames < Base # rubocop:disable Metrics/ClassLength
17
+ COLUMN_TYPE_METHOD_NAMES = %i[
18
+ bigint
19
+ binary
20
+ blob
21
+ boolean
22
+ date
23
+ datetime
24
+ decimal
25
+ float
26
+ integer
27
+ numeric
28
+ primary_key
29
+ string
30
+ text
31
+ time
32
+ ].to_set.freeze
33
+
34
+ # Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.0.5.
35
+ # rubocop:disable Metrics/CollectionLiteralLength
36
+ DANGEROUS_COLUMN_NAMES = %w[
37
+ __callbacks
38
+ _assign_attribute
39
+ _assign_attributes
40
+ _before_commit_callbacks
41
+ _commit_callbacks
42
+ _committed_already_called
43
+ _create_callbacks
44
+ _create_record
45
+ _delete_row
46
+ _destroy
47
+ _destroy_callbacks
48
+ _ensure_no_duplicate_errors
49
+ _find_callbacks
50
+ _find_record
51
+ _has_attribute
52
+ _initialize_callbacks
53
+ _lock_value_for_database
54
+ _merge_attributes
55
+ _primary_key_constraints_hash
56
+ _raise_readonly_record_error
57
+ _raise_record_not_destroyed
58
+ _raise_record_not_touched_error
59
+ _read_attribute
60
+ _record_changed
61
+ _reflections
62
+ _rollback_callbacks
63
+ _run_before_commit_callbacks
64
+ _run_commit_callbacks
65
+ _run_create_callbacks
66
+ _run_destroy_callbacks
67
+ _run_find_callbacks
68
+ _run_initialize_callbacks
69
+ _run_rollback_callbacks
70
+ _run_save_callbacks
71
+ _run_touch_callbacks
72
+ _run_update_callbacks
73
+ _run_validate_callbacks
74
+ _run_validation_callbacks
75
+ _save_callbacks
76
+ _touch_callbacks
77
+ _touch_row
78
+ _trigger_destroy_callback
79
+ _trigger_update_callback
80
+ _update_callbacks
81
+ _update_record
82
+ _update_row
83
+ _validate_callbacks
84
+ _validation_callbacks
85
+ _validators
86
+ _write_attribute
87
+ []
88
+ []=
89
+ accessed_fields
90
+ add_to_transaction
91
+ aggregate_reflections
92
+ all_timestamp_attributes_in_model
93
+ allow_destroy
94
+ apply_scoping
95
+ around_save_collection_association
96
+ assign_attributes
97
+ assign_multiparameter_attributes
98
+ assign_nested_attributes_for_collection_association
99
+ assign_nested_attributes_for_one_to_one_association
100
+ assign_nested_parameter_attributes
101
+ assign_to_or_mark_for_destruction
102
+ associated_records_to_validate_or_save
103
+ association
104
+ association_cached
105
+ association_foreign_key_changed
106
+ association_instance_get
107
+ association_instance_set
108
+ association_valid
109
+ attachment_changes
110
+ attachment_reflections
111
+ attribute
112
+ attribute_aliases
113
+ attribute_before_last_save
114
+ attribute_before_type_cast
115
+ attribute_came_from_user
116
+ attribute_change
117
+ attribute_change_to_be_saved
118
+ attribute_changed
119
+ attribute_changed_in_place
120
+ attribute_for_database
121
+ attribute_for_inspect
122
+ attribute_in_database
123
+ attribute_method
124
+ attribute_method_matchers
125
+ attribute_missing
126
+ attribute_names
127
+ attribute_names_for_partial_inserts
128
+ attribute_names_for_partial_updates
129
+ attribute_names_for_serialization
130
+ attribute_present
131
+ attribute_previous_change
132
+ attribute_previously_changed
133
+ attribute_previously_was
134
+ attribute_was
135
+ attribute_will_change
136
+ attribute=
137
+ attributes
138
+ attributes_before_type_cast
139
+ attributes_for_create
140
+ attributes_for_database
141
+ attributes_for_update
142
+ attributes_in_database
143
+ attributes_with_values
144
+ attributes=
145
+ automatic_scope_inversing
146
+ becomes
147
+ before_committed
148
+ belongs_to_touch_method
149
+ broadcast_action
150
+ broadcast_action_later
151
+ broadcast_action_later_to
152
+ broadcast_action_to
153
+ broadcast_after_to
154
+ broadcast_append
155
+ broadcast_append_later
156
+ broadcast_append_later_to
157
+ broadcast_append_to
158
+ broadcast_before_to
159
+ broadcast_prepend
160
+ broadcast_prepend_later
161
+ broadcast_prepend_later_to
162
+ broadcast_prepend_to
163
+ broadcast_remove
164
+ broadcast_remove_to
165
+ broadcast_render
166
+ broadcast_render_later
167
+ broadcast_render_later_to
168
+ broadcast_render_to
169
+ broadcast_rendering_with_defaults
170
+ broadcast_replace
171
+ broadcast_replace_later
172
+ broadcast_replace_later_to
173
+ broadcast_replace_to
174
+ broadcast_target_default
175
+ broadcast_update
176
+ broadcast_update_later
177
+ broadcast_update_later_to
178
+ broadcast_update_to
179
+ build_decrypt_attribute_assignments
180
+ build_encrypt_attribute_assignments
181
+ cache_key
182
+ cache_key_with_version
183
+ cache_timestamp_format
184
+ cache_version
185
+ cache_versioning
186
+ call_reject_if
187
+ can_use_fast_cache_version
188
+ cant_modify_encrypted_attributes_when_frozen
189
+ changed
190
+ changed_attribute_names_to_save
191
+ changed_attributes
192
+ changed_for_autosave
193
+ changes
194
+ changes_applied
195
+ changes_to_save
196
+ check_record_limit
197
+ ciphertext_for
198
+ clear_attribute_change
199
+ clear_attribute_changes
200
+ clear_changes_information
201
+ clear_timestamp_attributes
202
+ clear_transaction_record_state
203
+ collection_cache_versioning
204
+ column_for_attribute
205
+ committed
206
+ connection_handler
207
+ create_or_update
208
+ current_time_from_proper_timezone
209
+ custom_inspect_method_defined
210
+ custom_validation_context
211
+ decrement
212
+ decrypt
213
+ decrypt_attributes
214
+ decrypt_rich_texts
215
+ default_connection_handler
216
+ default_role
217
+ default_scope_override
218
+ default_scopes
219
+ default_shard
220
+ default_validation_context
221
+ defined_enums
222
+ delete
223
+ destroy
224
+ destroy_association_async_job
225
+ destroy_associations
226
+ destroy_row
227
+ destroyed
228
+ destroyed_by_association
229
+ destroyed_by_association=
230
+ each_counter_cached_associations
231
+ encode_with
232
+ encrypt
233
+ encrypt_attributes
234
+ encrypt_rich_texts
235
+ encryptable_rich_texts
236
+ encrypted_attribute
237
+ encrypted_attributes
238
+ encrypted_attributes=
239
+ ensure_proper_type
240
+ errors
241
+ execute_callstack_for_multiparameter_attributes
242
+ extract_callstack_for_multiparameter_attributes
243
+ find_parameter_position
244
+ forget_attribute_assignments
245
+ format_for_inspect
246
+ from_json
247
+ halted_callback_hook
248
+ has_attribute
249
+ has_changes_to_save
250
+ has_defer_touch_attrs
251
+ has_destroy_flag
252
+ has_encrypted_attributes
253
+ has_encrypted_rich_texts
254
+ has_transactional_callbacks
255
+ id
256
+ id_before_type_cast
257
+ id_for_database
258
+ id_in_database
259
+ id_was
260
+ id=
261
+ include_root_in_json
262
+ increment
263
+ init_internals
264
+ init_with
265
+ init_with_attributes
266
+ initialize_internals_callback
267
+ inspection_filter
268
+ invalid
269
+ lock
270
+ lock_optimistically
271
+ locking_enabled
272
+ logger
273
+ mark_for_destruction
274
+ marked_for_destruction
275
+ matched_attribute_method
276
+ max_updated_column_timestamp
277
+ missing_attribute
278
+ model_name
279
+ mutations_before_last_save
280
+ mutations_from_database
281
+ nested_attributes_options
282
+ nested_records_changed_for_autosave
283
+ new_record
284
+ no_touching
285
+ normalize_reflection_attribute
286
+ partial_inserts
287
+ partial_updates
288
+ perform_validations
289
+ persisted
290
+ pk_attribute
291
+ pluralize_table_names
292
+ populate_with_current_scope_attributes
293
+ previous_changes
294
+ previously_new_record
295
+ previously_persisted
296
+ primary_key_prefix_type
297
+ query_attribute
298
+ raise_nested_attributes_record_not_found
299
+ raise_validation_error
300
+ raw_timestamp_to_cache_version
301
+ read_attribute
302
+ read_attribute_before_type_cast
303
+ read_attribute_for_serialization
304
+ read_attribute_for_validation
305
+ read_store_attribute
306
+ readonly
307
+ record_timestamps
308
+ record_timestamps=
309
+ reject_new_record
310
+ reload
311
+ remember_transaction_record_state
312
+ respond_to_without_attributes
313
+ restore_attribute
314
+ restore_attributes
315
+ restore_transaction_record_state
316
+ rolledback
317
+ run_callbacks
318
+ run_validations
319
+ sanitize_for_mass_assignment
320
+ sanitize_forbidden_attributes
321
+ save
322
+ save_belongs_to_association
323
+ save_collection_association
324
+ save_has_one_association
325
+ saved_change_to_attribute
326
+ saved_changes
327
+ serializable_add_includes
328
+ serializable_attributes
329
+ serializable_hash
330
+ should_record_timestamps
331
+ signed_id
332
+ signed_id_verifier_secret
333
+ skip_time_zone_conversion_for_attributes
334
+ slice
335
+ store_accessor_for
336
+ store_full_class_name
337
+ store_full_sti_class
338
+ strict_loaded_associations
339
+ strict_loading
340
+ strict_loading_mode
341
+ strict_loading_n_plus_one_only
342
+ surreptitiously_touch
343
+ table_name_prefix
344
+ table_name_suffix
345
+ time_zone_aware_attributes
346
+ time_zone_aware_types
347
+ timestamp_attributes_for_create_in_model
348
+ timestamp_attributes_for_update_in_model
349
+ to_ary
350
+ to_gid
351
+ to_gid_param
352
+ to_global_id
353
+ to_key
354
+ to_model
355
+ to_partial_path
356
+ to_sgid
357
+ to_sgid_param
358
+ to_signed_global_id
359
+ toggle
360
+ touch
361
+ touch_deferred_attributes
362
+ touch_later
363
+ transaction
364
+ transaction_include_any_action
365
+ trigger_transactional_callbacks
366
+ type_cast_attribute_value
367
+ type_for_attribute
368
+ update
369
+ update_attribute
370
+ update_column
371
+ update_columns
372
+ valid
373
+ validate
374
+ validate_collection_association
375
+ validate_encryption_allowed
376
+ validate_single_association
377
+ validates_absence_of
378
+ validates_acceptance_of
379
+ validates_comparison_of
380
+ validates_confirmation_of
381
+ validates_exclusion_of
382
+ validates_format_of
383
+ validates_inclusion_of
384
+ validates_length_of
385
+ validates_numericality_of
386
+ validates_presence_of
387
+ validates_size_of
388
+ validates_with
389
+ validation_context
390
+ validation_context=
391
+ values_at
392
+ verify_readonly_attribute
393
+ will_be_destroyed
394
+ will_save_change_to_attribute
395
+ with_lock
396
+ with_transaction_returning_status
397
+ write_attribute
398
+ write_store_attribute
399
+ ].freeze
400
+ # rubocop:enable Metrics/CollectionLiteralLength
401
+
402
+ MSG = 'Avoid dangerous column names.'
403
+
404
+ RESTRICT_ON_SEND = [:add_column, :rename, :rename_column, *COLUMN_TYPE_METHOD_NAMES].freeze
405
+
406
+ def on_send(node)
407
+ column_name_node = column_name_node_from(node)
408
+ return false unless column_name_node
409
+ return false unless dangerous_column_name_node?(column_name_node)
410
+
411
+ add_offense(column_name_node)
412
+ end
413
+
414
+ private
415
+
416
+ def column_name_node_from(node)
417
+ case node.method_name
418
+ when :add_column, :rename
419
+ node.arguments[1]
420
+ when :rename_column
421
+ node.arguments[2]
422
+ when *COLUMN_TYPE_METHOD_NAMES
423
+ node.arguments[0]
424
+ end
425
+ end
426
+
427
+ def dangerous_column_name_node?(node)
428
+ return false unless node.respond_to?(:value)
429
+
430
+ dangerous_column_name?(node.value.to_s)
431
+ end
432
+
433
+ def dangerous_column_name?(column_name)
434
+ DANGEROUS_COLUMN_NAMES.include?(column_name)
435
+ end
436
+ end
437
+ end
438
+ end
439
+ end
@@ -139,7 +139,7 @@ module RuboCop
139
139
  end
140
140
 
141
141
  def safe_to_time?(node)
142
- return unless node.method?(:to_time)
142
+ return false unless node.method?(:to_time)
143
143
 
144
144
  if node.receiver.str_type?
145
145
  zone_regexp = /([+-][\d:]+|\dZ)\z/