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/UnknownEnv support Rails.env.local? by default for Rails 7.1 #893

Closed
yahonda opened this issue Dec 22, 2022 · 5 comments · Fixed by #894
Closed

Rails/UnknownEnv support Rails.env.local? by default for Rails 7.1 #893

yahonda opened this issue Dec 22, 2022 · 5 comments · Fixed by #894
Labels
feature request Request for new functionality

Comments

@yahonda
Copy link

yahonda commented Dec 22, 2022

Is your feature request related to a problem? Please describe.

rails/rails#46786 has been merged to Rails main.
When this feature is released in Rails 7.1, I prefer Rails/UnknownEnv cop allows Rails.env.local? by default.

Describe the solution you'd like

Rails/UnknownEnv cop allows Rails.env.local? by default for Rails 7.1.

Describe alternatives you've considered

Update .rubocop.yml manually as rubocop/rubocop#4956 (comment) does.

Rails/UnknownEnv:
  Environments:
    - production
    - development
    - test
    - local

Additional context

It may be a little bit early to open this feature request because Rails 7.1 is not released.

@yahonda
Copy link
Author

yahonda commented Dec 22, 2022

Here are the steps to reproduce.

git clone https://github.com/yahonda/sampleapp.git
cd sampleapp
bundle
bundle exec rubocop
$ bundle exec rubocop
Inspecting 31 files
.........C.....................

Offenses:

app/models/user.rb:2:16: C: Rails/UnknownEnv: Unknown environment local.
  if Rails.env.local?
               ^^^^^^

31 files inspected, 1 offense detected
$

How Rails.env.local? works.

$ bin/rails c
Loading development environment (Rails 7.1.0.alpha)
irb(main):001:0> Rails.env.local?
=> true
irb(main):002:0> Rails.env
=> "development"
irb(main):003:0>

@yahonda
Copy link
Author

yahonda commented Dec 22, 2022

FYI

Rails.env.local? is a kind of syntax sugar for Rails.env.development? || Rails.env.test?

$ RAILS_ENV=test bin/rails c
Loading test environment (Rails 7.1.0.alpha)
irb(main):001:0> Rails.env.local?
=> true
irb(main):002:0> Rails.env
=> "test"
irb(main):003:0> exit
$ RAILS_ENV=production bin/rails c
Loading production environment (Rails 7.1.0.alpha)
irb(main):001:0> Rails.env.local?
=> false
irb(main):002:0> Rails.env
=> "production"
irb(main):003:0> exit
$

@andyw8
Copy link
Contributor

andyw8 commented Dec 22, 2022

(I think you meant to write Rails.env.local? above).

@yahonda
Copy link
Author

yahonda commented Dec 23, 2022

Right. updated the previous comment.

ghiculescu added a commit to ghiculescu/rubocop-rails that referenced this issue Dec 23, 2022
ghiculescu added a commit to ghiculescu/rubocop-rails that referenced this issue Dec 23, 2022
@ghiculescu
Copy link
Contributor

#894

ghiculescu added a commit to ghiculescu/rubocop-rails that referenced this issue Dec 23, 2022
sambostock added a commit to sambostock/rubocop-rails that referenced this issue Jan 6, 2023
ghiculescu added a commit to ghiculescu/rubocop-rails that referenced this issue Jan 6, 2023
ghiculescu added a commit to ghiculescu/rubocop-rails that referenced this issue Jan 6, 2023
@koic koic added the feature request Request for new functionality label Mar 29, 2023
@koic koic closed this as completed in #894 Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants