rubocop-rails 2.19.1 → 2.30.3
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/LICENSE.txt +1 -1
- data/README.md +70 -16
- data/config/default.yml +173 -28
- data/lib/rubocop/cop/mixin/active_record_helper.rb +16 -4
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +2 -2
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +66 -0
- data/lib/rubocop/cop/mixin/index_method.rb +68 -61
- data/lib/rubocop/cop/mixin/routes_helper.rb +20 -0
- data/lib/rubocop/cop/mixin/target_rails_version.rb +27 -2
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +3 -1
- data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
- data/lib/rubocop/cop/rails/action_filter.rb +3 -0
- data/lib/rubocop/cop/rails/action_order.rb +1 -5
- data/lib/rubocop/cop/rails/active_record_aliases.rb +2 -2
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +1 -5
- data/lib/rubocop/cop/rails/active_support_aliases.rb +6 -5
- data/lib/rubocop/cop/rails/active_support_on_load.rb +21 -1
- data/lib/rubocop/cop/rails/add_column_index.rb +1 -0
- data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
- data/lib/rubocop/cop/rails/application_record.rb +4 -0
- data/lib/rubocop/cop/rails/assert_not.rb +0 -1
- data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
- data/lib/rubocop/cop/rails/blank.rb +1 -1
- data/lib/rubocop/cop/rails/bulk_change_table.rb +19 -45
- data/lib/rubocop/cop/rails/compact_blank.rb +29 -8
- data/lib/rubocop/cop/rails/content_tag.rb +2 -2
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +448 -0
- data/lib/rubocop/cop/rails/date.rb +14 -5
- data/lib/rubocop/cop/rails/delegate.rb +53 -7
- data/lib/rubocop/cop/rails/duplicate_association.rb +71 -10
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -3
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +2 -2
- data/lib/rubocop/cop/rails/enum_hash.rb +31 -8
- data/lib/rubocop/cop/rails/enum_syntax.rb +130 -0
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +29 -7
- data/lib/rubocop/cop/rails/env_local.rb +69 -0
- data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
- data/lib/rubocop/cop/rails/file_path.rb +186 -18
- data/lib/rubocop/cop/rails/find_by.rb +3 -3
- data/lib/rubocop/cop/rails/find_by_id.rb +9 -23
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/freeze_time.rb +1 -1
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +1 -1
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +1 -1
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +7 -0
- data/lib/rubocop/cop/rails/http_status.rb +16 -5
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +63 -13
- data/lib/rubocop/cop/rails/i18n_locale_texts.rb +5 -1
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +23 -3
- data/lib/rubocop/cop/rails/index_by.rb +28 -12
- data/lib/rubocop/cop/rails/index_with.rb +28 -12
- data/lib/rubocop/cop/rails/inquiry.rb +2 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +19 -10
- data/lib/rubocop/cop/rails/link_to_blank.rb +2 -2
- data/lib/rubocop/cop/rails/match_route.rb +1 -9
- data/lib/rubocop/cop/rails/multiple_route_paths.rb +50 -0
- data/lib/rubocop/cop/rails/not_null_column.rb +100 -6
- data/lib/rubocop/cop/rails/output.rb +3 -2
- data/lib/rubocop/cop/rails/pick.rb +10 -5
- data/lib/rubocop/cop/rails/pluck.rb +21 -1
- data/lib/rubocop/cop/rails/pluck_id.rb +2 -1
- data/lib/rubocop/cop/rails/pluck_in_where.rb +35 -13
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +30 -16
- data/lib/rubocop/cop/rails/presence.rb +1 -1
- data/lib/rubocop/cop/rails/present.rb +1 -3
- data/lib/rubocop/cop/rails/rake_environment.rb +22 -6
- data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +190 -0
- data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +16 -0
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +2 -2
- data/lib/rubocop/cop/rails/reflection_class_name.rb +2 -2
- data/lib/rubocop/cop/rails/refute_methods.rb +0 -1
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/render_plain_text.rb +6 -3
- data/lib/rubocop/cop/rails/request_referer.rb +1 -1
- data/lib/rubocop/cop/rails/response_parsed_body.rb +52 -10
- data/lib/rubocop/cop/rails/reversible_migration.rb +7 -5
- data/lib/rubocop/cop/rails/root_pathname_methods.rb +58 -15
- data/lib/rubocop/cop/rails/save_bang.rb +22 -14
- data/lib/rubocop/cop/rails/schema_comment.rb +17 -10
- data/lib/rubocop/cop/rails/select_map.rb +79 -0
- data/lib/rubocop/cop/rails/skips_model_validations.rb +9 -4
- data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +1 -2
- data/lib/rubocop/cop/rails/strip_heredoc.rb +1 -1
- data/lib/rubocop/cop/rails/strong_parameters_expect.rb +104 -0
- data/lib/rubocop/cop/rails/three_state_boolean_column.rb +4 -5
- data/lib/rubocop/cop/rails/time_zone.rb +26 -11
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +40 -9
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +11 -26
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +17 -21
- data/lib/rubocop/cop/rails/unknown_env.rb +5 -1
- data/lib/rubocop/cop/rails/unused_ignored_columns.rb +6 -0
- data/lib/rubocop/cop/rails/unused_render_content.rb +67 -0
- data/lib/rubocop/cop/rails/validation.rb +9 -4
- data/lib/rubocop/cop/rails/where_equals.rb +29 -12
- data/lib/rubocop/cop/rails/where_exists.rb +9 -9
- data/lib/rubocop/cop/rails/where_missing.rb +6 -2
- data/lib/rubocop/cop/rails/where_not.rb +18 -11
- data/lib/rubocop/cop/rails/where_range.rb +203 -0
- data/lib/rubocop/cop/rails_cops.rb +11 -0
- data/lib/rubocop/rails/migration_file_skippable.rb +54 -0
- data/lib/rubocop/rails/plugin.rb +48 -0
- data/lib/rubocop/rails/schema_loader/schema.rb +8 -7
- data/lib/rubocop/rails/schema_loader.rb +5 -15
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop/rails.rb +1 -8
- data/lib/rubocop-rails.rb +12 -4
- metadata +55 -11
- data/lib/rubocop/rails/inject.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a45ebdeef3a184afbb85ff1e1685fa978198ee00cf3bbbc0f1cbfa04b56f9dc7
|
4
|
+
data.tar.gz: 2d06943201b3836891ed9f8c0bd9a5e2bebd90de7736351add71af9460e271b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed82ce027a4bee9e6dfa16dd763fa856d7b19b96356b918d469ef1274ef0c5a4e8ea5e949c6aaed84ee6d0f290ca838e34e352929640294a6bd4d579c0145cdd
|
7
|
+
data.tar.gz: 7e11061742bc02b64742e4219ccfea80d5befb27572cb043d7ebc57c7a616f2fd2c8b829ac08dfad6b644f23d8a0f096c8b571cc5b8e9ecf34e7769f1f551fb4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# RuboCop Rails
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/rubocop-rails)
|
4
|
-
[](https://github.com/rubocop/rubocop-rails/actions/workflows/test.yml)
|
5
5
|
|
6
6
|
A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Rails best practices and coding conventions.
|
7
7
|
|
8
|
-
|
8
|
+
> [!IMPORTANT]
|
9
|
+
> This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<= 1.5.0) has been renamed to [rubocop-rails_config](https://rubygems.org/gems/rubocop-rails_config) gem.
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -31,13 +32,13 @@ ways to do this:
|
|
31
32
|
Put this into your `.rubocop.yml`.
|
32
33
|
|
33
34
|
```yaml
|
34
|
-
|
35
|
+
plugins: rubocop-rails
|
35
36
|
```
|
36
37
|
|
37
38
|
Alternatively, use the following array notation when specifying multiple extensions.
|
38
39
|
|
39
40
|
```yaml
|
40
|
-
|
41
|
+
plugins:
|
41
42
|
- rubocop-other-extension
|
42
43
|
- rubocop-rails
|
43
44
|
```
|
@@ -45,43 +46,96 @@ require:
|
|
45
46
|
Now you can run `rubocop` and it will automatically load the RuboCop Rails
|
46
47
|
cops together with the standard cops.
|
47
48
|
|
49
|
+
> [!NOTE]
|
50
|
+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
|
51
|
+
|
48
52
|
### Command line
|
49
53
|
|
50
54
|
```sh
|
51
|
-
$ rubocop --
|
55
|
+
$ rubocop --plugin rubocop-rails
|
52
56
|
```
|
53
57
|
|
54
|
-
Note: `--rails` option is required while `rubocop` command supports `--rails` option.
|
55
|
-
|
56
58
|
### Rake task
|
57
59
|
|
58
60
|
```ruby
|
61
|
+
require 'rubocop/rake_task'
|
62
|
+
|
59
63
|
RuboCop::RakeTask.new do |task|
|
60
|
-
task.
|
64
|
+
task.plugins << 'rubocop-rails'
|
61
65
|
end
|
62
66
|
```
|
63
67
|
|
68
|
+
## RuboCop Rails configuration
|
69
|
+
|
70
|
+
The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`.
|
71
|
+
|
72
|
+
### `AllCops: TargetRailsVersion`
|
73
|
+
|
74
|
+
What version of Rails is the inspected code using? If a value is specified
|
75
|
+
for `TargetRailsVersion` then it is used. Acceptable values are specified
|
76
|
+
as a float (e.g., 7.2); the patch version of Rails should not be included.
|
77
|
+
|
78
|
+
```yaml
|
79
|
+
AllCops:
|
80
|
+
TargetRailsVersion: 7.2
|
81
|
+
```
|
82
|
+
|
83
|
+
If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
|
84
|
+
gems.locked file to find the version of Rails that has been bound to the
|
85
|
+
application. If neither of those files exist, RuboCop will use Rails 5.0
|
86
|
+
as the default.
|
87
|
+
|
88
|
+
### `AllCops: MigratedSchemaVersion`
|
89
|
+
|
90
|
+
By specifying the `MigratedSchemaVersion` option, migration files that have already been run can be ignored.
|
91
|
+
When `MigratedSchemaVersion: '20241225000000'` is set, migration files lower than or equal to '20241225000000' will be ignored.
|
92
|
+
For example, to ignore db/migrate/20241225000000_create_articles.rb and earlier migrations you would configure it the following way:
|
93
|
+
|
94
|
+
```yaml
|
95
|
+
AllCops:
|
96
|
+
MigratedSchemaVersion: '20241225000000'
|
97
|
+
```
|
98
|
+
|
99
|
+
This prevents inspecting schema settings for already applied migration files.
|
100
|
+
Changing already applied migrations should be avoided because it can lead to the schema getting out of sync
|
101
|
+
between your local copy and what it actually is in production, depending on when `bin/rails db:migrate` was executed.
|
102
|
+
If you want to modify your schema to comply with the cops, you should instead create new migrations.
|
103
|
+
|
64
104
|
## Rails configuration tip
|
65
105
|
|
66
|
-
|
67
|
-
your config/
|
106
|
+
In Rails 6.1+, add the following `config.generators.after_generate` setting to
|
107
|
+
your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.
|
68
108
|
|
69
109
|
```ruby
|
70
|
-
# config/
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
110
|
+
# config/environments/development.rb
|
111
|
+
Rails.application.configure do
|
112
|
+
config.generators.after_generate do |files|
|
113
|
+
parsable_files = files.filter { |file| file.end_with?('.rb') }
|
114
|
+
unless parsable_files.empty?
|
75
115
|
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
|
76
116
|
end
|
77
117
|
end
|
78
118
|
end
|
79
119
|
```
|
80
120
|
|
81
|
-
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe
|
121
|
+
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorrection cops.
|
82
122
|
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
|
83
123
|
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
|
84
124
|
|
125
|
+
In Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:
|
126
|
+
|
127
|
+
```diff
|
128
|
+
# config/environments/development.rb
|
129
|
+
Rails.application.configure do
|
130
|
+
(snip)
|
131
|
+
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
|
132
|
+
- # config.generators.apply_rubocop_autocorrect_after_generate!
|
133
|
+
+ config.generators.apply_rubocop_autocorrect_after_generate!
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
You only need to uncomment.
|
138
|
+
|
85
139
|
## The Cops
|
86
140
|
|
87
141
|
All cops are located under
|
data/config/default.yml
CHANGED
@@ -6,6 +6,7 @@ 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
|
@@ -16,14 +17,18 @@ AllCops:
|
|
16
17
|
# Enable checking Active Support extensions.
|
17
18
|
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
|
18
19
|
ActiveSupportExtensionsEnabled: true
|
19
|
-
# What version of Rails is the inspected code using?
|
20
|
-
# for TargetRailsVersion then it is used.
|
21
|
-
# as a float (
|
22
|
-
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
|
20
|
+
# What version of Rails is the inspected code using? If a value is specified
|
21
|
+
# for `TargetRailsVersion` then it is used. Acceptable values are specified
|
22
|
+
# as a float (e.g., 7.2); the patch version of Rails should not be included.
|
23
|
+
# If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
|
23
24
|
# gems.locked file to find the version of Rails that has been bound to the
|
24
|
-
# application.
|
25
|
+
# application. If neither of those files exist, RuboCop will use Rails 5.0
|
25
26
|
# as the default.
|
26
27
|
TargetRailsVersion: ~
|
28
|
+
# By specifying `MigratedSchemaVersion` option, migration files that have been migrated can be ignored.
|
29
|
+
# When `MigratedSchemaVersion: '20241231000000'` is set. Migration files lower than or equal to '20250101000000' will be ignored.
|
30
|
+
# For example, this is the timestamp in db/migrate/20250101000000_create_articles.rb.
|
31
|
+
MigratedSchemaVersion: '19700101000000' # NOTE: Used as a sentinel value for the UNIX epoch time.
|
27
32
|
|
28
33
|
Lint/NumberConversion:
|
29
34
|
# Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
|
@@ -47,6 +52,45 @@ Lint/NumberConversion:
|
|
47
52
|
- in_milliseconds
|
48
53
|
AllowedPatterns: []
|
49
54
|
|
55
|
+
Lint/RedundantSafeNavigation:
|
56
|
+
# Add `presence` and `present?` methods to the default of the RuboCop core.
|
57
|
+
# https://github.com/rubocop/rubocop/blob/v1.51.0/config/default.yml#L2148-L2159
|
58
|
+
AllowedMethods:
|
59
|
+
- instance_of?
|
60
|
+
- kind_of?
|
61
|
+
- is_a?
|
62
|
+
- eql?
|
63
|
+
- respond_to?
|
64
|
+
- equal?
|
65
|
+
- presence
|
66
|
+
- present?
|
67
|
+
|
68
|
+
Lint/SafeNavigationChain:
|
69
|
+
# Add `presence_in` method to the default of the RuboCop core:
|
70
|
+
# https://github.com/rubocop/rubocop/blob/v1.56.0/config/default.yml#L2265-L2271
|
71
|
+
AllowedMethods:
|
72
|
+
- present?
|
73
|
+
- blank?
|
74
|
+
- presence
|
75
|
+
- presence_in
|
76
|
+
- try
|
77
|
+
- try!
|
78
|
+
- in?
|
79
|
+
|
80
|
+
Lint/UselessAccessModifier:
|
81
|
+
# Add methods from `ActiveSupport::Concern` and `Module::Concerning`:
|
82
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Concern.html
|
83
|
+
# https://api.rubyonrails.org/classes/Module/Concerning
|
84
|
+
inherit_mode:
|
85
|
+
merge:
|
86
|
+
- ContextCreatingMethods
|
87
|
+
ContextCreatingMethods:
|
88
|
+
- class_methods
|
89
|
+
- included
|
90
|
+
- prepended
|
91
|
+
- concern
|
92
|
+
- concerning
|
93
|
+
|
50
94
|
Rails:
|
51
95
|
Enabled: true
|
52
96
|
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
|
@@ -69,8 +113,9 @@ Rails/ActionControllerTestCase:
|
|
69
113
|
|
70
114
|
Rails/ActionFilter:
|
71
115
|
Description: 'Enforces consistent use of action filter methods.'
|
72
|
-
Enabled:
|
116
|
+
Enabled: false
|
73
117
|
VersionAdded: '0.19'
|
118
|
+
VersionChanged: '2.22'
|
74
119
|
EnforcedStyle: action
|
75
120
|
SupportedStyles:
|
76
121
|
- action
|
@@ -138,6 +183,7 @@ Rails/ActiveSupportOnLoad:
|
|
138
183
|
- 'https://guides.rubyonrails.org/engines.html#available-load-hooks'
|
139
184
|
SafeAutoCorrect: false
|
140
185
|
VersionAdded: '2.16'
|
186
|
+
VersionChanged: '2.24'
|
141
187
|
|
142
188
|
Rails/AddColumnIndex:
|
143
189
|
Description: >-
|
@@ -146,8 +192,9 @@ Rails/AddColumnIndex:
|
|
146
192
|
index might be used.
|
147
193
|
Enabled: pending
|
148
194
|
VersionAdded: '2.11'
|
195
|
+
VersionChanged: '2.20'
|
149
196
|
Include:
|
150
|
-
- db
|
197
|
+
- db/**/*.rb
|
151
198
|
|
152
199
|
Rails/AfterCommitOverride:
|
153
200
|
Description: >-
|
@@ -183,7 +230,9 @@ Rails/ApplicationRecord:
|
|
183
230
|
Enabled: true
|
184
231
|
SafeAutoCorrect: false
|
185
232
|
VersionAdded: '0.49'
|
186
|
-
VersionChanged: '2.
|
233
|
+
VersionChanged: '2.26'
|
234
|
+
Exclude:
|
235
|
+
- db/**/*.rb
|
187
236
|
|
188
237
|
Rails/ArelStar:
|
189
238
|
Description: 'Enforces `Arel.star` instead of `"*"` for expanded columns.'
|
@@ -235,12 +284,13 @@ Rails/BulkChangeTable:
|
|
235
284
|
- https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html
|
236
285
|
Enabled: true
|
237
286
|
VersionAdded: '0.57'
|
287
|
+
VersionChanged: '2.20'
|
238
288
|
Database: null
|
239
289
|
SupportedDatabases:
|
240
290
|
- mysql
|
241
291
|
- postgresql
|
242
292
|
Include:
|
243
|
-
- db
|
293
|
+
- db/**/*.rb
|
244
294
|
|
245
295
|
Rails/CompactBlank:
|
246
296
|
Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
|
@@ -270,18 +320,31 @@ Rails/CreateTableWithTimestamps:
|
|
270
320
|
when creating a new table.
|
271
321
|
Enabled: true
|
272
322
|
VersionAdded: '0.52'
|
323
|
+
VersionChanged: '2.20'
|
273
324
|
Include:
|
274
|
-
- db
|
325
|
+
- db/**/*.rb
|
275
326
|
Exclude:
|
276
327
|
# Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
|
328
|
+
# and `*_create_active_storage_variant_records.active_storage.rb`
|
277
329
|
# auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
|
278
|
-
- db
|
330
|
+
- db/**/*_create_active_storage_tables.active_storage.rb
|
331
|
+
- db/**/*_create_active_storage_variant_records.active_storage.rb
|
332
|
+
|
333
|
+
Rails/DangerousColumnNames:
|
334
|
+
Description: >-
|
335
|
+
Avoid dangerous column names.
|
336
|
+
Enabled: pending
|
337
|
+
Severity: warning
|
338
|
+
VersionAdded: '2.21'
|
339
|
+
Include:
|
340
|
+
- 'db/**/*.rb'
|
279
341
|
|
280
342
|
Rails/Date:
|
281
343
|
Description: >-
|
282
344
|
Checks the correct usage of date aware methods,
|
283
345
|
such as Date.today, Date.current etc.
|
284
346
|
Enabled: true
|
347
|
+
SafeAutoCorrect: false
|
285
348
|
VersionAdded: '0.30'
|
286
349
|
VersionChanged: '2.11'
|
287
350
|
# The value `strict` disallows usage of `Date.today`, `Date.current`,
|
@@ -297,7 +360,6 @@ Rails/Date:
|
|
297
360
|
|
298
361
|
Rails/DefaultScope:
|
299
362
|
Description: 'Avoid use of `default_scope`.'
|
300
|
-
StyleGuide: 'https://rails.rubystyle.guide#avoid-default-scope'
|
301
363
|
Enabled: false
|
302
364
|
VersionAdded: '2.7'
|
303
365
|
|
@@ -305,11 +367,13 @@ Rails/Delegate:
|
|
305
367
|
Description: 'Prefer delegate method for delegations.'
|
306
368
|
Enabled: true
|
307
369
|
VersionAdded: '0.21'
|
308
|
-
VersionChanged: '
|
370
|
+
VersionChanged: '2.30'
|
309
371
|
# When set to true, using the target object as a prefix of the
|
310
372
|
# method name without using the `delegate` method will be a
|
311
373
|
# violation. When set to false, this case is legal.
|
312
374
|
EnforceForPrefixed: true
|
375
|
+
Exclude:
|
376
|
+
- app/controllers/**/*.rb
|
313
377
|
|
314
378
|
Rails/DelegateAllowBlank:
|
315
379
|
Description: 'Do not use allow_blank as an option to delegate.'
|
@@ -382,6 +446,14 @@ Rails/EnumHash:
|
|
382
446
|
Include:
|
383
447
|
- app/models/**/*.rb
|
384
448
|
|
449
|
+
Rails/EnumSyntax:
|
450
|
+
Description: 'Use positional arguments over keyword arguments when defining enums.'
|
451
|
+
Enabled: pending
|
452
|
+
Severity: warning
|
453
|
+
VersionAdded: '2.26'
|
454
|
+
Include:
|
455
|
+
- app/models/**/*.rb
|
456
|
+
|
385
457
|
Rails/EnumUniqueness:
|
386
458
|
Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
|
387
459
|
Enabled: true
|
@@ -389,6 +461,11 @@ Rails/EnumUniqueness:
|
|
389
461
|
Include:
|
390
462
|
- app/models/**/*.rb
|
391
463
|
|
464
|
+
Rails/EnvLocal:
|
465
|
+
Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
|
466
|
+
Enabled: pending
|
467
|
+
VersionAdded: '2.22'
|
468
|
+
|
392
469
|
Rails/EnvironmentComparison:
|
393
470
|
Description: "Favor `Rails.env.production?` over `Rails.env == 'production'`."
|
394
471
|
Enabled: true
|
@@ -399,9 +476,10 @@ Rails/EnvironmentVariableAccess:
|
|
399
476
|
# TODO: Set to `pending` status in RuboCop Rails 2 series when migration doc will be written.
|
400
477
|
Enabled: false
|
401
478
|
VersionAdded: '2.10'
|
402
|
-
VersionChanged: '2.
|
479
|
+
VersionChanged: '2.24'
|
403
480
|
Include:
|
404
481
|
- app/**/*.rb
|
482
|
+
- config/initializers/**/*.rb
|
405
483
|
- lib/**/*.rb
|
406
484
|
Exclude:
|
407
485
|
- lib/**/*.rake
|
@@ -443,10 +521,8 @@ Rails/FindBy:
|
|
443
521
|
StyleGuide: 'https://rails.rubystyle.guide#find_by'
|
444
522
|
Enabled: true
|
445
523
|
VersionAdded: '0.30'
|
446
|
-
VersionChanged: '2.
|
524
|
+
VersionChanged: '2.21'
|
447
525
|
IgnoreWhereFirst: true
|
448
|
-
Include:
|
449
|
-
- app/models/**/*.rb
|
450
526
|
|
451
527
|
Rails/FindById:
|
452
528
|
Description: >-
|
@@ -462,9 +538,7 @@ Rails/FindEach:
|
|
462
538
|
Enabled: true
|
463
539
|
Safe: false
|
464
540
|
VersionAdded: '0.30'
|
465
|
-
VersionChanged: '2.
|
466
|
-
Include:
|
467
|
-
- app/models/**/*.rb
|
541
|
+
VersionChanged: '2.21'
|
468
542
|
AllowedMethods:
|
469
543
|
# Methods that don't work well with `find_each`.
|
470
544
|
- order
|
@@ -527,6 +601,10 @@ Rails/I18nLazyLookup:
|
|
527
601
|
Reference: 'https://guides.rubyonrails.org/i18n.html#lazy-lookup'
|
528
602
|
Enabled: pending
|
529
603
|
VersionAdded: '2.14'
|
604
|
+
EnforcedStyle: lazy
|
605
|
+
SupportedStyles:
|
606
|
+
- lazy
|
607
|
+
- explicit
|
530
608
|
Include:
|
531
609
|
- 'app/controllers/**/*.rb'
|
532
610
|
|
@@ -632,8 +710,18 @@ Rails/MigrationClassName:
|
|
632
710
|
Description: 'The class name of the migration should match its file name.'
|
633
711
|
Enabled: pending
|
634
712
|
VersionAdded: '2.14'
|
713
|
+
VersionChanged: '2.20'
|
714
|
+
Include:
|
715
|
+
- db/**/*.rb
|
716
|
+
|
717
|
+
Rails/MultipleRoutePaths:
|
718
|
+
Description: 'Checks for mapping a route with multiple paths, which is deprecated and will be removed in Rails 8.1.'
|
719
|
+
Enabled: pending
|
720
|
+
Severity: warning
|
721
|
+
VersionAdded: '2.29'
|
635
722
|
Include:
|
636
|
-
-
|
723
|
+
- config/routes.rb
|
724
|
+
- config/routes/**/*.rb
|
637
725
|
|
638
726
|
Rails/NegateInclude:
|
639
727
|
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
|
@@ -644,11 +732,15 @@ Rails/NegateInclude:
|
|
644
732
|
VersionChanged: '2.9'
|
645
733
|
|
646
734
|
Rails/NotNullColumn:
|
647
|
-
Description: 'Do not add a NOT NULL column without a default value.'
|
735
|
+
Description: 'Do not add a NOT NULL column without a default value to existing tables.'
|
648
736
|
Enabled: true
|
649
737
|
VersionAdded: '0.43'
|
738
|
+
VersionChanged: '2.20'
|
739
|
+
Database: null
|
740
|
+
SupportedDatabases:
|
741
|
+
- mysql
|
650
742
|
Include:
|
651
|
-
- db
|
743
|
+
- db/**/*.rb
|
652
744
|
|
653
745
|
Rails/OrderById:
|
654
746
|
Description: >-
|
@@ -753,6 +845,16 @@ Rails/ReadWriteAttribute:
|
|
753
845
|
Include:
|
754
846
|
- app/models/**/*.rb
|
755
847
|
|
848
|
+
Rails/RedundantActiveRecordAllMethod:
|
849
|
+
Description: Detect redundant `all` used as a receiver for Active Record query methods.
|
850
|
+
StyleGuide: 'https://rails.rubystyle.guide/#redundant-all'
|
851
|
+
Enabled: pending
|
852
|
+
Safe: false
|
853
|
+
AllowedReceivers:
|
854
|
+
- ActionMailer::Preview
|
855
|
+
- ActiveSupport::TimeZone
|
856
|
+
VersionAdded: '2.21'
|
857
|
+
|
756
858
|
Rails/RedundantAllowNil:
|
757
859
|
Description: >-
|
758
860
|
Finds redundant use of `allow_nil` when `allow_blank` is set to
|
@@ -841,7 +943,7 @@ Rails/RequireDependency:
|
|
841
943
|
VersionAdded: '2.10'
|
842
944
|
|
843
945
|
Rails/ResponseParsedBody:
|
844
|
-
Description: Prefer `response.parsed_body` to `
|
946
|
+
Description: Prefer `response.parsed_body` to custom parsing logic for `response.body`.
|
845
947
|
Enabled: pending
|
846
948
|
Safe: false
|
847
949
|
VersionAdded: '2.18'
|
@@ -933,6 +1035,12 @@ Rails/ScopeArgs:
|
|
933
1035
|
Include:
|
934
1036
|
- app/models/**/*.rb
|
935
1037
|
|
1038
|
+
Rails/SelectMap:
|
1039
|
+
Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
|
1040
|
+
Enabled: pending
|
1041
|
+
Safe: false
|
1042
|
+
VersionAdded: '2.21'
|
1043
|
+
|
936
1044
|
Rails/ShortI18n:
|
937
1045
|
Description: 'Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.'
|
938
1046
|
StyleGuide: 'https://rails.rubystyle.guide/#short-i18n'
|
@@ -949,8 +1057,9 @@ Rails/SkipsModelValidations:
|
|
949
1057
|
See reference for more information.
|
950
1058
|
Reference: 'https://guides.rubyonrails.org/active_record_validations.html#skipping-validations'
|
951
1059
|
Enabled: true
|
1060
|
+
Safe: false
|
952
1061
|
VersionAdded: '0.47'
|
953
|
-
VersionChanged: '2.
|
1062
|
+
VersionChanged: '2.25'
|
954
1063
|
ForbiddenMethods:
|
955
1064
|
- decrement!
|
956
1065
|
- decrement_counter
|
@@ -988,6 +1097,15 @@ Rails/StripHeredoc:
|
|
988
1097
|
Enabled: pending
|
989
1098
|
VersionAdded: '2.15'
|
990
1099
|
|
1100
|
+
Rails/StrongParametersExpect:
|
1101
|
+
Description: 'Enforces the use of `ActionController::Parameters#expect` as a method for strong parameter handling.'
|
1102
|
+
Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
|
1103
|
+
Enabled: pending
|
1104
|
+
Include:
|
1105
|
+
- app/controllers/**/*.rb
|
1106
|
+
SafeAutoCorrect: false
|
1107
|
+
VersionAdded: '2.29'
|
1108
|
+
|
991
1109
|
Rails/TableNameAssignment:
|
992
1110
|
Description: >-
|
993
1111
|
Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
|
@@ -1061,6 +1179,7 @@ Rails/TransactionExitStatement:
|
|
1061
1179
|
- https://github.com/rails/rails/commit/15aa4200e083
|
1062
1180
|
Enabled: pending
|
1063
1181
|
VersionAdded: '2.14'
|
1182
|
+
TransactionMethods: []
|
1064
1183
|
|
1065
1184
|
Rails/UniqBeforePluck:
|
1066
1185
|
Description: 'Prefer the use of uniq or distinct before pluck.'
|
@@ -1093,11 +1212,18 @@ Rails/UnknownEnv:
|
|
1093
1212
|
|
1094
1213
|
Rails/UnusedIgnoredColumns:
|
1095
1214
|
Description: 'Remove a column that does not exist from `ignored_columns`.'
|
1096
|
-
Enabled:
|
1215
|
+
Enabled: false
|
1097
1216
|
VersionAdded: '2.11'
|
1217
|
+
VersionChanged: '2.25'
|
1098
1218
|
Include:
|
1099
1219
|
- app/models/**/*.rb
|
1100
1220
|
|
1221
|
+
Rails/UnusedRenderContent:
|
1222
|
+
Description: 'Do not specify body content for a response with a non-content status code.'
|
1223
|
+
Enabled: pending
|
1224
|
+
Severity: warning
|
1225
|
+
VersionAdded: '2.21'
|
1226
|
+
|
1101
1227
|
Rails/Validation:
|
1102
1228
|
Description: 'Use validates :attribute, hash of validations.'
|
1103
1229
|
Enabled: true
|
@@ -1107,12 +1233,12 @@ Rails/Validation:
|
|
1107
1233
|
- app/models/**/*.rb
|
1108
1234
|
|
1109
1235
|
Rails/WhereEquals:
|
1110
|
-
Description: 'Pass conditions to `where` as a hash instead of manually constructing SQL.'
|
1236
|
+
Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'
|
1111
1237
|
StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
|
1112
1238
|
Enabled: 'pending'
|
1113
1239
|
SafeAutoCorrect: false
|
1114
1240
|
VersionAdded: '2.9'
|
1115
|
-
VersionChanged: '2.
|
1241
|
+
VersionChanged: '2.26'
|
1116
1242
|
|
1117
1243
|
Rails/WhereExists:
|
1118
1244
|
Description: 'Prefer `exists?(...)` over `where(...).exists?`.'
|
@@ -1145,14 +1271,33 @@ Rails/WhereNotWithMultipleConditions:
|
|
1145
1271
|
VersionAdded: '2.17'
|
1146
1272
|
VersionChanged: '2.18'
|
1147
1273
|
|
1274
|
+
Rails/WhereRange:
|
1275
|
+
Description: 'Use ranges in `where` instead of manually constructing SQL.'
|
1276
|
+
StyleGuide: 'https://rails.rubystyle.guide/#where-ranges'
|
1277
|
+
Enabled: pending
|
1278
|
+
SafeAutoCorrect: false
|
1279
|
+
VersionAdded: '2.25'
|
1280
|
+
|
1148
1281
|
# Accept `redirect_to(...) and return` and similar cases.
|
1149
1282
|
Style/AndOr:
|
1150
1283
|
EnforcedStyle: conditionals
|
1151
1284
|
|
1285
|
+
Style/CollectionCompact:
|
1286
|
+
AllowedReceivers:
|
1287
|
+
- params
|
1288
|
+
|
1152
1289
|
Style/FormatStringToken:
|
1153
1290
|
AllowedMethods:
|
1154
1291
|
- redirect
|
1155
1292
|
|
1293
|
+
Style/InvertibleUnlessCondition:
|
1294
|
+
InverseMethods:
|
1295
|
+
# Active Support defines some common inverse methods. They are listed below:
|
1296
|
+
:present?: :blank?
|
1297
|
+
:blank?: :present?
|
1298
|
+
:include?: :exclude?
|
1299
|
+
:exclude?: :include?
|
1300
|
+
|
1156
1301
|
Style/SymbolProc:
|
1157
1302
|
AllowedMethods:
|
1158
1303
|
- define_method
|
@@ -39,7 +39,12 @@ module RuboCop
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def schema
|
42
|
-
RuboCop
|
42
|
+
# For compatibility with RuboCop 1.61.0 or lower.
|
43
|
+
if respond_to?(:parser_engine)
|
44
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, parser_engine)
|
45
|
+
else
|
46
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, :parser_whitequark)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def table_name(class_node)
|
@@ -82,7 +87,7 @@ module RuboCop
|
|
82
87
|
|
83
88
|
options.each_pair.find do |pair|
|
84
89
|
next unless pair.key.sym_type? && pair.key.value == :foreign_key
|
85
|
-
next unless pair.value.
|
90
|
+
next unless pair.value.type?(:sym, :str)
|
86
91
|
|
87
92
|
break pair.value.value.to_s
|
88
93
|
end
|
@@ -98,8 +103,15 @@ module RuboCop
|
|
98
103
|
end
|
99
104
|
|
100
105
|
def in_where?(node)
|
101
|
-
send_node = node.each_ancestor(:
|
102
|
-
|
106
|
+
send_node = node.each_ancestor(:call).first
|
107
|
+
return false unless send_node
|
108
|
+
|
109
|
+
return true if WHERE_METHODS.include?(send_node.method_name)
|
110
|
+
|
111
|
+
receiver = send_node.receiver
|
112
|
+
return false unless receiver&.send_type?
|
113
|
+
|
114
|
+
send_node.method?(:not) && WHERE_METHODS.include?(receiver.method_name)
|
103
115
|
end
|
104
116
|
end
|
105
117
|
end
|