Class: RuboCop::Cop::Obsession::Graphql::MutationName

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/rubocop/cop/obsession/graphql/mutation_name.rb

Overview

This cop checks for mutation names that do not start with a verb.

Mutation names should start with a verb, because mutations are actions, and actions are best described with verbs.

Examples:


# bad
module Mutations
  class Event < Base
  end
end

# good
module Mutations
  class TrackEvent < Base
  end
end

Constant Summary collapse

MSG =
'Mutation name should start with a verb.'

Instance Method Summary collapse

Methods included from Helpers

#rails_callback?, #verb?

Instance Method Details

#on_class(class_node) ⇒ Object



30
31
32
33
34
35
# File 'lib/rubocop/cop/obsession/graphql/mutation_name.rb', line 30

def on_class(class_node)
  class_name = class_node.identifier.source
  class_name_first_word = class_name.underscore.split('_').first

  add_offense(class_node) if !verb?(class_name_first_word)
end