-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathargument_name.rb
40 lines (34 loc) · 899 Bytes
/
argument_name.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true
module RuboCop
module Cop
module GraphQL
# This cop checks whether field names are snake_case.
#
# @example
# # good
#
# class BanUser < BaseMutation
# argument :user_id, ID, required: true
# end
#
# # bad
#
# class BanUser < BaseMutation
# argument :userId, ID, required: true
# end
#
class ArgumentName < Base
include RuboCop::GraphQL::NodePattern
RESTRICT_ON_SEND = %i[argument].freeze
using RuboCop::GraphQL::Ext::SnakeCase
MSG = "Use snake_case for argument names"
def on_send(node)
return unless argument?(node)
argument = RuboCop::GraphQL::Argument.new(node)
return if argument.name.snake_case?
add_offense(node)
end
end
end
end
end