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 |
# File 'lib/rubocop/cop/graphql/ordered_arguments.rb', line 60 def on_class(node) # Do a single pass over descendants to get argument declarations # with and without a block. argument_declarations = argument_declaration(node).map do |declaration| if argument_declaration_with_block?(declaration) declaration.parent else declaration end 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 |