Class: RuboCop::Cop::Gusto::Graphql::IdFieldArgumentDescription
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Gusto::Graphql::IdFieldArgumentDescription
- Includes:
- IdDescriptionConcerns
- Defined in:
- lib/rubocop/cop/gusto/graphql/id_field_argument_description.rb
Overview
Ensures ID type arguments on query fields follow the standardized description template:
"The identifier of the <ObjectName.fieldName>) to filter by"
"The identifiers of each <ObjectName.fieldName>) to filter by" (for arrays)
This cop only applies to arguments on regular GraphQL objects/queries, NOT on mutations or input objects (see IdInputArgumentDescription for those).
Constant Summary collapse
- MSG =
"ID argument description should match template: " \ "'The identifier of the <ObjectName> (`<ObjectName.fieldName>`) to filter by'."
- RESTRICT_ON_SEND =
i(argument).freeze
- TYPE_REF =
A single "
( <ObjectName.fieldName>)" reference. Multiple may be joined with " or " for arguments that accept an id from more than one entity. /\w+ \(`\w+\.\w+`\)/- SINGLE_PATTERN =
Single: "The identifier of the
( <ObjectName.fieldName>) to filter by" /\AThe identifier of the #{TYPE_REF}(?: or #{TYPE_REF})* to filter by/- ARRAY_PATTERN =
Array: "The identifiers of each
( <ObjectName.fieldName>) to filter by" /\AThe identifiers of each #{TYPE_REF}(?: or #{TYPE_REF})* to filter by/
Constants included from IdDescriptionConcerns
RuboCop::Cop::Gusto::Graphql::IdDescriptionConcerns::ARGUMENT_CALL_PATTERN, RuboCop::Cop::Gusto::Graphql::IdDescriptionConcerns::FIELD_CALL_PATTERN, RuboCop::Cop::Gusto::Graphql::IdDescriptionConcerns::MUTATION_OR_INPUT_BASE_SUFFIXES, RuboCop::Cop::Gusto::Graphql::IdDescriptionConcerns::PRIMARY_ID_FIELDS
Instance Method Summary collapse
Methods included from IdDescriptionConcerns
Instance Method Details
#on_send(node) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubocop/cop/gusto/graphql/id_field_argument_description.rb', line 41 def on_send(node) # Skip if we're in a mutation or input object context because there's another cop for that return if in_mutation_or_input_object?(node) argument_call?(node) do |_name, type_node| is_array = array_id_type?(type_node) return unless id_type?(type_node) || is_array desc = extract_description(node) return if desc.nil? # No description - let other cops handle missing descriptions return if valid_argument_description?(desc, is_array) add_offense(node) end end |