-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
False positive in Style/TrivialAccessors with inline private #5641
Comments
You can still define private readers using private
attr_reader :foo although not using the new inline syntax. |
I don't think it is a false positive for the same reason as the @Drenmi comment. BTW, maybe we can add an option to ignore this case, i.e. this cop ignores |
…def` with `private` See rubocop#5641 This cop should not auto-correct `private def foo() @foo end`. Because `def foo() @foo end` returns `:foo`, but `attr_reader :foo` returns `nil`. The `autocorrect` method checks only the parent is a `send` type. It does not check method name. Because the cop also should handle methods other than `private`, `public`, `protected`. For example, [finalist](https://github.com/joker1007/finalist) gem defines `final` method (`final def foo; end`). Note === This pull-request does not close the related issue since the issue still has an problem if the auto-correction is fixed. I think we should discuss the cop should have or not an option to ignore `private def foo() @foo end` on the issue.
…th `private` (#5691) See #5641 This cop should not auto-correct `private def foo() @foo end`. Because `def foo() @foo end` returns `:foo`, but `attr_reader :foo` returns `nil`. The `autocorrect` method checks only the parent is a `send` type. It does not check method name. Because the cop also should handle methods other than `private`, `public`, `protected`. For example, [finalist](https://github.com/joker1007/finalist) gem defines `final` method (`final def foo; end`). Note === This pull-request does not close the related issue since the issue still has an problem if the auto-correction is fixed. I think we should discuss the cop should have or not an option to ignore `private def foo() @foo end` on the issue.
Agreed. Thanks for fixing this! |
Fixed in 0.54. Can we close this? |
Expected behavior
Not an offense. In this case,
private
/protected
clause needs symbol returned fromdef
butattr_reader
returns nil, which causes TypeError.Actual behavior
Steps to reproduce the problem
Described in actual behavour.
RuboCop version
The text was updated successfully, but these errors were encountered: