Skip to content

Commit

Permalink
[Fix rubocop#6974] Make Layout/FirstMethodArgumentLineBreak aware o…
Browse files Browse the repository at this point in the history
…f calling using `super`

Fixes rubocop#6974.

This PR makes `Layout/FirstMethodArgumentLineBreak` aware of calling using `super`.

```ruby
# example.rb
super(:foo,
  :bar
  )
```

## Before

```console
% rubocop --only Layout/FirstMethodArgumentLineBreak
Inspecting 1 file
.

1 file inspected, no offenses detected
```

## After

```console
% rubocop --only Layout/FirstMethodArgumentLineBreak
Inspecting 1 file
C

Offenses:

example.rb:1:7: C: Layout/FirstMethodArgumentLineBreak: Add a line break
before the first argument of a multi-line method argument list.
super(:foo,
      ^^^^

1 file inspected, 1 offense detected
```
  • Loading branch information
koic committed Apr 26, 2019
1 parent 971328e commit 653379e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* Add new `Layout/HeredocArgumentClosingParenthesis` cop. ([@maxh][])
* [#6895](https://github.com/rubocop-hq/rubocop/pull/6895): Add support for XDG config home for user-config. ([@Mange][], [@tejasbubane][])
* Add initial autocorrection support to `Metrics/LineLength`. ([@maxh][])
* [#6974](https://github.com/rubocop-hq/rubocop/issues/6974): Make `Layout/FirstMethodArgumentLineBreak` aware of calling using `super`. ([@koic][])

### Bug fixes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/layout/first_method_argument_line_break.rb
Expand Up @@ -44,6 +44,7 @@ def on_send(node)
check_method_line_break(node, args)
end
alias on_csend on_send
alias on_super on_send

def autocorrect(node)
EmptyLineCorrector.insert_before(node)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/layout/first_method_argument_line_break_spec.rb
Expand Up @@ -25,6 +25,20 @@
RUBY
end

it 'detects the offense when using `super`' do
expect_offense(<<-RUBY.strip_indent)
super(bar,
^^^ Add a line break before the first argument of a multi-line method argument list.
baz)
RUBY

expect_correction(<<-RUBY.strip_indent)
super(
bar,
baz)
RUBY
end

context 'when using safe navigation operator', :ruby23 do
it 'detects the offense' do
expect_offense(<<-RUBY.strip_indent)
Expand Down

0 comments on commit 653379e

Please sign in to comment.