Class: RuboCop::Cop::GraphQL::UnnecessaryArgumentCamelize

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

Overview

This cop checks if each argument has an unnecessary camelize.

# bad

 class UserType < BaseType
   argument :filter, String, required: false, camelize: false
 end

# bad

 class UserType < BaseType
   field :name, String, "Name of the user", null: true do
     argument :filter, String, required: false, camelize: false
   end
 end

Examples:

# good

class UserType < BaseType
  field :name, String, "Name of the user", null: true do
    argument :filter, String, required: false
  end
end

# good

class UserType < BaseType
  argument :filter, String, required: false
end

# good

class UserType < BaseType
  argument :email_filter, String, required: false, camelize: true
end

Constant Summary collapse

MSG =
"Unnecessary argument camelize"
RESTRICT_ON_SEND =
%i[argument].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



49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/graphql/unnecessary_argument_camelize.rb', line 49

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

  argument = RuboCop::GraphQL::Argument.new(node)

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