2019-12-04 20:38:33 +05:30
|
|
|
# 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
|
|
|
|
#
|
2022-10-11 01:57:18 +05:30
|
|
|
class FileUploads < RuboCop::Cop::Base
|
2023-04-23 21:23:45 +05:30
|
|
|
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)) ...>
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2019-12-04 20:38:33 +05:30
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
2023-04-23 21:23:45 +05:30
|
|
|
file_in_type(node) do |file_node|
|
|
|
|
add_offense(file_node)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|