Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UnusedArgument] Ignore arguments defined in a nested class #71

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/rubocop/cop/graphql/unused_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def on_class(node)
arg.arg_type? || arg.kwrestarg_type?
end

declared_arg_nodes = argument_declarations(node)
declared_arg_nodes = find_declared_arg_nodes(node)
return unless declared_arg_nodes.any?

unresolved_args = find_unresolved_args(resolve_method_node, declared_arg_nodes)
Expand All @@ -81,6 +81,13 @@ def on_class(node)

private

def find_declared_arg_nodes(node)
argument_declarations(node).select do |arg_declaration|
# argument is declared on the same class that is being analyzed
arg_declaration.each_ancestor(:class).first == node
end
end

def find_resolve_method_node(node)
resolve_method_nodes = resolve_method_definition(node)
resolve_method_nodes.to_a.last if resolve_method_nodes.any?
Expand Down
7 changes: 6 additions & 1 deletion spec/rubocop/cop/graphql/unused_argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
it "not registers an offense" do
expect_no_offenses(<<~RUBY)
class SomeResolver < Resolvers::Base
class Input < GraphQL::Schema::InputObject
argument :arg4, String, required: true
end

argument :arg1, String, required: true
argument :arg2, String, required: false
argunent :arg3, Input, required: true

def resolve(arg1:, arg2: "hey"); end
def resolve(arg1:, arg2: "hey", arg3:); end
end
RUBY
end
Expand Down