From 1d7cb0d8cc62d446cef83fa27d1c903b0005ee86 Mon Sep 17 00:00:00 2001 From: Matt Bessey Date: Wed, 3 Mar 2021 23:21:10 +0000 Subject: [PATCH] ExtractInputType: show all excess args in offense 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. --- lib/rubocop/cop/graphql/extract_input_type.rb | 7 ++++++- spec/rubocop/cop/graphql/extract_input_type_spec.rb | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/graphql/extract_input_type.rb b/lib/rubocop/cop/graphql/extract_input_type.rb index 3c54848..247ae33 100644 --- a/lib/rubocop/cop/graphql/extract_input_type.rb +++ b/lib/rubocop/cop/graphql/extract_input_type.rb @@ -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 diff --git a/spec/rubocop/cop/graphql/extract_input_type_spec.rb b/spec/rubocop/cop/graphql/extract_input_type_spec.rb index 0a6ba72..653d788 100644 --- a/spec/rubocop/cop/graphql/extract_input_type_spec.rb +++ b/spec/rubocop/cop/graphql/extract_input_type_spec.rb @@ -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