Skip to content

Commit

Permalink
ExtractInputType: show all excess args in offense
Browse files Browse the repository at this point in the history
I believe this makes it clearer what is wrong when introducing the cop to an existing code base, where a mutation may already have an excess of arguments.

Otherwise, you delete an argument, the errors moves up a line, and so on until you get below MaxArguments.
  • Loading branch information
bessey authored and Matt Bessey committed Apr 7, 2021
1 parent 22590d6 commit 1d7cb0d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rubocop/cop/graphql/extract_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def on_class(node)
if (body = schema_member.body)
arguments = body.select { |node| argument?(node) }

add_offense(arguments.last) if arguments.count > cop_config["MaxArguments"]
excess_arguments = arguments.count - cop_config["MaxArguments"]
return unless excess_arguments.positive?

arguments.last(excess_arguments).each do |excess_argument|
add_offense(excess_argument)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/rubocop/cop/graphql/extract_input_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UpdateUser < BaseMutation
argument :uuid, ID, required: true
argument :first_name, String, required: true
argument :last_name, String, required: true
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Consider moving arguments to a new input type
argument :email, String, required: true
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Consider moving arguments to a new input type
end
Expand Down

0 comments on commit 1d7cb0d

Please sign in to comment.