Class: RuboCop::Cop::GraphQL::ArgumentName

Inherits:
Base
  • Object
show all
Includes:
GraphQL::NodePattern
Defined in:
lib/rubocop/cop/graphql/argument_name.rb

Overview

This cop checks whether field names are snake_case.

Examples:

# good

class BanUser < BaseMutation
  argument :user_id, ID, required: true
end

# bad

class BanUser < BaseMutation
  argument :userId, ID, required: true
end

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from GraphQL::NodePattern

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

Instance Method Details

#on_send(node) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/rubocop/cop/graphql/argument_name.rb', line 29

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

  argument = RuboCop::GraphQL::Argument.new(node)
  return if argument.name.snake_case?

  add_offense(node)
end