Skip to content

Commit

Permalink
Use first_argument instead of first_argument_range
Browse files Browse the repository at this point in the history
The standard `first_argument` method is simpler.
And this commit removes private API `first_argument_range`.
  • Loading branch information
koic committed Mar 28, 2023
1 parent 18e39e9 commit e970d41
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/refute_equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def on_send(node)
corrector.replace(node.loc.selector, 'refute_equal')

replacement = [expected, actual].map(&:source).join(', ')
corrector.replace(first_argument_range(node), replacement)
corrector.replace(node.first_argument, replacement)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/refute_false.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def autocorrect(corrector, node, actual)
if node.method?(:assert_equal)
corrector.replace(first_and_second_arguments_range(node), actual.source)
else
corrector.replace(first_argument_range(node), actual.source)
corrector.replace(node.first_argument, actual.source)
end
end
end
Expand Down
6 changes: 0 additions & 6 deletions lib/rubocop/cop/mixin/argument_range_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ module ArgumentRangeHelper

private

def first_argument_range(node)
first_argument = node.first_argument

range_between(first_argument.source_range.begin_pos, first_argument.source_range.end_pos)
end

def first_and_second_arguments_range(node)
first_argument = node.first_argument
second_argument = node.arguments[1]
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/minitest_cop_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def autocorrect(corrector, node, arguments)
new_arguments = '(' + new_arguments + ')'
end
corrector.replace(first_argument_range(node), new_arguments)
corrector.replace(node.first_argument, new_arguments)
end
private
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/predicate_assertion_handleable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def autocorrect(corrector, node, arguments)

new_arguments = new_arguments(arguments).join(', ')

corrector.replace(first_argument_range(node), new_arguments)
corrector.replace(node.first_argument, new_arguments)
end

private
Expand Down

0 comments on commit e970d41

Please sign in to comment.