Class: RuboCop::Cop::Ezcater::GraphqlFieldsNaming

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
ConfigurableNaming
Defined in:
lib/rubocop/cop/ezcater/graphql_fields_naming.rb

Overview

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

Examples:

# 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

Constant Summary collapse

MSG =
"Use %<style>s for GraphQL fields & arguments names. " \
"See https://git.io/JeofW for our guide. " \
"This can be overridden with camelize."
FIELD_ADDING_METHODS =
i(field argument).freeze
PROCESSABLE_TYPES =
i(sym string).freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_super, on_yield



34
35
36
37
38
39
40
41
42
43
44
# 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.loc.expression)
end