diff --git a/lib/rubocop/cop/style/redundant_argument.rb b/lib/rubocop/cop/style/redundant_argument.rb index 70eebce4dd2..778b4ef6b85 100644 --- a/lib/rubocop/cop/style/redundant_argument.rb +++ b/lib/rubocop/cop/style/redundant_argument.rb @@ -58,8 +58,11 @@ def on_send(node) return if node.arguments.count != 1 return unless redundant_argument?(node) - add_offense(node, message: format(MSG, arg: node.arguments.first.source)) do |corrector| - corrector.remove(argument_range(node)) + offense_range = argument_range(node) + message = format(MSG, arg: node.arguments.first.source) + + add_offense(offense_range, message: message) do |corrector| + corrector.remove(offense_range) end end diff --git a/spec/rubocop/cop/style/redundant_argument_spec.rb b/spec/rubocop/cop/style/redundant_argument_spec.rb index 83a42cea90b..528f0ec55df 100644 --- a/spec/rubocop/cop/style/redundant_argument_spec.rb +++ b/spec/rubocop/cop/style/redundant_argument_spec.rb @@ -8,13 +8,13 @@ it 'registers an offense and corrects when method called on variable' do expect_offense(<<~'RUBY') foo.join('') - ^^^^^^^^^^^^ Argument '' is redundant because it is implied by default. + ^^^^ Argument '' is redundant because it is implied by default. foo.split(' ') - ^^^^^^^^^^^^^^ Argument ' ' is redundant because it is implied by default. + ^^^^^ Argument ' ' is redundant because it is implied by default. foo.chomp("\n") - ^^^^^^^^^^^^^^^ Argument "\n" is redundant because it is implied by default. + ^^^^^^ Argument "\n" is redundant because it is implied by default. foo.chomp!("\n") - ^^^^^^^^^^^^^^^^ Argument "\n" is redundant because it is implied by default. + ^^^^^^ Argument "\n" is redundant because it is implied by default. RUBY expect_correction(<<~RUBY) @@ -28,9 +28,9 @@ it 'registers an offense and corrects when method called without parenthesis on variable' do expect_offense(<<~RUBY) foo.join '' - ^^^^^^^^^^^ Argument '' is redundant because it is implied by default. + ^^^ Argument '' is redundant because it is implied by default. foo.split ' ' - ^^^^^^^^^^^^^ Argument ' ' is redundant because it is implied by default. + ^^^^ Argument ' ' is redundant because it is implied by default. RUBY expect_correction(<<~RUBY) @@ -42,9 +42,9 @@ it 'registers an offense and corrects when method called on literals' do expect_offense(<<~RUBY) [1, 2, 3].join('') - ^^^^^^^^^^^^^^^^^^ Argument '' is redundant because it is implied by default. + ^^^^ Argument '' is redundant because it is implied by default. "first second".split(' ') - ^^^^^^^^^^^^^^^^^^^^^^^^^ Argument ' ' is redundant because it is implied by default. + ^^^^^ Argument ' ' is redundant because it is implied by default. RUBY expect_correction(<<~RUBY) @@ -56,7 +56,7 @@ it 'registers an offense and corrects when method called without parenthesis on literals' do expect_offense(<<~RUBY) [1, 2, 3].join '' - ^^^^^^^^^^^^^^^^^ Argument '' is redundant because it is implied by default. + ^^^ Argument '' is redundant because it is implied by default. RUBY expect_correction(<<~RUBY) @@ -67,9 +67,9 @@ it 'works with double-quoted strings when configuration is single-quotes' do expect_offense(<<~RUBY) foo.join("") - ^^^^^^^^^^^^ Argument "" is redundant because it is implied by default. + ^^^^ Argument "" is redundant because it is implied by default. "first second".split(" ") - ^^^^^^^^^^^^^^^^^^^^^^^^^ Argument " " is redundant because it is implied by default. + ^^^^^ Argument " " is redundant because it is implied by default. RUBY expect_correction(<<~RUBY) @@ -112,7 +112,7 @@ it 'registers an offense and corrects with configured argument' do expect_offense(<<~RUBY) A.foo(2) - ^^^^^^^^ Argument 2 is redundant because it is implied by default. + ^^^ Argument 2 is redundant because it is implied by default. RUBY expect_correction(<<~RUBY)