-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add Rails/EnvLocal
cop to enforce upcoming Rails.env.local?
#906
Conversation
1004ce3
to
6b4cbc2
Compare
Oh, I see #894 uses an alternative approach to add support for
As I type this, I realize maybe the tradeoff in #894 is actually just best addressed by me making this cop have a configurable enforced style ( |
6b4cbc2
to
e259391
Compare
Rails.env.local?
Rails/EnvLocal
cop to enforce upcoming Rails.env.local?
e259391
to
0d71906
Compare
I've updated the PR as follows:
|
lib/rubocop/cop/rails/env_local.rb
Outdated
# Rails.env.local? | ||
# | ||
# # good | ||
# Rails.env.development? || Rails.env.test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EnforcedStyle: no_local
option looks unnecessary. So, it would be sufficient to provide only the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My justification was that authors may prefer to be explicit (or perhaps they need to support an old Rails version, in the case of a gem author) and not want to use local?
. Normally this would be covered by updating the UnknownEnv
config, except that #894's implementation always injects it in if the target Rails version is >= 7.1.
However, if you think that's too obscure, I can certainly remove the EnforcedStyle
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not generally downgraded supported version of Rails. If user don't want to replace with this Rails.env.local?
, just can disable this cop. So I think it would be better to remove this EnforcedStyle: no_local
and keep it simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
0d71906
to
095d8ac
Compare
This looks good. However, Rails 7.1 is a development version yet. So, the new cop merge is pending until at least a beta, preferably a release candidate is shipped. |
Please open a PR only for c856fa1 if you like. Rails 7.1 development has started, so it can be merged independently. |
@sambostock #1134 was merged. Can you rebase with the latest master branch? |
095d8ac
to
3b894ec
Compare
Enforces the use of `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`, as of Rails 7.1.
3b894ec
to
e0cb140
Compare
|
||
def on_or(node) | ||
rails_env_local_candidate?(node) do |*environments| | ||
next unless environments.to_set == LOCAL_ENVIRONMENTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you resolve the following offense?
https://app.circleci.com/pipelines/github/rubocop/rubocop-rails/2710/workflows/7b3e5571-a8f9-460f-8fef-eecf228283e3/jobs/18160
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! You're too fast for me! 😅
Thanks! |
rails/rails#46786 introduces
Rails.env.local?
as a helper forRails.env.development? || Rails.env.test?
, which should be released as part of the next Rails release (presumably 7.1, although possible 8).This PR includes the following to support this:
:rails71
shared context so specs can be written against Rails 7.1ChangeRails/UnknownEnv
default config to addlocal
Removed in favour of Support
local
as an environment forRails/UnknownEnv
from Rails 7.1 onward. #894Rails/EnvLocal
cop to enforce use ofRails.env.local?
when applicableEnforcedStyle: no_local
to disallowRails.env.local?
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.Good idea!