-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathlegacy_dsl.rb
45 lines (41 loc) · 988 Bytes
/
legacy_dsl.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
# frozen_string_literal: true
module RuboCop
module Cop
# This cop checks whether type definitions are class-based or legacy.
#
# @example
# # good
#
# class Example < BaseType
# ....
# end
#
# # bad
#
# Example = GraphQL::ObjectType.define do
# ....
# ....
# end
#
module GraphQL
class LegacyDsl < Base
# @!method legacy_dsl?(node)
def_node_matcher :legacy_dsl?, <<~PATTERN
(block
(send
(const
(const nil? :GraphQL) _) :define)
...
)
PATTERN
MSG = "Avoid using legacy based type-based definitions. " \
"Use class-based definitions instead."
RESTRICT_ON_SEND = %i[define].freeze
def on_send(node)
return unless node.parent.block_type?
add_offense(node.parent) if legacy_dsl?(node.parent)
end
end
end
end
end