Skip to content

Commit

Permalink
Suppress RuboCop output when there are no offenses in code generation
Browse files Browse the repository at this point in the history
Follow up rails#51782.

> But it's overkill for the default case where people use the default style guide,
> and it introduces both delay and console output as a cost.

When there are no offenses with the coding style generated by code generation,
outputting RuboCop results to the console was redundant.
Since RuboCop has `--format=quiet` option that suppresses console output
when there are no offenses, this PR adds that option:
https://docs.rubocop.org/rubocop/1.63/formatters.html#quiet-formatter

While this PR doesn't resolve any added execution speed by RuboCop,
the frequency of using the generator is not high within the development flow.
Therefore, depending on the execution speed, it might be possible to uncomment rails#51782,
but this PR respects the defaults in rails#51782 and doesn't address that.
  • Loading branch information
koic committed May 13, 2024
1 parent dae4867 commit 6afc368
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion railties/lib/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def apply_rubocop_autocorrect_after_generate!
after_generate do |files|
parsable_files = files.filter { |file| File.exist?(file) && file.end_with?(".rb") }
unless parsable_files.empty?
system(RbConfig.ruby, "bin/rubocop", "-A", "--fail-level=E", *parsable_files, exception: true)
system(RbConfig.ruby, "bin/rubocop", "-A", "--fail-level=E", "--format=quiet", *parsable_files, exception: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion railties/test/application/generators_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def check_expected
end

output = rails("generate", "model", "post", "title:string", "body:string")
assert_match(/3 files inspected, no offenses detected/, output)
assert_no_match(/3 files inspected, no offenses detected/, output)
end

test "generators with apply_rubocop_autocorrect_after_generate! and pretend" do
Expand Down

0 comments on commit 6afc368

Please sign in to comment.