Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnvironmentComparison does not recognize other equality comparisons #193

Closed
matthewhively opened this issue Jan 24, 2020 · 0 comments · Fixed by #196
Closed

EnvironmentComparison does not recognize other equality comparisons #193

matthewhively opened this issue Jan 24, 2020 · 0 comments · Fixed by #196
Labels
enhancement New feature or request

Comments

@matthewhively
Copy link

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.

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

@koic koic added the enhancement New feature or request label Jan 25, 2020
koic added a commit to koic/rubocop-rails that referenced this issue Feb 3, 2020
… comparisons

Fixes rubocop#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

Fixes rubocop#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

Fixes rubocop#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 koic closed this as completed in #196 Feb 9, 2020
koic added a commit that referenced this issue Feb 9, 2020
…f_comparisons

[Fix #193] Make `Rails/EnvironmentComparison` aware of several comparisons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants