-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathrefinement.rb
More file actions
52 lines (47 loc) · 1.25 KB
/
Copy pathrefinement.rb
File metadata and controls
52 lines (47 loc) · 1.25 KB
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
# frozen_string_literal: true
module RuboCop
module Cop
module Sorbet
# Checks for the use of Ruby Refinements library. Refinements add
# complexity and incur a performance penalty that can be significant
# for large code bases. Good examples are cases of unrelated
# methods that happen to have the same name as these module methods.
#
# @example
# # bad
# module Foo
# refine(Date) do
# end
# end
#
# # bad
# module Foo
# using(Date) do
# end
# end
#
# # good
# module Foo
# bar.refine(Date)
# end
#
# # good
# module Foo
# bar.using(Date)
# end
class Refinement < Base
MSG = "Do not use Ruby Refinements library as it is not supported by Sorbet."
RESTRICT_ON_SEND = [:refine, :using].freeze
def on_send(node)
return unless node.receiver.nil?
return unless node.first_argument&.const_type?
if node.method?(:refine)
return unless node.block_node
return unless node.parent.parent.module_type?
end
add_offense(node)
end
end
end
end
end