Skip to content

Commit 3691414

Browse files
committed
[Doc] Prevent unintended auto-correct with after_generate
Some `rails generators` may not generate `*.rb`. (e.g. `bin/rails g stimulus`) In this case, `parsable_files` is empty, so RuboCop will parse all files. This behavior is not intended, so it fixes the doc.
1 parent a3711eb commit 3691414

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ module YourCoolApp
7272
class Application < Rails::Application
7373
config.generators.after_generate do |files|
7474
parsable_files = files.filter { |file| file.end_with?('.rb') }
75-
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
75+
unless parsable_files.empty?
76+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
77+
end
7678
end
7779
end
7880
end

docs/modules/ROOT/pages/usage.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ module YourCoolApp
4242
class Application < Rails::Application
4343
config.generators.after_generate do |files|
4444
parsable_files = files.filter { |file| file.end_with?('.rb') }
45-
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
45+
unless parsable_files.empty?
46+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
47+
end
4648
end
4749
end
4850
end

0 commit comments

Comments
 (0)