Skip to content

Commit

Permalink
Merge pull request #945 from cschramm/space_before_first_arg
Browse files Browse the repository at this point in the history
Fix SpaceBeforeFirstArg cop for multiline arguments
  • Loading branch information
bbatsov committed Apr 4, 2014
2 parents f5ae10e + d390652 commit 2ba0c08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#953](https://github.com/bbatsov/rubocop/pull/953): Fix auto-correction bug in `NonNilCheck`. ([@bbatsov][])
* [#952](https://github.com/bbatsov/rubocop/pull/952): Handle implicit receiver in `StringConversionInInterpolation`. ([@bbatsov][])
* [#956](https://github.com/bbatsov/rubocop/pull/956): Apply `ClassMethods` check only on `class`/`module` bodies. ([@bbatsov][])
* [#945](https://github.com/bbatsov/rubocop/issues/945): Fix SpaceBeforeFirstArg cop for multiline argument and exclude assignments. ([@cschramm][])

## 0.20.0 (02/04/2014)

Expand Down Expand Up @@ -842,3 +843,4 @@
[@hiroponz]: https://github.com/hiroponz
[@tamird]: https://github.com/tamird
[@fshowalter]: https://github.com/fshowalter
[@cschramm]: https://github.com/cschramm
3 changes: 2 additions & 1 deletion lib/rubocop/cop/lint/space_before_first_arg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def on_send(node)
_receiver, method_name, *args = *node
return if args.empty?
return if operator?(method_name)
return if method_name.to_s.end_with?('=')

# Setter calls with parentheses are parsed this way. The parentheses
# belong to the argument, not the send node.
Expand All @@ -28,7 +29,7 @@ def on_send(node)
arg1 = args.first.loc.expression
arg1_with_space = range_with_surrounding_space(arg1, :left)

add_offense(nil, arg1) if arg1_with_space.source =~ /^\S/
add_offense(nil, arg1) if arg1_with_space.source =~ /\A\S/
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/lint/space_before_first_arg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
inspect_source(cop, ['something[:x]'])
expect(cop.offenses).to be_empty
end

it 'accepts a method call with space before a multiline arg' do
inspect_source(cop, "something [\n 'foo',\n 'bar'\n]")
expect(cop.offenses).to be_empty
end

it 'accepts an assignment without space before first arg' do
inspect_source(cop, ['a.something=c', 'a.something,b=c,d'])
expect(cop.offenses).to be_empty
end
end

context 'for method calls with parentheses' do
Expand Down

0 comments on commit 2ba0c08

Please sign in to comment.