Class: RuboCop::Cop::GraphQL::OrderedArguments
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::GraphQL::OrderedArguments
- Extended by:
- AutoCorrector
- Includes:
- GraphQL::CompareOrder, GraphQL::SwapRange
- Defined in:
- lib/rubocop/cop/graphql/ordered_arguments.rb
Overview
Arguments should be alphabetically sorted within groups.
Constant Summary collapse
- MSG =
"Arguments should be sorted in an alphabetical order within their section. " \ "Field `%<current>s` should appear before `%<previous>s`."
Instance Method Summary collapse
Methods included from GraphQL::CompareOrder
Methods included from GraphQL::SwapRange
#declaration, #final_end_location, #swap_range
Instance Method Details
#on_class(node) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubocop/cop/graphql/ordered_arguments.rb', line 60 def on_class(node) declarations_with_blocks = argument_declarations_with_blocks(node) declarations_without_blocks = argument_declarations_without_blocks(node) argument_declarations = declarations_without_blocks.map do |node| arg_name = argument_name(node) same_arg_with_block_declaration = declarations_with_blocks.find do |dec| argument_name(dec) == arg_name end same_arg_with_block_declaration || node end argument_declarations.each_cons(2) do |previous, current| next unless consecutive_lines(previous, current) next if correct_order?(argument_name(previous), argument_name(current)) register_offense(previous, current) end end |