Skip to content

Commit 38cec18

Browse files
committed
[Doc] Sync the Rails configuration tip with the README
1 parent 5dc42d5 commit 38cec18

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

docs/modules/ROOT/pages/usage.adoc

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ end
3333

3434
== Rails configuration tip
3535

36-
If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
37-
your config/application.rb to apply RuboCop autocorrection to code generated by `bin/rails g`.
36+
In Rails 6.1+, add the following `config.generators.after_generate` setting to
37+
your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.
3838

3939
[source,ruby]
4040
----
41-
module YourCoolApp
42-
class Application < Rails::Application
43-
config.generators.after_generate do |files|
44-
parsable_files = files.filter { |file| File.exist?(file) && file.end_with?('.rb') }
45-
unless parsable_files.empty?
46-
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
47-
end
41+
# config/environments/development.rb
42+
Rails.application.configure do
43+
config.generators.after_generate do |files|
44+
parsable_files = files.filter { |file| file.end_with?('.rb') }
45+
unless parsable_files.empty?
46+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
4847
end
4948
end
5049
end
@@ -53,3 +52,18 @@ end
5352
It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorrection cops.
5453
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
5554
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
55+
56+
In Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:
57+
58+
[source,diff]
59+
----
60+
# config/environments/development.rb
61+
Rails.application.configure do
62+
(snip)
63+
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
64+
- # config.generators.apply_rubocop_autocorrect_after_generate!
65+
+ config.generators.apply_rubocop_autocorrect_after_generate!
66+
end
67+
----
68+
69+
You only need to uncomment.

0 commit comments

Comments
 (0)