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

Rails/EnvironmentComparison does not recognize case statements #1395

Open
maxjacobson opened this issue Dec 13, 2024 · 0 comments
Open

Rails/EnvironmentComparison does not recognize case statements #1395

maxjacobson opened this issue Dec 13, 2024 · 0 comments

Comments

@maxjacobson
Copy link
Contributor

I've gotten accustomed to preferring if Rails.env.production? over if Rails.env == 'production' as a result of following the Rails/EnvironmentComparison rule. I noticed recently that code like this is still permissible:

case Rails.env
when "production"
  foo
else
  bar
end

This seems to violate the spirit of the rule, and also like it could be detected with static analysis.

Similarly, case statements that use pattern matching are also permitted:

case Rails.env
in "production"
  foo
in "test" | "development"
  bar
end

Perhaps this should also trigger an offense. What do you think?

Expected behavior

The examples above ought to produce Rails/EnvironmentComparison offenses.

Perhaps they could also be corrected to the equivalent if ... else ... end statements, but if they produced offenses that would be a good start.

Actual behavior

The examples above do not produce offenses.

Steps to reproduce the problem

Write code such as the above and run rubocop.

RuboCop version

1.69.1 (using Parser 3.3.6.0, rubocop-ast 1.36.2, analyzing as Ruby 3.3, running on ruby 3.3.6) [arm64-darwin24]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-graphql 1.5.4
  - rubocop-rails 2.27.0
  - rubocop-rspec 3.2.0
  - rubocop-rspec_rails 2.30.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant