Class: RuboCop::Cop::Gusto::Graphql::IdFieldDescription

Inherits:
Base
  • Object
show all
Includes:
IdDescriptionConcerns
Defined in:
lib/rubocop/cop/gusto/graphql/id_field_description.rb

Overview

Ensures ID type fields follow the standardized description template: "The identifier"

This applies to fields named :id or :uuid with type ID.

Examples:

Bad

field :id, ID, 'Unique identifier', null: false
field :id, ID, null: false, description: 'The unique identifier'

Good

field :id, ID, 'The Employee identifier', null: false
field :id, ID, null: false, description: 'The Employee identifier'

Constant Summary collapse

MSG =
"ID field description should match template: 'The <ObjectName> identifier'."
RESTRICT_ON_SEND =
i(field).freeze

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

#argument_call?, #field_call?

Instance Method Details

#on_send(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/gusto/graphql/id_field_description.rb', line 29

def on_send(node)
  field_call?(node) do |name, type_node|
    return unless id_type?(type_node) && PRIMARY_ID_FIELDS.include?(name)

    desc = extract_description(node)
    return if desc.nil? # No description - let other cops handle missing descriptions
    return if valid_field_description?(desc, node)

    suggested = expected_description(node)
    report_offense(node, suggested)
  end
end