Skip to content

Commit

Permalink
[Fix rubocop#3034] Register an offense in SpaceAfterNot for condition…
Browse files Browse the repository at this point in the history
…s using parentheses
  • Loading branch information
rrosenblum authored and Neodelf committed Oct 15, 2016
1 parent 0f1eec3 commit b4a6176
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [#3010](https://github.com/bbatsov/rubocop/issues/3010): Fix double reporting/correction of spaces after ternary operator colons (now only reported by `Style/SpaceAroundOperators`, and not `Style/SpaceAfterColon` too). ([@owst][])
* [#3006](https://github.com/bbatsov/rubocop/issues/3006): Register an offense for calling `merge!` on a method on a variable inside `each_with_object` in `Performance/RedundantMerge`. ([@lumeet][], [@rrosenblum][])
* [#2886](https://github.com/bbatsov/rubocop/issues/2886): Custom cop changes now bust the cache. ([@ptarjan][])
* [#3043](https://github.com/bbatsov/rubocop/issues/3043): `Style/SpaceAfterNot` will now register an offense for a receiver that is wrapped in parentheses. ([@rrosenblum][])

### Changes

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/space_after_not.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class SpaceAfterNot < Cop
MSG = 'Do not leave space between `!` and its argument.'.freeze

def on_send(node)
_receiver, method_name, *_args = *node
receiver, method_name, *_args = *node

return unless method_name == :!
return unless node.source =~ /^!\s+\w+/
return unless receiver.loc.column - node.loc.column > 1

# TODO: Improve source range to highlight the redundant whitespace.
add_offense(node, :selector)
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/space_after_not_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
expect(cop.offenses).to be_empty
end

it 'reports an offense for space after ! with the negated receiver ' \
'wrapped in parentheses' do
inspect_source(cop, '! (model)')
expect(cop.offenses.size).to eq(1)
end

it 'auto-corrects by removing redundant space' do
new_source = autocorrect_source(cop, '! something')
expect(new_source).to eq('!something')
Expand Down

0 comments on commit b4a6176

Please sign in to comment.