Closed
Description
The Rails/Blank cop autocorrects item.nil? || item.empty?
to item.blank?
, even with the 'safe' autocorrect mode (i.e., rubocop -a
). However, a string consisting of just spaces is considered blank but not empty by Rails, which means this autocorrect causes a change in behavior.
Expected behavior
Given a file in Rails containing the line
item.nil? || item.empty?
When running rubocop -a
, RuboCop should not autocorrect this to item.blank?
.
Actual behavior
RuboCorrect the code to item.blank?
Steps to reproduce the problem
This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.
- Create a file
foo.rb
containing:
# frozen_string_literal: true
def foo(item)
item.nil? || item.empty?
end
- Create a file
.rubocop.yml
containing:
require:
- rubocop-rails
AllCops:
NewCops: enable
Rails:
Enabled: true
Run rubocop -a
. The file foo.rb will have been changed as described above.
RuboCop version
$ rubocop -V
1.11.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 3.0.0 x86_64-linux)
- rubocop-rails 2.9.1
Metadata
Metadata
Assignees
Labels
No labels
Activity