-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
[Fix #912] Enhance Rails/Delegate
by adding delegation detection for self.class
, constants, class variables, global variables, and instance variables
#1438
Conversation
2d0f730
to
f2e3803
Compare
@inst_obj.foo | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
delegate :foo, to: :@inst_obj |
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.
That's my two cents. Can you tweak the example? e.g.,
@inst_obj.foo | |
end | |
RUBY | |
expect_correction(<<~RUBY) | |
delegate :foo, to: :@inst_obj | |
@instance_variable.foo | |
end | |
RUBY | |
expect_correction(<<~RUBY) | |
delegate :foo, to: :@instance_variable |
@@cls_obj.foo | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
delegate :foo, to: :@@cls_obj |
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.
@@cls_obj.foo | |
end | |
RUBY | |
expect_correction(<<~RUBY) | |
delegate :foo, to: :@@cls_obj | |
@@class_variable.foo | |
end | |
RUBY | |
expect_correction(<<~RUBY) | |
delegate :foo, to: :@@class_variable |
It's a corner case, but wouldn't it be possible to apply the same handling to global variables as well? |
I'm not sure if Rails delegate supports it because I couldn't find an example of it in the official documentation. |
This is the behavior in Rails 8.0.1. For your reference. $ bin/rails -v
Rails 8.0.1
$ cat /tmp/x.rb
class X
def foo
puts 'hi'
end
end
$global_variable = X.new
class Y
delegate :foo, to: :$global_variable
end
Y.new.foo
$ bin/rails r /tmp/x.rb
hi |
f2e3803
to
a228e9c
Compare
Thank you, I've fixed it. |
@@ -0,0 +1 @@ | |||
* [#912](https://github.com/rubocop/rubocop-rails/issues/912): Enhance `Rails/Delegate` by adding delegation detection for `self.class`, constants, instance variables, and class variables. ([@ydakuka][]) |
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 add a mention of global variables?
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.
P.S. I got a failed test that is not related to this PR.
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 issue was fixed in f9adec0. There's no problem with this PR. Thank you!
46cf5a2
to
3d2f8bf
Compare
…tion for `self.class`, constants, instance variables, and class variables
3d2f8bf
to
23e2098
Compare
Thanks! |
Rails/Delegate
by adding delegation detection for self.class
, constants, instance variables, and class variablesRails/Delegate
by adding delegation detection for self.class
, constants, class variables, global variables, and instance variables
Fix #912
[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.