-
-
Notifications
You must be signed in to change notification settings - Fork 279
[Fix #1228] Enhance Rails/SaveBang
to properly handle instance variables
#1421
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 #1228] Enhance Rails/SaveBang
to properly handle instance variables
#1421
Conversation
lib/rubocop/cop/rails/save_bang.rb
Outdated
assignment = assignable_node(node).parent | ||
assignment&.lvasgn_type? | ||
|
||
assignment&.ivasgn_type? || assignment&.lvasgn_type? |
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 refactor to the following?
diff --git a/lib/rubocop/cop/rails/save_bang.rb b/lib/rubocop/cop/rails/save_bang.rb
index 2729c762c..b60598a4e 100644
--- a/lib/rubocop/cop/rails/save_bang.rb
+++ b/lib/rubocop/cop/rails/save_bang.rb
@@ -328,9 +328,9 @@ module RuboCop
end
def return_value_assigned?(node)
- assignment = assignable_node(node).parent
+ return false unless (assignment = assignable_node(node).parent)
- assignment&.ivasgn_type? || assignment&.lvasgn_type?
+ assignment.ivasgn_type? || assignment.lvasgn_type?
end
def persist_method?(node, methods = RESTRICT_ON_SEND)
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
7487f40
to
5030b42
Compare
Can you add a changelog entry file? |
lib/rubocop/cop/rails/save_bang.rb
Outdated
assignment&.lvasgn_type? | ||
return false unless (assignment = assignable_node(node).parent) | ||
|
||
assignment.ivasgn_type? || assignment.lvasgn_type? |
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.
Could it be that it’s not limited solely to adding instance variables?
assignment.ivasgn_type? || assignment.lvasgn_type? | |
assignment.assignment? |
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
5cb703b
to
bf0dc58
Compare
@@ -0,0 +1 @@ | |||
* [#1228](https://github.com/rubocop/rubocop-rails/issues/1228): Enhance `Rails/SaveBang` to properly handle instance 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.
This file is missing the .md
extension and I think it will not be picked up by the changelog generator because of that
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.
Oops, fixed.
bf0dc58
to
48233de
Compare
Thanks! |
Fix #1228
[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.