class RuboCop::Cop::Ezcater::GraphqlFieldsNaming

This cop makes sure that GraphQL fields & arguments match the supported style git.io/JeofW

The cop also ignores when users provide a :camelize option, because the user is manually requesting to override the value

@example

# bad
field :fooBar, ID, null: false
argument :barBaz, ID, required: true

# good
field :foo_bar, ID, null: true
field :foo_bar, ID, null: true do
  argument :bar_baz, ID, required: true
end

field :fooBar, ID, null: true, camelize: true

Constants

FIELD_ADDING_METHODS
MSG
PROCESSABLE_TYPES

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/ezcater/graphql_fields_naming.rb, line 34
def on_send(node)
  method = method_name(node)
  first_arg = node.first_argument

  return unless FIELD_ADDING_METHODS.include? method
  return unless PROCESSABLE_TYPES.include?(first_arg&.type)

  return if includes_camelize?(node)

  check_name(node, first_arg.value, node.first_argument)
end
Also aliased as: on_super, on_yield
on_super(node)
Alias for: on_send
on_yield(node)
Alias for: on_send

Private Instance Methods

args_include_camelize?(arg_pair) click to toggle source
# File lib/rubocop/cop/ezcater/graphql_fields_naming.rb, line 57
def args_include_camelize?(arg_pair)
  key_node = arg_pair.key
  _value_node = arg_pair.value

  key_node.value.match?(/camelize/)
end
includes_camelize?(node) click to toggle source
# File lib/rubocop/cop/ezcater/graphql_fields_naming.rb, line 51
def includes_camelize?(node)
  results = []
  node.last_argument.each_child_node { |arg| results << args_include_camelize?(arg) }
  results.any?
end
message(style) click to toggle source
# File lib/rubocop/cop/ezcater/graphql_fields_naming.rb, line 68
def message(style)
  format(MSG, style: style)
end
method_name(node) click to toggle source
# File lib/rubocop/cop/ezcater/graphql_fields_naming.rb, line 64
def method_name(node)
  node.children[1]
end