Closed
Description
Expected behavior
I recently updated ruby and rails, not sure what cased me to find this but I think it is a bug anyway. Rails/Output don't like this code below in my migration, which is correct. I think I agree with #175 that this cop should ignore migrations by default but thats a different issue
puts
puts "WARNING: Partially irreversible migration!"
puts
puts "It is not possible to reconstruct the data deleted in this migration."
puts "Reverted the structure, but not the data"
puts
The issue is that the suggestions is this. And this code is accepted.
puts
Rails.logger.debug "WARNING: Partially irreversible migration!"
puts
Rails.logger.debug "It is not possible to reconstruct the data deleted in this migration."
Rails.logger.debug "Reverted the structure, but not the data"
puts
I think this is what should happend
Rails.logger.debug
Rails.logger.debug "WARNING: Partially irreversible migration!"
Rails.logger.debug
Rails.logger.debug "It is not possible to reconstruct the data deleted in this migration."
Rails.logger.debug "Reverted the structure, but not the data"
Rails.logger.debug
Actual behavior
This code is accepted but should be
puts
Rails.logger.debug "WARNING: Partially irreversible migration!"
puts
Rails.logger.debug "It is not possible to reconstruct the data deleted in this migration."
Rails.logger.debug "Reverted the structure, but not the data"
puts
Steps to reproduce the problem
I coded the repo from master at sha fd69f79 and wrote a failing spec. It might not be the correct place for this
diff --git a/spec/rubocop/cop/rails/output_spec.rb b/spec/rubocop/cop/rails/output_spec.rb
index ce501f840..d11548b69 100644
--- a/spec/rubocop/cop/rails/output_spec.rb
+++ b/spec/rubocop/cop/rails/output_spec.rb
@@ -23,6 +23,17 @@ RSpec.describe RuboCop::Cop::Rails::Output, :config do
RUBY
end
+ it 'registers and corrects an offense for using `puts` method without a receiver' do
+ expect_offense(<<~RUBY)
+ puts
+ ^^^^ Do not write to stdout. Use Rails's logger if you want to log.
+ RUBY
+
+ expect_correction(<<~RUBY)
+ Rails.logger.debug
+ RUBY
+ end
+
it 'registers and corrects an offense for using `print` method without a receiver' do
expect_offense(<<~RUBY)
print "abbe busoni"
RuboCop version
cloned at fd69f79 and had a failing spec
Activity