Skip to content

Commit

Permalink
Refine offense highlight range for Style/RedundantArgument
Browse files Browse the repository at this point in the history
This commit refines offense highlight range for `Style/RedundantArgument`.
  • Loading branch information
koic committed Sep 30, 2021
1 parent efcf741 commit 1bed3ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions lib/rubocop/cop/style/redundant_argument.rb
Expand Up @@ -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

Expand Down
24 changes: 12 additions & 12 deletions spec/rubocop/cop/style/redundant_argument_spec.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1bed3ec

Please sign in to comment.