Class: RuboCop::Cop::GraphQL::UnnecessaryFieldCamelize

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

Overview

This cop checks if each field has an unnecessary camelize.

Examples:

# good

class UserType < BaseType
  field :name, String, "Name of the user", null: true
end

# bad

class UserType < BaseType
  field :name, "Name of the user", String, null: true, camelize: true
end

Constant Summary collapse

MSG =
"Unnecessary field camelize"
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



27
28
29
30
31
32
33
# File 'lib/rubocop/cop/graphql/unnecessary_field_camelize.rb', line 27

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

  field = RuboCop::GraphQL::Field.new(node)

  add_offense(node) if field.name.to_s.split("_").length < 2 && !field.kwargs.camelize.nil?
end