rubocop-rails 2.15.2 → 2.20.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +23 -2
- data/config/default.yml +181 -13
- data/config/obsoletion.yml +10 -0
- data/lib/rubocop/cop/mixin/active_record_helper.rb +3 -6
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +1 -3
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
- data/lib/rubocop/cop/mixin/index_method.rb +7 -17
- data/lib/rubocop/cop/mixin/migrations_helper.rb +1 -1
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +112 -0
- data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/action_order.rb +116 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +3 -4
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +6 -3
- data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
- data/lib/rubocop/cop/rails/active_support_on_load.rb +70 -0
- data/lib/rubocop/cop/rails/add_column_index.rb +2 -5
- data/lib/rubocop/cop/rails/application_controller.rb +1 -1
- data/lib/rubocop/cop/rails/application_job.rb +2 -2
- data/lib/rubocop/cop/rails/application_mailer.rb +1 -1
- data/lib/rubocop/cop/rails/application_record.rb +1 -1
- data/lib/rubocop/cop/rails/arel_star.rb +1 -1
- data/lib/rubocop/cop/rails/assert_not.rb +1 -2
- data/lib/rubocop/cop/rails/belongs_to.rb +1 -4
- data/lib/rubocop/cop/rails/blank.rb +6 -7
- data/lib/rubocop/cop/rails/bulk_change_table.rb +7 -24
- data/lib/rubocop/cop/rails/compact_blank.rb +5 -1
- data/lib/rubocop/cop/rails/content_tag.rb +5 -6
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +16 -3
- data/lib/rubocop/cop/rails/date.rb +15 -11
- data/lib/rubocop/cop/rails/delegate.rb +19 -8
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +18 -14
- data/lib/rubocop/cop/rails/dot_separated_keys.rb +2 -2
- data/lib/rubocop/cop/rails/duration_arithmetic.rb +3 -3
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +25 -13
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +5 -1
- data/lib/rubocop/cop/rails/enum_hash.rb +1 -1
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -5
- data/lib/rubocop/cop/rails/environment_comparison.rb +2 -3
- data/lib/rubocop/cop/rails/file_path.rb +154 -27
- data/lib/rubocop/cop/rails/find_by_id.rb +2 -2
- data/lib/rubocop/cop/rails/find_each.rb +15 -5
- data/lib/rubocop/cop/rails/freeze_time.rb +79 -0
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +4 -6
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +1 -1
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +22 -11
- data/lib/rubocop/cop/rails/http_status.rb +6 -11
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +2 -0
- data/lib/rubocop/cop/rails/i18n_locale_texts.rb +7 -3
- data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +23 -12
- data/lib/rubocop/cop/rails/index_by.rb +1 -1
- data/lib/rubocop/cop/rails/index_with.rb +1 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +3 -9
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +21 -15
- data/lib/rubocop/cop/rails/link_to_blank.rb +1 -4
- data/lib/rubocop/cop/rails/mailer_name.rb +4 -4
- data/lib/rubocop/cop/rails/migration_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/negate_include.rb +1 -1
- data/lib/rubocop/cop/rails/not_null_column.rb +9 -6
- data/lib/rubocop/cop/rails/output.rb +6 -8
- data/lib/rubocop/cop/rails/output_safety.rb +5 -1
- data/lib/rubocop/cop/rails/pluck.rb +44 -12
- data/lib/rubocop/cop/rails/pluck_id.rb +1 -1
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +1 -2
- data/lib/rubocop/cop/rails/presence.rb +21 -12
- data/lib/rubocop/cop/rails/present.rb +8 -11
- data/lib/rubocop/cop/rails/rake_environment.rb +2 -2
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +5 -7
- data/lib/rubocop/cop/rails/redundant_foreign_key.rb +2 -2
- data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +3 -3
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +30 -26
- data/lib/rubocop/cop/rails/reflection_class_name.rb +34 -1
- data/lib/rubocop/cop/rails/refute_methods.rb +1 -6
- data/lib/rubocop/cop/rails/relative_date_constant.rb +4 -7
- data/lib/rubocop/cop/rails/request_referer.rb +1 -2
- data/lib/rubocop/cop/rails/require_dependency.rb +1 -1
- data/lib/rubocop/cop/rails/response_parsed_body.rb +57 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +14 -62
- data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +1 -2
- data/lib/rubocop/cop/rails/root_join_chain.rb +1 -1
- data/lib/rubocop/cop/rails/root_pathname_methods.rb +238 -0
- data/lib/rubocop/cop/rails/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -3
- data/lib/rubocop/cop/rails/save_bang.rb +10 -22
- data/lib/rubocop/cop/rails/short_i18n.rb +2 -5
- data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -3
- data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +9 -7
- data/lib/rubocop/cop/rails/three_state_boolean_column.rb +71 -0
- data/lib/rubocop/cop/rails/time_zone.rb +27 -25
- data/lib/rubocop/cop/rails/time_zone_assignment.rb +1 -1
- data/lib/rubocop/cop/rails/to_s_with_argument.rb +78 -0
- data/lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb +49 -0
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +8 -3
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -6
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +22 -19
- data/lib/rubocop/cop/rails/unknown_env.rb +2 -4
- data/lib/rubocop/cop/rails/unused_ignored_columns.rb +6 -1
- data/lib/rubocop/cop/rails/validation.rb +4 -12
- data/lib/rubocop/cop/rails/where_equals.rb +1 -1
- data/lib/rubocop/cop/rails/where_exists.rb +1 -1
- data/lib/rubocop/cop/rails/where_missing.rb +118 -0
- data/lib/rubocop/cop/rails/where_not.rb +1 -1
- data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
- data/lib/rubocop/cop/rails_cops.rb +12 -0
- data/lib/rubocop/rails/schema_loader/schema.rb +4 -4
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop/rails.rb +1 -1
- data/lib/rubocop-rails.rb +11 -0
- metadata +19 -9
- data/bin/console +0 -11
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 227ce5b698e456412c24917c5644b2a938531440ab8c64e2b5036d6f2857a548
|
4
|
+
data.tar.gz: 41c6157da73215cca0b5d56ffa254711c2f9f4f5399c8aa3d85ac7c719958b28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afafd2f9293f4592cc914fdb42c6742900681574d5d0a27dc2031eddb3446b419ac04a77a149e0169ab89a0bb7afe4e0481b3ff889631345a0227b0d24a2c185
|
7
|
+
data.tar.gz: a90108eed94c1cedbe1b9a059b60cae51465cffd5a8612f56a0548182b6f992e3e626125e4a4f2f74ceda491a91cdcacb0bd8206ebf94d7d245841572639b556
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Note: This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<
|
|
12
12
|
Just install the `rubocop-rails` gem
|
13
13
|
|
14
14
|
```sh
|
15
|
-
gem install rubocop-rails
|
15
|
+
$ gem install rubocop-rails
|
16
16
|
```
|
17
17
|
|
18
18
|
or if you use bundler put this in your `Gemfile`
|
@@ -48,7 +48,7 @@ cops together with the standard cops.
|
|
48
48
|
### Command line
|
49
49
|
|
50
50
|
```sh
|
51
|
-
rubocop --require rubocop-rails
|
51
|
+
$ rubocop --require rubocop-rails
|
52
52
|
```
|
53
53
|
|
54
54
|
Note: `--rails` option is required while `rubocop` command supports `--rails` option.
|
@@ -61,6 +61,27 @@ RuboCop::RakeTask.new do |task|
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
+
## Rails configuration tip
|
65
|
+
|
66
|
+
If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
|
67
|
+
your config/application.rb to apply RuboCop autocorrection to code generated by `bin/rails g`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# config/application.rb
|
71
|
+
module YourCoolApp
|
72
|
+
class Application < Rails::Application
|
73
|
+
config.generators.after_generate do |files|
|
74
|
+
parsable_files = files.filter { |file| file.end_with?('.rb') }
|
75
|
+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorretion cops.
|
82
|
+
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
|
83
|
+
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
|
84
|
+
|
64
85
|
## The Cops
|
65
86
|
|
66
87
|
All cops are located under
|
data/config/default.yml
CHANGED
@@ -6,10 +6,17 @@ inherit_mode:
|
|
6
6
|
|
7
7
|
AllCops:
|
8
8
|
Exclude:
|
9
|
+
- app/assets/**/*
|
9
10
|
- bin/*
|
10
11
|
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
|
11
12
|
# See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
|
12
13
|
- db/*schema.rb
|
14
|
+
- log/**/*
|
15
|
+
- public/**/*
|
16
|
+
- storage/**/*
|
17
|
+
# Enable checking Active Support extensions.
|
18
|
+
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
|
19
|
+
ActiveSupportExtensionsEnabled: true
|
13
20
|
# What version of Rails is the inspected code using? If a value is specified
|
14
21
|
# for TargetRailsVersion then it is used. Acceptable values are specified
|
15
22
|
# as a float (i.e. 5.1); the patch version of Rails should not be included.
|
@@ -23,7 +30,7 @@ Lint/NumberConversion:
|
|
23
30
|
# Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
|
24
31
|
# so that calling `to_i` on one of these does not register an offense.
|
25
32
|
# See: https://github.com/rubocop/rubocop/issues/8950
|
26
|
-
|
33
|
+
AllowedMethods:
|
27
34
|
- ago
|
28
35
|
- from_now
|
29
36
|
- second
|
@@ -39,13 +46,37 @@ Lint/NumberConversion:
|
|
39
46
|
- fortnight
|
40
47
|
- fortnights
|
41
48
|
- in_milliseconds
|
49
|
+
AllowedPatterns: []
|
50
|
+
|
51
|
+
Lint/RedundantSafeNavigation:
|
52
|
+
# Add `presence` and `present?` methods to the default of the RuboCop core.
|
53
|
+
# https://github.com/rubocop/rubocop/blob/v1.51.0/config/default.yml#L2148-L2159
|
54
|
+
AllowedMethods:
|
55
|
+
- instance_of?
|
56
|
+
- kind_of?
|
57
|
+
- is_a?
|
58
|
+
- eql?
|
59
|
+
- respond_to?
|
60
|
+
- equal?
|
61
|
+
- presence
|
62
|
+
- present?
|
63
|
+
|
64
|
+
Rails:
|
65
|
+
Enabled: true
|
66
|
+
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
|
67
|
+
|
68
|
+
Rails/ActionControllerFlashBeforeRender:
|
69
|
+
Description: 'Use `flash.now` instead of `flash` before `render`.'
|
70
|
+
Enabled: 'pending'
|
71
|
+
SafeAutoCorrect: false
|
72
|
+
VersionAdded: '2.16'
|
42
73
|
|
43
74
|
Rails/ActionControllerTestCase:
|
44
75
|
Description: 'Use `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase`.'
|
45
76
|
StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
|
46
77
|
Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
|
47
78
|
Enabled: 'pending'
|
48
|
-
|
79
|
+
SafeAutoCorrect: false
|
49
80
|
VersionAdded: '2.14'
|
50
81
|
Include:
|
51
82
|
- '**/test/**/*.rb'
|
@@ -62,6 +93,21 @@ Rails/ActionFilter:
|
|
62
93
|
- app/controllers/**/*.rb
|
63
94
|
- app/mailers/**/*.rb
|
64
95
|
|
96
|
+
Rails/ActionOrder:
|
97
|
+
Description: 'Enforce consistent ordering of controller actions.'
|
98
|
+
Enabled: pending
|
99
|
+
VersionAdded: '2.17'
|
100
|
+
ExpectedOrder:
|
101
|
+
- index
|
102
|
+
- show
|
103
|
+
- new
|
104
|
+
- edit
|
105
|
+
- create
|
106
|
+
- update
|
107
|
+
- destroy
|
108
|
+
Include:
|
109
|
+
- app/controllers/**/*.rb
|
110
|
+
|
65
111
|
Rails/ActiveRecordAliases:
|
66
112
|
Description: >-
|
67
113
|
Avoid Active Record aliases:
|
@@ -84,7 +130,9 @@ Rails/ActiveRecordOverride:
|
|
84
130
|
Check for overriding Active Record methods instead of using
|
85
131
|
callbacks.
|
86
132
|
Enabled: true
|
133
|
+
Severity: warning
|
87
134
|
VersionAdded: '0.67'
|
135
|
+
VersionChanged: '2.18'
|
88
136
|
Include:
|
89
137
|
- app/models/**/*.rb
|
90
138
|
|
@@ -96,6 +144,15 @@ Rails/ActiveSupportAliases:
|
|
96
144
|
Enabled: true
|
97
145
|
VersionAdded: '0.48'
|
98
146
|
|
147
|
+
Rails/ActiveSupportOnLoad:
|
148
|
+
Description: 'Use `ActiveSupport.on_load(...)` to patch Rails framework classes.'
|
149
|
+
Enabled: 'pending'
|
150
|
+
Reference:
|
151
|
+
- 'https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html'
|
152
|
+
- 'https://guides.rubyonrails.org/engines.html#available-load-hooks'
|
153
|
+
SafeAutoCorrect: false
|
154
|
+
VersionAdded: '2.16'
|
155
|
+
|
99
156
|
Rails/AddColumnIndex:
|
100
157
|
Description: >-
|
101
158
|
Rails migrations don't make use of a given `index` key, but also
|
@@ -103,8 +160,9 @@ Rails/AddColumnIndex:
|
|
103
160
|
index might be used.
|
104
161
|
Enabled: pending
|
105
162
|
VersionAdded: '2.11'
|
163
|
+
VersionChanged: '2.20'
|
106
164
|
Include:
|
107
|
-
- db
|
165
|
+
- db/**/*.rb
|
108
166
|
|
109
167
|
Rails/AfterCommitOverride:
|
110
168
|
Description: >-
|
@@ -166,6 +224,9 @@ Rails/BelongsTo:
|
|
166
224
|
Description: >-
|
167
225
|
Use `optional: true` instead of `required: false` for
|
168
226
|
`belongs_to` relations.
|
227
|
+
Reference:
|
228
|
+
- https://guides.rubyonrails.org/5_0_release_notes.html
|
229
|
+
- https://github.com/rails/rails/pull/18937
|
169
230
|
Enabled: true
|
170
231
|
VersionAdded: '0.62'
|
171
232
|
|
@@ -184,14 +245,18 @@ Rails/Blank:
|
|
184
245
|
|
185
246
|
Rails/BulkChangeTable:
|
186
247
|
Description: 'Check whether alter queries are combinable.'
|
248
|
+
Reference:
|
249
|
+
- https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_table
|
250
|
+
- https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html
|
187
251
|
Enabled: true
|
188
252
|
VersionAdded: '0.57'
|
253
|
+
VersionChanged: '2.20'
|
189
254
|
Database: null
|
190
255
|
SupportedDatabases:
|
191
256
|
- mysql
|
192
257
|
- postgresql
|
193
258
|
Include:
|
194
|
-
- db
|
259
|
+
- db/**/*.rb
|
195
260
|
|
196
261
|
Rails/CompactBlank:
|
197
262
|
Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
|
@@ -221,18 +286,22 @@ Rails/CreateTableWithTimestamps:
|
|
221
286
|
when creating a new table.
|
222
287
|
Enabled: true
|
223
288
|
VersionAdded: '0.52'
|
289
|
+
VersionChanged: '2.20'
|
224
290
|
Include:
|
225
|
-
- db
|
291
|
+
- db/**/*.rb
|
226
292
|
Exclude:
|
227
293
|
# Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
|
294
|
+
# and `*_create_active_storage_variant_records.active_storage.rb`
|
228
295
|
# auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
|
229
|
-
- db
|
296
|
+
- db/**/*_create_active_storage_tables.active_storage.rb
|
297
|
+
- db/**/*_create_active_storage_variant_records.active_storage.rb
|
230
298
|
|
231
299
|
Rails/Date:
|
232
300
|
Description: >-
|
233
301
|
Checks the correct usage of date aware methods,
|
234
302
|
such as Date.today, Date.current etc.
|
235
303
|
Enabled: true
|
304
|
+
SafeAutoCorrect: false
|
236
305
|
VersionAdded: '0.30'
|
237
306
|
VersionChanged: '2.11'
|
238
307
|
# The value `strict` disallows usage of `Date.today`, `Date.current`,
|
@@ -270,9 +339,10 @@ Rails/DelegateAllowBlank:
|
|
270
339
|
Rails/DeprecatedActiveModelErrorsMethods:
|
271
340
|
Description: 'Avoid manipulating ActiveModel errors hash directly.'
|
272
341
|
Enabled: pending
|
342
|
+
Severity: warning
|
273
343
|
Safe: false
|
274
344
|
VersionAdded: '2.14'
|
275
|
-
VersionChanged: '2.
|
345
|
+
VersionChanged: '2.18'
|
276
346
|
|
277
347
|
Rails/DotSeparatedKeys:
|
278
348
|
Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
|
@@ -283,12 +353,16 @@ Rails/DotSeparatedKeys:
|
|
283
353
|
Rails/DuplicateAssociation:
|
284
354
|
Description: "Don't repeat associations in a model."
|
285
355
|
Enabled: pending
|
356
|
+
Severity: warning
|
286
357
|
VersionAdded: '2.14'
|
358
|
+
VersionChanged: '2.18'
|
287
359
|
|
288
360
|
Rails/DuplicateScope:
|
289
361
|
Description: 'Multiple scopes share this same where clause.'
|
290
362
|
Enabled: pending
|
363
|
+
Severity: warning
|
291
364
|
VersionAdded: '2.14'
|
365
|
+
VersionChanged: '2.18'
|
292
366
|
|
293
367
|
Rails/DurationArithmetic:
|
294
368
|
Description: 'Do not use duration as arithmetic operand with `Time.current`.'
|
@@ -306,10 +380,13 @@ Rails/DynamicFindBy:
|
|
306
380
|
# The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
|
307
381
|
Whitelist:
|
308
382
|
- find_by_sql
|
383
|
+
- find_by_token_for
|
309
384
|
AllowedMethods:
|
310
385
|
- find_by_sql
|
386
|
+
- find_by_token_for
|
311
387
|
AllowedReceivers:
|
312
388
|
- Gem::Specification
|
389
|
+
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
|
313
390
|
|
314
391
|
Rails/EagerEvaluationLogMessage:
|
315
392
|
Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
|
@@ -400,19 +477,28 @@ Rails/FindById:
|
|
400
477
|
VersionAdded: '2.7'
|
401
478
|
|
402
479
|
Rails/FindEach:
|
403
|
-
Description: 'Prefer all.find_each over all.
|
480
|
+
Description: 'Prefer all.find_each over all.each.'
|
404
481
|
StyleGuide: 'https://rails.rubystyle.guide#find-each'
|
405
482
|
Enabled: true
|
483
|
+
Safe: false
|
406
484
|
VersionAdded: '0.30'
|
407
|
-
VersionChanged: '2.
|
485
|
+
VersionChanged: '2.19'
|
408
486
|
Include:
|
409
487
|
- app/models/**/*.rb
|
410
|
-
|
488
|
+
AllowedMethods:
|
411
489
|
# Methods that don't work well with `find_each`.
|
412
490
|
- order
|
413
491
|
- limit
|
414
492
|
- select
|
415
493
|
- lock
|
494
|
+
AllowedPatterns: []
|
495
|
+
|
496
|
+
Rails/FreezeTime:
|
497
|
+
Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.'
|
498
|
+
StyleGuide: 'https://rails.rubystyle.guide/#freeze-time'
|
499
|
+
Enabled: pending
|
500
|
+
VersionAdded: '2.16'
|
501
|
+
SafeAutoCorrect: false
|
416
502
|
|
417
503
|
Rails/HasAndBelongsToMany:
|
418
504
|
Description: 'Prefer has_many :through to has_and_belongs_to_many.'
|
@@ -462,7 +548,7 @@ Rails/I18nLazyLookup:
|
|
462
548
|
Enabled: pending
|
463
549
|
VersionAdded: '2.14'
|
464
550
|
Include:
|
465
|
-
- 'controllers
|
551
|
+
- 'app/controllers/**/*.rb'
|
466
552
|
|
467
553
|
Rails/I18nLocaleAssignment:
|
468
554
|
Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
|
@@ -478,6 +564,13 @@ Rails/I18nLocaleTexts:
|
|
478
564
|
Enabled: pending
|
479
565
|
VersionAdded: '2.14'
|
480
566
|
|
567
|
+
Rails/IgnoredColumnsAssignment:
|
568
|
+
Description: 'Looks for assignments of `ignored_columns` that override previous assignments.'
|
569
|
+
StyleGuide: 'https://rails.rubystyle.guide/#append-ignored-columns'
|
570
|
+
Enabled: pending
|
571
|
+
SafeAutoCorrect: false
|
572
|
+
VersionAdded: '2.17'
|
573
|
+
|
481
574
|
Rails/IgnoredSkipActionFilterOption:
|
482
575
|
Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
|
483
576
|
Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
|
@@ -507,6 +600,9 @@ Rails/Inquiry:
|
|
507
600
|
|
508
601
|
Rails/InverseOf:
|
509
602
|
Description: 'Checks for associations where the inverse cannot be determined automatically.'
|
603
|
+
Reference:
|
604
|
+
- https://guides.rubyonrails.org/association_basics.html#bi-directional-associations
|
605
|
+
- https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
|
510
606
|
Enabled: true
|
511
607
|
VersionAdded: '0.52'
|
512
608
|
IgnoreScopes: false
|
@@ -556,8 +652,9 @@ Rails/MigrationClassName:
|
|
556
652
|
Description: 'The class name of the migration should match its file name.'
|
557
653
|
Enabled: pending
|
558
654
|
VersionAdded: '2.14'
|
655
|
+
VersionChanged: '2.20'
|
559
656
|
Include:
|
560
|
-
- db
|
657
|
+
- db/**/*.rb
|
561
658
|
|
562
659
|
Rails/NegateInclude:
|
563
660
|
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
|
@@ -571,8 +668,9 @@ Rails/NotNullColumn:
|
|
571
668
|
Description: 'Do not add a NOT NULL column without a default value.'
|
572
669
|
Enabled: true
|
573
670
|
VersionAdded: '0.43'
|
671
|
+
VersionChanged: '2.20'
|
574
672
|
Include:
|
575
|
-
- db
|
673
|
+
- db/**/*.rb
|
576
674
|
|
577
675
|
Rails/OrderById:
|
578
676
|
Description: >-
|
@@ -610,7 +708,9 @@ Rails/Pluck:
|
|
610
708
|
Description: 'Prefer `pluck` over `map { ... }`.'
|
611
709
|
StyleGuide: 'https://rails.rubystyle.guide#pluck'
|
612
710
|
Enabled: 'pending'
|
711
|
+
Safe: false
|
613
712
|
VersionAdded: '2.7'
|
713
|
+
VersionChanged: '2.18'
|
614
714
|
|
615
715
|
Rails/PluckId:
|
616
716
|
Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
|
@@ -762,6 +862,18 @@ Rails/RequireDependency:
|
|
762
862
|
Enabled: false
|
763
863
|
VersionAdded: '2.10'
|
764
864
|
|
865
|
+
Rails/ResponseParsedBody:
|
866
|
+
Description: Prefer `response.parsed_body` to `JSON.parse(response.body)`.
|
867
|
+
Enabled: pending
|
868
|
+
Safe: false
|
869
|
+
VersionAdded: '2.18'
|
870
|
+
VersionChanged: '2.19'
|
871
|
+
Include:
|
872
|
+
- spec/controllers/**/*.rb
|
873
|
+
- spec/requests/**/*.rb
|
874
|
+
- test/controllers/**/*.rb
|
875
|
+
- test/integration/**/*.rb
|
876
|
+
|
765
877
|
Rails/ReversibleMigration:
|
766
878
|
Description: 'Checks whether the change method of the migration file is reversible.'
|
767
879
|
StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
|
@@ -785,6 +897,12 @@ Rails/RootJoinChain:
|
|
785
897
|
Enabled: pending
|
786
898
|
VersionAdded: '2.13'
|
787
899
|
|
900
|
+
Rails/RootPathnameMethods:
|
901
|
+
Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
|
902
|
+
Enabled: pending
|
903
|
+
SafeAutoCorrect: false
|
904
|
+
VersionAdded: '2.16'
|
905
|
+
|
788
906
|
Rails/RootPublicPath:
|
789
907
|
Description: "Favor `Rails.public_path` over `Rails.root` with `'public'`."
|
790
908
|
Enabled: pending
|
@@ -901,6 +1019,14 @@ Rails/TableNameAssignment:
|
|
901
1019
|
Include:
|
902
1020
|
- app/models/**/*.rb
|
903
1021
|
|
1022
|
+
Rails/ThreeStateBooleanColumn:
|
1023
|
+
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
|
1024
|
+
StyleGuide: 'https://rails.rubystyle.guide/#three-state-boolean'
|
1025
|
+
Enabled: pending
|
1026
|
+
VersionAdded: '2.19'
|
1027
|
+
Include:
|
1028
|
+
- db/**/*.rb
|
1029
|
+
|
904
1030
|
Rails/TimeZone:
|
905
1031
|
Description: 'Checks the correct usage of time zone aware methods.'
|
906
1032
|
StyleGuide: 'https://rails.rubystyle.guide#time'
|
@@ -937,8 +1063,24 @@ Rails/ToFormattedS:
|
|
937
1063
|
- to_formatted_s
|
938
1064
|
VersionAdded: '2.15'
|
939
1065
|
|
1066
|
+
Rails/ToSWithArgument:
|
1067
|
+
Description: 'Identifies passing any argument to `#to_s`.'
|
1068
|
+
Enabled: pending
|
1069
|
+
Safe: false
|
1070
|
+
VersionAdded: '2.16'
|
1071
|
+
|
1072
|
+
Rails/TopLevelHashWithIndifferentAccess:
|
1073
|
+
Description: 'Identifies top-level `HashWithIndifferentAccess`.'
|
1074
|
+
Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated'
|
1075
|
+
Enabled: pending
|
1076
|
+
Severity: warning
|
1077
|
+
VersionAdded: '2.16'
|
1078
|
+
VersionChanged: '2.18'
|
1079
|
+
|
940
1080
|
Rails/TransactionExitStatement:
|
941
1081
|
Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
|
1082
|
+
Reference:
|
1083
|
+
- https://github.com/rails/rails/commit/15aa4200e083
|
942
1084
|
Enabled: pending
|
943
1085
|
VersionAdded: '2.14'
|
944
1086
|
|
@@ -963,7 +1105,9 @@ Rails/UniqueValidationWithoutIndex:
|
|
963
1105
|
Rails/UnknownEnv:
|
964
1106
|
Description: 'Use correct environment name.'
|
965
1107
|
Enabled: true
|
1108
|
+
Severity: warning
|
966
1109
|
VersionAdded: '0.51'
|
1110
|
+
VersionChanged: '2.18'
|
967
1111
|
Environments:
|
968
1112
|
- development
|
969
1113
|
- test
|
@@ -1003,12 +1147,36 @@ Rails/WhereExists:
|
|
1003
1147
|
VersionAdded: '2.7'
|
1004
1148
|
VersionChanged: '2.10'
|
1005
1149
|
|
1150
|
+
Rails/WhereMissing:
|
1151
|
+
Description: 'Use `where.missing(...)` to find missing relationship records.'
|
1152
|
+
StyleGuide: 'https://rails.rubystyle.guide/#finding-missing-relationship-records'
|
1153
|
+
Enabled: pending
|
1154
|
+
VersionAdded: '2.16'
|
1155
|
+
|
1006
1156
|
Rails/WhereNot:
|
1007
1157
|
Description: 'Use `where.not(...)` instead of manually constructing negated SQL in `where`.'
|
1008
1158
|
StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
|
1009
1159
|
Enabled: 'pending'
|
1010
1160
|
VersionAdded: '2.8'
|
1011
1161
|
|
1162
|
+
Rails/WhereNotWithMultipleConditions:
|
1163
|
+
Description: 'Do not use `where.not(...)` with multiple conditions.'
|
1164
|
+
StyleGuide: 'https://rails.rubystyle.guide/#where-not-with-multiple-attributes'
|
1165
|
+
Enabled: 'pending'
|
1166
|
+
Severity: warning
|
1167
|
+
VersionAdded: '2.17'
|
1168
|
+
VersionChanged: '2.18'
|
1169
|
+
|
1012
1170
|
# Accept `redirect_to(...) and return` and similar cases.
|
1013
1171
|
Style/AndOr:
|
1014
1172
|
EnforcedStyle: conditionals
|
1173
|
+
|
1174
|
+
Style/FormatStringToken:
|
1175
|
+
AllowedMethods:
|
1176
|
+
- redirect
|
1177
|
+
|
1178
|
+
Style/SymbolProc:
|
1179
|
+
AllowedMethods:
|
1180
|
+
- define_method
|
1181
|
+
- mail
|
1182
|
+
- respond_to
|
data/config/obsoletion.yml
CHANGED
@@ -5,3 +5,13 @@
|
|
5
5
|
#
|
6
6
|
extracted:
|
7
7
|
Rails/*: ~
|
8
|
+
|
9
|
+
# Cop parameters that have been changed
|
10
|
+
# Can be treated as a warning instead of a failure with `severity: warning`
|
11
|
+
changed_parameters:
|
12
|
+
- cops: Rails/FindEach
|
13
|
+
parameters: IgnoredMethods
|
14
|
+
alternatives:
|
15
|
+
- AllowedMethods
|
16
|
+
- AllowedPatterns
|
17
|
+
severity: warning
|
@@ -10,8 +10,8 @@ module RuboCop
|
|
10
10
|
|
11
11
|
def_node_matcher :active_record?, <<~PATTERN
|
12
12
|
{
|
13
|
-
(const nil? :ApplicationRecord)
|
14
|
-
(const (const nil? :ActiveRecord) :Base)
|
13
|
+
(const {nil? cbase} :ApplicationRecord)
|
14
|
+
(const (const {nil? cbase} :ActiveRecord) :Base)
|
15
15
|
}
|
16
16
|
PATTERN
|
17
17
|
|
@@ -48,10 +48,7 @@ module RuboCop
|
|
48
48
|
|
49
49
|
class_nodes = class_node.defined_module.each_node
|
50
50
|
namespaces = class_node.each_ancestor(:class, :module).map(&:identifier)
|
51
|
-
[*class_nodes, *namespaces]
|
52
|
-
.reverse
|
53
|
-
.map { |node| node.children[1] }.join('_')
|
54
|
-
.tableize
|
51
|
+
[*class_nodes, *namespaces].reverse.map { |node| node.children[1] }.join('_').tableize
|
55
52
|
end
|
56
53
|
|
57
54
|
# Resolve relation into column name.
|
@@ -10,9 +10,7 @@ module RuboCop
|
|
10
10
|
bigint binary boolean date datetime decimal float integer json string
|
11
11
|
text time timestamp virtual
|
12
12
|
].freeze
|
13
|
-
RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[
|
14
|
-
column references belongs_to primary_key numeric
|
15
|
-
].freeze
|
13
|
+
RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[column references belongs_to primary_key numeric].freeze
|
16
14
|
POSTGRES_SCHEMA_DEFINITIONS = %i[
|
17
15
|
bigserial bit bit_varying cidr citext daterange hstore inet interval
|
18
16
|
int4range int8range jsonb ltree macaddr money numrange oid point line
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
module IndexMethod # rubocop:disable Metrics/ModuleLength
|
7
7
|
RESTRICT_ON_SEND = %i[each_with_object to_h map collect []].freeze
|
8
8
|
|
9
|
-
def on_block(node)
|
9
|
+
def on_block(node) # rubocop:todo InternalAffairs/NumblockHandler
|
10
10
|
on_bad_each_with_object(node) do |*match|
|
11
11
|
handle_possible_offense(node, match, 'each_with_object')
|
12
12
|
end
|
@@ -98,10 +98,7 @@ module RuboCop
|
|
98
98
|
|
99
99
|
captures = extract_captures(correction.match)
|
100
100
|
correction.set_new_arg_name(captures.transformed_argname, corrector)
|
101
|
-
correction.set_new_body_expression(
|
102
|
-
captures.transforming_body_expr,
|
103
|
-
corrector
|
104
|
-
)
|
101
|
+
correction.set_new_body_expression(captures.transforming_body_expr, corrector)
|
105
102
|
end
|
106
103
|
|
107
104
|
# Internal helper class to hold match data
|
@@ -110,8 +107,7 @@ module RuboCop
|
|
110
107
|
:transforming_body_expr
|
111
108
|
) do
|
112
109
|
def noop_transformation?
|
113
|
-
transforming_body_expr.lvar_type? &&
|
114
|
-
transforming_body_expr.children == [transformed_argname]
|
110
|
+
transforming_body_expr.lvar_type? && transforming_body_expr.children == [transformed_argname]
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
@@ -138,11 +134,11 @@ module RuboCop
|
|
138
134
|
end
|
139
135
|
|
140
136
|
def self.from_hash_brackets_map(node, match)
|
141
|
-
new(match, node.children.last,
|
137
|
+
new(match, node.children.last, "#{node.receiver.source}[".length, ']'.length)
|
142
138
|
end
|
143
139
|
|
144
140
|
def strip_prefix_and_suffix(node, corrector)
|
145
|
-
expression = node.
|
141
|
+
expression = node.source_range
|
146
142
|
corrector.remove_leading(expression, leading)
|
147
143
|
corrector.remove_trailing(expression, trailing)
|
148
144
|
end
|
@@ -157,17 +153,11 @@ module RuboCop
|
|
157
153
|
end
|
158
154
|
|
159
155
|
def set_new_arg_name(transformed_argname, corrector)
|
160
|
-
corrector.replace(
|
161
|
-
block_node.arguments.loc.expression,
|
162
|
-
"|#{transformed_argname}|"
|
163
|
-
)
|
156
|
+
corrector.replace(block_node.arguments, "|#{transformed_argname}|")
|
164
157
|
end
|
165
158
|
|
166
159
|
def set_new_body_expression(transforming_body_expr, corrector)
|
167
|
-
corrector.replace(
|
168
|
-
block_node.body.loc.expression,
|
169
|
-
transforming_body_expr.loc.expression.source
|
170
|
-
)
|
160
|
+
corrector.replace(block_node.body, transforming_body_expr.source)
|
171
161
|
end
|
172
162
|
end
|
173
163
|
end
|