Skip to content

Commit

Permalink
[UnusedArgument] Ignore forward arguments (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
nipe0324 authored Mar 26, 2022
1 parent 5768265 commit b381b48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/rubocop/cop/graphql/unused_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ class UnusedArgument < Base

def on_class(node)
resolve_method_node = find_resolve_method_node(node)
return if resolve_method_node.nil? ||
resolve_method_node.arguments.any? do |arg|
arg.arg_type? || arg.kwrestarg_type?
end
return if resolve_method_node.nil? || ignore_arguments_type?(resolve_method_node)

declared_arg_nodes = find_declared_arg_nodes(node)
return unless declared_arg_nodes.any?
Expand Down Expand Up @@ -109,6 +106,12 @@ def find_unresolved_args(method_node, declared_arg_nodes)
end
end

def ignore_arguments_type?(resolve_method_node)
resolve_method_node.arguments.any? do |arg|
arg.arg_type? || arg.kwrestarg_type? || arg.forward_arg_type?
end
end

def register_offense(node, unresolved_args)
unresolved_args_source = unresolved_args.map { |v| "#{v}:" }.join(", ")

Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/graphql/unused_argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ def resolve(arg1:, arg2:, user:, cards:, article:, notes:); end
end
end

context "when args is forwarding arguments" do
let(:ruby_version) { 2.7 } # forward arguments was introduced in Ruby 2.7

it "does not registers an offense" do
expect_no_offenses(<<~RUBY)
class SomeResolver < Resolvers::Base
argument :arg1, String, required: true
argument :arg2, String, required: true
def resolve(...); end
end
RUBY
end
end

context "when resolve method belongs to a different class" do
it "does not register an offence" do
expect_no_offenses(<<~RUBY)
Expand Down

0 comments on commit b381b48

Please sign in to comment.