rubocop-rails 2.20.2 → 2.21.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/config/default.yml +55 -6
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +1 -1
- data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
- data/lib/rubocop/cop/rails/bulk_change_table.rb +20 -3
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +439 -0
- data/lib/rubocop/cop/rails/date.rb +1 -1
- data/lib/rubocop/cop/rails/duplicate_association.rb +3 -0
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -3
- data/lib/rubocop/cop/rails/file_path.rb +4 -1
- data/lib/rubocop/cop/rails/freeze_time.rb +1 -1
- data/lib/rubocop/cop/rails/http_status.rb +4 -3
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +63 -13
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +7 -8
- data/lib/rubocop/cop/rails/rake_environment.rb +20 -4
- data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +145 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
- data/lib/rubocop/cop/rails/root_pathname_methods.rb +38 -4
- data/lib/rubocop/cop/rails/save_bang.rb +2 -2
- data/lib/rubocop/cop/rails/schema_comment.rb +16 -10
- data/lib/rubocop/cop/rails/select_map.rb +75 -0
- data/lib/rubocop/cop/rails/time_zone.rb +12 -5
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +29 -10
- data/lib/rubocop/cop/rails/unused_render_content.rb +68 -0
- data/lib/rubocop/cop/rails/where_exists.rb +0 -1
- data/lib/rubocop/cop/rails_cops.rb +4 -0
- data/lib/rubocop/rails/schema_loader.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop-rails.rb +8 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9de78b7956de6935004b845bb3a50ae7b751aa5b81abbc4feceb62ea20b9d3a7
|
4
|
+
data.tar.gz: d8f7f57ae1cfe141e6082547f6ea40dbdc6d42f32c2e9f95ba4ec904baaeea7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b3366bdbfa5bd3a53715a3b7ab2fcc5ffd8a6e1eef1da7e557297a827f1caf92bdcfbd2c771e9ef384713d97a347d7f09e4ef792252f8e9900476f034a82ab
|
7
|
+
data.tar.gz: cb54c3f8a7a8ca823055341f531ed2922138c73f101e1cf2455376902b15d545708ddf3c94a06e44146f765277fbdf49e080eb6db085edf438afbaa4a2f61cbc
|
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.
|
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.
|
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,13 @@ 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
|
+
VersionAdded: '2.21'
|
805
|
+
|
778
806
|
Rails/RedundantAllowNil:
|
779
807
|
Description: >-
|
780
808
|
Finds redundant use of `allow_nil` when `allow_blank` is set to
|
@@ -955,6 +983,12 @@ Rails/ScopeArgs:
|
|
955
983
|
Include:
|
956
984
|
- app/models/**/*.rb
|
957
985
|
|
986
|
+
Rails/SelectMap:
|
987
|
+
Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
|
988
|
+
Enabled: pending
|
989
|
+
Safe: false
|
990
|
+
VersionAdded: '2.21'
|
991
|
+
|
958
992
|
Rails/ShortI18n:
|
959
993
|
Description: 'Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.'
|
960
994
|
StyleGuide: 'https://rails.rubystyle.guide/#short-i18n'
|
@@ -1083,6 +1117,7 @@ Rails/TransactionExitStatement:
|
|
1083
1117
|
- https://github.com/rails/rails/commit/15aa4200e083
|
1084
1118
|
Enabled: pending
|
1085
1119
|
VersionAdded: '2.14'
|
1120
|
+
TransactionMethods: []
|
1086
1121
|
|
1087
1122
|
Rails/UniqBeforePluck:
|
1088
1123
|
Description: 'Prefer the use of uniq or distinct before pluck.'
|
@@ -1120,6 +1155,12 @@ Rails/UnusedIgnoredColumns:
|
|
1120
1155
|
Include:
|
1121
1156
|
- app/models/**/*.rb
|
1122
1157
|
|
1158
|
+
Rails/UnusedRenderContent:
|
1159
|
+
Description: 'Do not specify body content for a response with a non-content status code.'
|
1160
|
+
Enabled: pending
|
1161
|
+
Severity: warning
|
1162
|
+
VersionAdded: '2.21'
|
1163
|
+
|
1123
1164
|
Rails/Validation:
|
1124
1165
|
Description: 'Use validates :attribute, hash of validations.'
|
1125
1166
|
Enabled: true
|
@@ -1175,6 +1216,14 @@ Style/FormatStringToken:
|
|
1175
1216
|
AllowedMethods:
|
1176
1217
|
- redirect
|
1177
1218
|
|
1219
|
+
Style/InvertibleUnlessCondition:
|
1220
|
+
InverseMethods:
|
1221
|
+
# Active Support defines some common inverse methods. They are listed below:
|
1222
|
+
:present?: :blank?
|
1223
|
+
:blank?: :present?
|
1224
|
+
:include?: :exclude?
|
1225
|
+
:exclude?: :include?
|
1226
|
+
|
1178
1227
|
Style/SymbolProc:
|
1179
1228
|
AllowedMethods:
|
1180
1229
|
- define_method
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
# Using `ActionController::TestCase
|
7
|
-
# `ActionDispatch::IntegrationTest
|
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`
|
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
|
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
|
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
include RangeHelp
|
25
25
|
extend AutoCorrector
|
26
26
|
include ClassSendNodeHelper
|
27
|
+
include ActiveRecordHelper
|
27
28
|
|
28
29
|
MSG = "Association `%<name>s` is defined multiple times. Don't repeat associations."
|
29
30
|
|
@@ -32,6 +33,8 @@ module RuboCop
|
|
32
33
|
PATTERN
|
33
34
|
|
34
35
|
def on_class(class_node)
|
36
|
+
return unless active_record?(class_node.parent_class)
|
37
|
+
|
35
38
|
offenses(class_node).each do |name, nodes|
|
36
39
|
nodes.each do |node|
|
37
40
|
add_offense(node, message: format(MSG, name: name)) do |corrector|
|