/
unnecessary_argument_camelize.rb
61 lines (56 loc) · 1.53 KB
/
unnecessary_argument_camelize.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
module RuboCop
module Cop
module GraphQL
# This cop checks if each argument has an unnecessary camelize.
#
# @example
# # 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
#
# # 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
#
class UnnecessaryArgumentCamelize < Base
include RuboCop::GraphQL::NodePattern
MSG = "Unnecessary argument camelize"
RESTRICT_ON_SEND = %i[argument].freeze
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
end
end
end
end