-
-
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
[WIP] New cop Rails/SafeNavigationOperator
#2545
Conversation
Checks for the use of `#try` and instead encourages changing it to Ruby 2.3's safe navigation operator - `*.`. The cop is enabled by default. E.g ```ruby obj.try! :id obj&.id ```
context "with method #{method}" do | ||
context 'and with a receiver' do | ||
it 'registers an offense for an invocation with args' do | ||
inspect_source(cop, "obj.#{method}! :id") |
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 !
should not be here.
# Checks for use of `#try` or `#try!`. | ||
class SafeNavigationOperator < Cop | ||
MSG = 'Prefer `&.` over `ActiveSupport#try!`.' | ||
INVALID_METHODS = [:try!] |
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'd call this TARGET_METHODS and freeze the array.
@syndbg ping |
One more thing - the new cop should make use of the functionality @alexdowad just added about target Ruby versions. |
I'll close this for now. Feel free to reopen it if you make any progress with it. |
@syndbg any plans to work on this soon or should I pick it up? |
Addresses
#2428
Changes
Checks for the use of
#try
and instead encourageschanging it to Ruby 2.3's safe navigation operator -
*.
.The cop is enabled by default.
E.g
Features (TODOs):
#try!
.#try!
methods to&.
.#try
.#try
.