Skip to content

Commit

Permalink
Merge pull request #8328 from fatkodima/fix-space_around_method_call_…
Browse files Browse the repository at this point in the history
…operator-cop

Fix crash for `Layout/SpaceAroundMethodCallOperator` when using `Proc#call` shorthand syntax
  • Loading branch information
koic committed Jul 13, 2020
2 parents 804c8e6 + 131fc06 commit a500463
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#8324](https://github.com/rubocop-hq/rubocop/issues/8324): Fix crash for `Layout/SpaceAroundMethodCallOperator` when using `Proc#call` shorthand syntax. ([@fatkodima][])

## 0.88.0 (2020-07-13)

### New features
Expand Down
10 changes: 9 additions & 1 deletion lib/rubocop/cop/layout/space_around_method_call_operator.rb
Expand Up @@ -66,7 +66,15 @@ def check_space_before_dot(node)

def check_space_after_dot(node)
dot_pos = node.loc.dot.end_pos
selector_pos = node.loc.selector.begin_pos

selector_pos =
# `Proc#call` shorthand syntax
if node.method?(:call) && !node.loc.selector
node.loc.begin.begin_pos
else
node.loc.selector.begin_pos
end

check_space(dot_pos, selector_pos)
end

Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/layout/space_around_method_call_operator_spec.rb
Expand Up @@ -69,6 +69,16 @@
foo.bar
CORRECTION

include_examples 'offense', 'spaces after `Proc#call` shorthand call',
<<-CODE, <<-OFFENSE, <<-CORRECTION
foo. ()
CODE
foo. ()
^ Avoid using spaces around a method call operator.
OFFENSE
foo.()
CORRECTION

context 'when multi line method call' do
include_examples 'offense', 'space before method call',
<<-CODE, <<-OFFENSE, <<-CORRECTION
Expand Down

0 comments on commit a500463

Please sign in to comment.