Class: RuboCop::Cop::GraphQL::FieldName

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
GraphQL::NodePattern
Defined in:
lib/rubocop/cop/graphql/field_name.rb

Overview

This cop checks whether field names are snake_case.

Examples:

# good

class UserType < BaseType
  field :first_name, String, null: true
end

# bad

class UserType < BaseType
  field :firstName, String, null: true
end

Constant Summary collapse

MSG =
"Use snake_case for field names"
RESTRICT_ON_SEND =
%i[field].freeze

Instance Method Summary collapse

Methods included from GraphQL::NodePattern

#argument?, #field?, #field_definition?, #field_definition_with_body?

Instance Method Details

#on_send(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/rubocop/cop/graphql/field_name.rb', line 34

def on_send(node)
  return unless field_definition?(node)

  field = RuboCop::GraphQL::Field.new(node)
  return if field.name.snake_case?

  add_offense(node) do |corrector|
    rename_field_name(corrector, field, node)
  end
end