You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Fixes #rubocop#444.
This PR marks `Rails/Blank` as unsafe auto-correction because `' '.empty?` returns false,
but `' '.blank?` returns true. Therefore, auto-correction is not compatible if receiver is
a non-empty blank string, tab, or newline meta characters.
The Rails/Blank cop autocorrects
item.nil? || item.empty?
toitem.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
When running
rubocop -a
, RuboCop should not autocorrect this toitem.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.
foo.rb
containing:.rubocop.yml
containing:Run
rubocop -a
. The file foo.rb will have been changed as described above.RuboCop version
The text was updated successfully, but these errors were encountered: