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
I would have assumed that the ordering of a comparison would be irrelevant to rubocop. Apparently this is wrong in at least this case.
In addition, I would assume that negative comparisons would also be caught.
Expected behavior
Rails.env == 'development' Rails.env != 'development' 'development' == Rails.env 'development' != Rails.env
Should all be detected by this Cop
Actual behavior
Only Rails.env == 'development' is recognized by this Cop.
Steps to reproduce the problem
Testfile.rb
# All Bad examples
# Recognized
if Rails.env == 'development'
puts 'test1'
end
if Rails.env != 'development'
puts 'test2'
end
if 'development' == Rails.env
puts 'test3'
end
if 'development' != Rails.env
puts 'test4'
end
puts 'test5' if 'development' == Rails.env
# Recognized
puts 'test6' if Rails.env == 'development'
puts 'test7' if 'development' != Rails.env
puts 'test8' if Rails.env != 'development'
rubocop testfile.rb
Only test 1 and test 6 are flagged by rubocop as needing correction.
… comparisons
Fixesrubocop#193.
This PR makes `Rails/EnvironmentComparison` aware of the following
comparisons:
- When `Rails.env` is used on RHS
- When `!=` is used to compare with `Rails.env`
… comparisons
Fixesrubocop#193.
This PR makes `Rails/EnvironmentComparison` aware of the following
comparisons:
- When `Rails.env` is used on RHS
- When `!=` is used to compare with `Rails.env`
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Feb 4, 2020
… comparisons
Fixesrubocop#193.
This PR makes `Rails/EnvironmentComparison` aware of the following
comparisons:
- When `Rails.env` is used on RHS
- When `!=` is used to compare with `Rails.env`
I would have assumed that the ordering of a comparison would be irrelevant to rubocop. Apparently this is wrong in at least this case.
In addition, I would assume that negative comparisons would also be caught.
Expected behavior
Rails.env == 'development'
Rails.env != 'development'
'development' == Rails.env
'development' != Rails.env
Should all be detected by this Cop
Actual behavior
Only
Rails.env == 'development'
is recognized by this Cop.Steps to reproduce the problem
Testfile.rb
rubocop testfile.rb
RuboCop version
Tested on:
Rubocop version: 0.79
Rubocop-rails version: 2.4.1
Rubocop-performance version: 1.5.2
Ruby version: 2.5.5
Rails version: 4.2.11.1
The text was updated successfully, but these errors were encountered: