Skip to content

Commit

Permalink
[Fix rubocop#2331] Do not register an offense for count with an argum…
Browse files Browse the repository at this point in the history
…ent in Performance/Size
  • Loading branch information
rrosenblum committed Oct 23, 2015
1 parent 0740c43 commit bb5c09e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [#2324](https://github.com/bbatsov/rubocop/issues/2324): Handle `--only Lint/Syntax` and `--except Lint/Syntax` correctly. ([@jonas054][])
* [#2317](https://github.com/bbatsov/rubocop/issues/2317): Handle `case` as an argument correctly in `Lint/EndAlignment`. ([@lumeet][])
* [#2287](https://github.com/bbatsov/rubocop/issues/2287): Fix auto-correct of lines with only whitespace in `Style/IndentationWidth`. ([@lumeet][])
* [#2331](https://github.com/bbatsov/rubocop/issues/2331): Do not register an offense in `Performance/Size` for `count` with an argument. ([@rrosenblum][])

## 0.34.2 (21/09/2015)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def on_send(node)
return unless method == :count
return unless array?(receiver) || hash?(receiver)
return if node.parent && node.parent.block_type?
return if args && args.block_pass_type?
return if args

add_offense(node, node.loc.selector)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/performance/size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
expect(cop.offenses).to be_empty
end

it 'does not register an offense when calling count with an argument' do
inspect_source(cop, '[1, 2, 3].count(1)')

expect(cop.offenses).to be_empty
end

it 'corrects count to size' do
new_source = autocorrect_source(cop, '[1, 2, 3].count')

Expand Down Expand Up @@ -124,6 +130,12 @@
expect(cop.offenses).to be_empty
end

it 'does not register an offense when calling count with an argument' do
inspect_source(cop, '{a: 1, b: 2, c: 3}.count(1)')

expect(cop.offenses).to be_empty
end

it 'corrects count to size' do
new_source = autocorrect_source(cop, '{a: 1, b: 2, c: 3}.count')

Expand Down

0 comments on commit bb5c09e

Please sign in to comment.