blob: fc52444c551228050cb4c8587b7e52a9bc06e843 (
plain)
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 Scalability
# This cop checks for `File` params in API
#
# @example
#
# # bad
# params do
# requires :file, type: File
# end
#
# params do
# optional :file, type: File
# end
#
# # good
# params do
# requires :file, type: ::API::Validations::Types::WorkhorseFile
# end
#
# params do
# optional :file, type: ::API::Validations::Types::WorkhorseFile
# end
#
class FileUploads < RuboCop::Cop::Base
MSG = 'Do not upload files without workhorse acceleration. ' \
'Please refer to https://docs.gitlab.com/ee/development/uploads.html'
def_node_matcher :file_in_type, <<~PATTERN
(send nil? {:requires :optional}
(sym _)
(hash
{
<(pair (sym :types) (array <$(const nil? :File) ...>)) ...>
<(pair (sym :type) $(const nil? :File)) ...>
}
)
)
PATTERN
def on_send(node)
file_in_type(node) do |file_node|
add_offense(file_node)
end
end
end
end
end
end
|