From 653379ec94b7281678018ea5f5ec5eaa09a963f4 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 27 Apr 2019 00:57:06 +0900 Subject: [PATCH] [Fix #6974] Make `Layout/FirstMethodArgumentLineBreak` aware of calling using `super` Fixes #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 ``` --- CHANGELOG.md | 1 + .../cop/layout/first_method_argument_line_break.rb | 1 + .../first_method_argument_line_break_spec.rb | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6022538e101..98a766a0c55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/layout/first_method_argument_line_break.rb b/lib/rubocop/cop/layout/first_method_argument_line_break.rb index 62b931c0527..776363f66ed 100644 --- a/lib/rubocop/cop/layout/first_method_argument_line_break.rb +++ b/lib/rubocop/cop/layout/first_method_argument_line_break.rb @@ -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) diff --git a/spec/rubocop/cop/layout/first_method_argument_line_break_spec.rb b/spec/rubocop/cop/layout/first_method_argument_line_break_spec.rb index d26e9aff7eb..2594ee6173f 100644 --- a/spec/rubocop/cop/layout/first_method_argument_line_break_spec.rb +++ b/spec/rubocop/cop/layout/first_method_argument_line_break_spec.rb @@ -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)