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
Is your feature request related to a problem? Please describe.
I'm using Ruby 2.7 in my Rails application and I know there is Style/HashExcept cop which is useful where we can use Hash#except.
Hash#except was originally provided as a core extension to activesupport, and then it was ported to Ruby, right? Since Hash#except is already available for environments like Rails apps, I would really like to take advantage of this cop, regardless of the Ruby version.
So the question is, is there any good way to enable RuboCop to enable this cop in such case?
Describe the solution you'd like
I think the best way for users is that this cop is disabled by default, but can be enabled by writing the following setting:
Style/HashExcept:
Enabled: true
though I understand that from an internal implementation point of view, that would be a bit of a challenge.
Describe alternatives you've considered
Monkey-patching minimum_target_ruby_version will work, so I'm doing this for now 😇
In this issue, I am targeting Style/HashExcept for example, but I think this kind of problem can actually occur in other cops. I hope some good way is provided in such cases.
The real problem we are having is that we are trying to upgrade Ruby from 2.7 to 3.0, but when we try to upgrade it to Ruby 3.0, Style/HashExcept starts reporting offenses. Well, we can temporarily disable this cop, but ideally we don't want to do that, right? Also we don't want to make changes about Hash#except at the same time with Ruby upgrade, if possible, because the diff would be larger and then the risk of conflict would be greater.
Besides Hash#except, I am sure there are other cases where, for example, you want to backport a new feature from new Ruby or Rails version and enable cop for this feature in advance in order to make upgrading easier. Another example is the deprecation of to_fs in Rails 7. That required a large change to our codebase, so we backported that feature in Rails 6.1, and then we had to monkey-patch Rails/ToSWithArgument cop on minimum_target_rails_version 7.0. I wish we had the ability to force enable it in this situation as well.
The text was updated successfully, but these errors were encountered:
… 2.x
Fixesrubocop#790.
This PR makes `Style/HashExcept` aware of TargetRubyVersion: 2.x
because Rails has `Hash#except`.
So Ruby version is irrelevant when used in Rails.
Since Rails has Hash#except, I think it makes sense for Rails to always support it and opened #791. On the other hand, the Rails/ToSWithArgument backpoting is about monkey patching. I think application monkey patching should be solved on the application side, not framework and follower side.
Is your feature request related to a problem? Please describe.
I'm using Ruby 2.7 in my Rails application and I know there is
Style/HashExcept
cop which is useful where we can useHash#except
.Hash#except
was originally provided as a core extension to activesupport, and then it was ported to Ruby, right? SinceHash#except
is already available for environments like Rails apps, I would really like to take advantage of this cop, regardless of the Ruby version.So the question is, is there any good way to enable RuboCop to enable this cop in such case?
Describe the solution you'd like
I think the best way for users is that this cop is disabled by default, but can be enabled by writing the following setting:
though I understand that from an internal implementation point of view, that would be a bit of a challenge.
Describe alternatives you've considered
Monkey-patching
minimum_target_ruby_version
will work, so I'm doing this for now 😇Additional context
In this issue, I am targeting
Style/HashExcept
for example, but I think this kind of problem can actually occur in other cops. I hope some good way is provided in such cases.The real problem we are having is that we are trying to upgrade Ruby from 2.7 to 3.0, but when we try to upgrade it to Ruby 3.0,
Style/HashExcept
starts reporting offenses. Well, we can temporarily disable this cop, but ideally we don't want to do that, right? Also we don't want to make changes aboutHash#except
at the same time with Ruby upgrade, if possible, because the diff would be larger and then the risk of conflict would be greater.Besides
Hash#except
, I am sure there are other cases where, for example, you want to backport a new feature from new Ruby or Rails version and enable cop for this feature in advance in order to make upgrading easier. Another example is the deprecation ofto_fs
in Rails 7. That required a large change to our codebase, so we backported that feature in Rails 6.1, and then we had to monkey-patchRails/ToSWithArgument
cop onminimum_target_rails_version 7.0
. I wish we had the ability to force enable it in this situation as well.The text was updated successfully, but these errors were encountered: