Skip to content

Commit

Permalink
[Fix #2248] Allow AutoResourceCleanup block-pass
Browse files Browse the repository at this point in the history
Accept `File.open('file', &:read)` in `Style/AutoResourceCleanup`.
  • Loading branch information
lumeet committed Sep 15, 2015
1 parent e6561af commit e929a91
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* [#2121](https://github.com/bbatsov/rubocop/issues/2121): Allow space before values in hash literals in `Style/ExtraSpacing` to avoid correction conflict. ([@jonas054][])
* [#2241](https://github.com/bbatsov/rubocop/issues/2241): Read cache in binary format. ([@jonas054][])

### Changes

* [#2248](https://github.com/bbatsov/rubocop/issues/2248): Allow block-pass in `Style/AutoResourceCleanup`. ([@lumeet][])

## 0.34.1 (09/09/2015)

### Bug Fixes
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/auto_resource_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class AutoResourceCleanup < Cop
]

def on_send(node)
receiver_node, method_name, *_arg_nodes = *node
receiver_node, method_name, *arg_nodes = *node

TARGET_METHODS.each do |(target_class, target_method)|
target_receiver = s(:const, nil, target_class)

next if receiver_node != target_receiver
next if method_name != target_method
next if node.parent && node.parent.block_type?
next if !arg_nodes.empty? && arg_nodes.last.block_pass_type?

add_offense(node,
:expression,
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/auto_resource_cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@

expect(cop.offenses).to be_empty
end

it 'does not register an offense for File.open with block-pass' do
inspect_source(cop, 'File.open("file", &:read)')

expect(cop.offenses).to be_empty
end
end

0 comments on commit e929a91

Please sign in to comment.