Skip to content

Commit

Permalink
[Fix rubocop#1123] Setter calls in safe assignment
Browse files Browse the repository at this point in the history
Support if (a.b = x).
  • Loading branch information
jonas054 committed May 30, 2014
1 parent aa0d0b4 commit 2241b9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [#1111](https://github.com/bbatsov/rubocop/issues/1111): Fix problem in `EndOfLine` with reading non-UTF-8 encoded files. ([@jonas054][])
* [#1115](https://github.com/bbatsov/rubocop/issues/1115): Fix `Next` to ignore super nodes. ([@geniou][])
* [#1117](https://github.com/bbatsov/rubocop/issues/1117): Don't auto-correct indentation in scopes that contain block comments (`=begin`..`=end`). ([@jonas054][])
* [#1123](https://github.com/bbatsov/rubocop/pull/1123): Support setter calls in safe assignment in `ParenthesesAroundCondition`. ([@jonas054][])

## 0.22.0 (20/04/2014)

Expand Down
15 changes: 13 additions & 2 deletions lib/rubocop/cop/mixin/safe_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ module Cop
# assignment as a condition. It's not a mistake."
module SafeAssignment
def safe_assignment?(node)
node.type == :begin && node.children.size == 1 &&
Util::EQUALS_ASGN_NODES.include?(node.children[0].type)
return false unless node.type == :begin
return false unless node.children.size == 1

child = node.children.first
case child.type
when *Util::EQUALS_ASGN_NODES
true
when :send
_receiver, method_name, _args = *child
method_name.to_s.end_with?('=')
else
false
end
end

def safe_assignment_allowed?
Expand Down

0 comments on commit 2241b9b

Please sign in to comment.