Skip to content

Commit

Permalink
ExtractInputType: show all excess args in offense (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bessey authored Apr 8, 2021
1 parent 22590d6 commit 2c1a3e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion spec/rubocop/cop/graphql/extract_input_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class UpdateUser < BaseMutation
end

context "when count of fields is more than Max fields" do
it "registers an offense" do
it "registers an offense for each line over Max fields" do
expect_offense(<<~RUBY)
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 2c1a3e0

Please sign in to comment.