rubocop-rails 2.15.2 → 2.37.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/LICENSE.txt +1 -1
- data/README.md +84 -9
- data/config/default.yml +417 -82
- data/config/obsoletion.yml +10 -0
- data/lib/rubocop/cop/mixin/active_record_helper.rb +19 -10
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +3 -5
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +66 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +7 -2
- data/lib/rubocop/cop/mixin/index_method.rb +73 -71
- data/lib/rubocop/cop/mixin/migrations_helper.rb +1 -1
- data/lib/rubocop/cop/mixin/routes_helper.rb +20 -0
- data/lib/rubocop/cop/mixin/target_rails_version.rb +17 -2
- data/lib/rubocop/cop/mixin.rb +17 -0
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +116 -0
- data/lib/rubocop/cop/rails/action_controller_test_case.rb +4 -4
- data/lib/rubocop/cop/rails/action_filter.rb +4 -1
- data/lib/rubocop/cop/rails/action_order.rb +112 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +5 -6
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +3 -4
- data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
- data/lib/rubocop/cop/rails/active_support_aliases.rb +6 -5
- data/lib/rubocop/cop/rails/active_support_on_load.rb +90 -0
- data/lib/rubocop/cop/rails/add_column_index.rb +3 -5
- data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
- data/lib/rubocop/cop/rails/application_controller.rb +2 -3
- data/lib/rubocop/cop/rails/application_job.rb +3 -4
- data/lib/rubocop/cop/rails/application_mailer.rb +2 -3
- data/lib/rubocop/cop/rails/application_record.rb +6 -3
- data/lib/rubocop/cop/rails/arel_star.rb +6 -6
- data/lib/rubocop/cop/rails/assert_not.rb +1 -2
- data/lib/rubocop/cop/rails/attribute_default_block_value.rb +9 -0
- data/lib/rubocop/cop/rails/belongs_to.rb +2 -5
- data/lib/rubocop/cop/rails/blank.rb +7 -8
- data/lib/rubocop/cop/rails/bulk_change_table.rb +26 -69
- data/lib/rubocop/cop/rails/compact_blank.rb +34 -9
- data/lib/rubocop/cop/rails/content_tag.rb +7 -8
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +16 -3
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +447 -0
- data/lib/rubocop/cop/rails/date.rb +18 -14
- data/lib/rubocop/cop/rails/delegate.rb +71 -14
- 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/duplicate_association.rb +71 -10
- data/lib/rubocop/cop/rails/duplicate_scope.rb +2 -2
- data/lib/rubocop/cop/rails/duration_arithmetic.rb +3 -3
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +28 -16
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +9 -7
- 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 +30 -11
- data/lib/rubocop/cop/rails/env.rb +70 -0
- data/lib/rubocop/cop/rails/env_local.rb +93 -0
- data/lib/rubocop/cop/rails/environment_comparison.rb +56 -49
- data/lib/rubocop/cop/rails/exit.rb +7 -4
- data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
- data/lib/rubocop/cop/rails/file_path.rb +214 -32
- data/lib/rubocop/cop/rails/find_by.rb +4 -4
- data/lib/rubocop/cop/rails/find_by_id.rb +11 -25
- data/lib/rubocop/cop/rails/find_by_or_assignment_memoization.rb +124 -0
- 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 +5 -7
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +17 -18
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +35 -11
- data/lib/rubocop/cop/rails/http_status.rb +22 -16
- data/lib/rubocop/cop/rails/http_status_name_consistency.rb +80 -0
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +65 -13
- data/lib/rubocop/cop/rails/i18n_locale_texts.rb +29 -3
- data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +24 -13
- data/lib/rubocop/cop/rails/index_by.rb +38 -13
- data/lib/rubocop/cop/rails/index_with.rb +43 -13
- data/lib/rubocop/cop/rails/inquiry.rb +2 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +9 -9
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +38 -23
- data/lib/rubocop/cop/rails/link_to_blank.rb +3 -6
- data/lib/rubocop/cop/rails/mailer_name.rb +4 -4
- data/lib/rubocop/cop/rails/match_route.rb +1 -9
- data/lib/rubocop/cop/rails/migration_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/multiple_route_paths.rb +50 -0
- data/lib/rubocop/cop/rails/negate_include.rb +1 -1
- data/lib/rubocop/cop/rails/not_null_column.rb +108 -9
- data/lib/rubocop/cop/rails/order_arguments.rb +84 -0
- data/lib/rubocop/cop/rails/output.rb +8 -8
- data/lib/rubocop/cop/rails/output_safety.rb +8 -2
- data/lib/rubocop/cop/rails/pick.rb +10 -5
- data/lib/rubocop/cop/rails/pluck.rb +73 -13
- data/lib/rubocop/cop/rails/pluck_id.rb +3 -2
- data/lib/rubocop/cop/rails/pluck_in_where.rb +35 -13
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +30 -17
- data/lib/rubocop/cop/rails/presence.rb +94 -29
- data/lib/rubocop/cop/rails/present.rb +9 -14
- data/lib/rubocop/cop/rails/rake_environment.rb +23 -7
- data/lib/rubocop/cop/rails/read_write_attribute.rb +2 -2
- data/lib/rubocop/cop/rails/redirect_back_or_to.rb +98 -0
- data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +190 -0
- 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 +21 -5
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +34 -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 +5 -8
- data/lib/rubocop/cop/rails/render_plain_text.rb +6 -3
- data/lib/rubocop/cop/rails/request_referer.rb +2 -3
- data/lib/rubocop/cop/rails/require_dependency.rb +1 -1
- data/lib/rubocop/cop/rails/response_parsed_body.rb +108 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +28 -65
- 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 +281 -0
- data/lib/rubocop/cop/rails/safe_navigation.rb +34 -6
- data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -3
- data/lib/rubocop/cop/rails/save_bang.rb +42 -39
- data/lib/rubocop/cop/rails/schema_comment.rb +18 -11
- data/lib/rubocop/cop/rails/select_map.rb +100 -0
- data/lib/rubocop/cop/rails/short_i18n.rb +2 -5
- data/lib/rubocop/cop/rails/skips_model_validations.rb +11 -7
- data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +10 -8
- data/lib/rubocop/cop/rails/strip_heredoc.rb +1 -1
- data/lib/rubocop/cop/rails/strong_parameters_expect.rb +212 -0
- data/lib/rubocop/cop/rails/three_state_boolean_column.rb +72 -0
- data/lib/rubocop/cop/rails/time_zone.rb +54 -35
- 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 +42 -10
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +11 -29
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +25 -22
- data/lib/rubocop/cop/rails/unknown_env.rb +40 -11
- data/lib/rubocop/cop/rails/unused_ignored_columns.rb +12 -1
- data/lib/rubocop/cop/rails/unused_render_content.rb +67 -0
- data/lib/rubocop/cop/rails/validation.rb +13 -16
- data/lib/rubocop/cop/rails/where_equals.rb +29 -13
- data/lib/rubocop/cop/rails/where_exists.rb +14 -14
- data/lib/rubocop/cop/rails/where_missing.rb +121 -0
- data/lib/rubocop/cop/rails/where_not.rb +18 -12
- data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
- data/lib/rubocop/cop/rails/where_range.rb +202 -0
- data/lib/rubocop/cop/rails.rb +152 -0
- data/lib/rubocop/cop/rails_cops.rb +4 -120
- data/lib/rubocop/rails/migration_file_skippable.rb +50 -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 +30 -3
- metadata +74 -13
- data/bin/console +0 -11
- data/bin/setup +0 -7
- 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: 9258d56d31fc4adeef0526b551dbe652abe70dd4599debc25ee39be54b743330
|
|
4
|
+
data.tar.gz: ab2d60fe9b2a61ac47f8f15f8753fb60dd26e278d5452d23501f59a398fd7b0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ba4c487f87fdbd58130ba06fc0184c9c5b5dabe5ee3934aa03930c27467072a7f89ac77ba423fe89f69ad9739c2dfcbeac1bb947e64804757e6efbdb47b47a5
|
|
7
|
+
data.tar.gz: 223e0693edfd7de08b9d6a770fbdd7ced5c6422cab60d5074657ef65dd7b4ce538c8f61c37cc15156d63824e1d4060a654bca1fef7830d1b587e7ca84d516f62
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
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
|
|
|
12
13
|
Just install the `rubocop-rails` gem
|
|
13
14
|
|
|
14
15
|
```sh
|
|
15
|
-
gem install rubocop-rails
|
|
16
|
+
$ gem install rubocop-rails
|
|
16
17
|
```
|
|
17
18
|
|
|
18
19
|
or if you use bundler put this in your `Gemfile`
|
|
@@ -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,22 +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'
|
|
65
|
+
end
|
|
66
|
+
```
|
|
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
|
+
|
|
104
|
+
## Rails configuration tip
|
|
105
|
+
|
|
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`.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
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?
|
|
115
|
+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
61
118
|
end
|
|
62
119
|
```
|
|
63
120
|
|
|
121
|
+
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorrection cops.
|
|
122
|
+
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
|
|
123
|
+
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
|
|
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
|
+
|
|
64
139
|
## The Cops
|
|
65
140
|
|
|
66
141
|
All cops are located under
|