Skip to content
代码片段 群组 项目
未验证 提交 38e91267 编辑于 作者: Peter Leitzen's avatar Peter Leitzen
浏览文件

Simplify cop rule Scalability/FileUploads

Define a single node pattern to catch both cases `type: File` and
`types: [File, ...]`.

Defining node patterns on the fly is slow and discouraged.
上级 426a84f7
No related branches found
No related tags found
1 合并请求!1355Draft: Reset password by phone with geetest captcha
...@@ -7019,7 +7019,6 @@ RSpec/MissingFeatureCategory: ...@@ -7019,7 +7019,6 @@ RSpec/MissingFeatureCategory:
- 'spec/rubocop/cop/safe_params_spec.rb' - 'spec/rubocop/cop/safe_params_spec.rb'
- 'spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb' - 'spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb'
- 'spec/rubocop/cop/scalability/cron_worker_context_spec.rb' - 'spec/rubocop/cop/scalability/cron_worker_context_spec.rb'
- 'spec/rubocop/cop/scalability/file_uploads_spec.rb'
- 'spec/rubocop/cop/scalability/idempotent_worker_spec.rb' - 'spec/rubocop/cop/scalability/idempotent_worker_spec.rb'
- 'spec/rubocop/cop/sidekiq_api_usage_spec.rb' - 'spec/rubocop/cop/sidekiq_api_usage_spec.rb'
- 'spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb' - 'spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb'
......
...@@ -31,10 +31,10 @@ def current_appearance ...@@ -31,10 +31,10 @@ def current_appearance
optional :pwa_short_name, type: String, desc: 'Optional, short name for Progressive Web App' optional :pwa_short_name, type: String, desc: 'Optional, short name for Progressive Web App'
optional :pwa_description, type: String, desc: 'An explanation of what the Progressive Web App does' optional :pwa_description, type: String, desc: 'An explanation of what the Progressive Web App does'
# TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960
optional :logo, type: File, desc: 'Instance image used on the sign in / sign up page' # rubocop:disable Scalability/FileUploads optional :logo, type: File, desc: 'Instance image used on the sign in / sign up page' # rubocop:todo Scalability/FileUploads
optional :pwa_icon, type: File, desc: 'Icon used for Progressive Web App' # rubocop:disable Scalability/FileUploads optional :pwa_icon, type: File, desc: 'Icon used for Progressive Web App' # rubocop:todo Scalability/FileUploads
optional :header_logo, type: File, desc: 'Instance image used for the main navigation bar' # rubocop:disable Scalability/FileUploads optional :header_logo, type: File, desc: 'Instance image used for the main navigation bar' # rubocop:todo Scalability/FileUploads
optional :favicon, type: File, desc: 'Instance favicon in .ico/.png format' # rubocop:disable Scalability/FileUploads optional :favicon, type: File, desc: 'Instance favicon in .ico/.png format' # rubocop:todo Scalability/FileUploads
optional :new_project_guidelines, type: String, desc: 'Markdown text shown on the new project page' optional :new_project_guidelines, type: String, desc: 'Markdown text shown on the new project page'
optional :profile_image_guidelines, type: String, desc: 'Markdown text shown on the profile page below Public Avatar' optional :profile_image_guidelines, type: String, desc: 'Markdown text shown on the profile page below Public Avatar'
optional :header_message, type: String, desc: 'Message within the system header bar' optional :header_message, type: String, desc: 'Message within the system header bar'
......
...@@ -94,7 +94,7 @@ def normalize_params_file_to_string ...@@ -94,7 +94,7 @@ def normalize_params_file_to_string
end end
params do params do
requires :domain, type: String, desc: 'The domain' requires :domain, type: String, desc: 'The domain'
# rubocop:disable Scalability/FileUploads # rubocop:todo Scalability/FileUploads
# TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960
optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate
optional :key, types: [File, String], desc: 'The key', as: :user_provided_key optional :key, types: [File, String], desc: 'The key', as: :user_provided_key
...@@ -122,7 +122,7 @@ def normalize_params_file_to_string ...@@ -122,7 +122,7 @@ def normalize_params_file_to_string
desc 'Updates a pages domain' desc 'Updates a pages domain'
params do params do
requires :domain, type: String, desc: 'The domain' requires :domain, type: String, desc: 'The domain'
# rubocop:disable Scalability/FileUploads # rubocop:todo Scalability/FileUploads
# TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960
optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate
optional :key, types: [File, String], desc: 'The key', as: :user_provided_key optional :key, types: [File, String], desc: 'The key', as: :user_provided_key
......
...@@ -26,34 +26,25 @@ module Scalability ...@@ -26,34 +26,25 @@ module Scalability
# end # end
# #
class FileUploads < RuboCop::Cop::Base class FileUploads < RuboCop::Cop::Base
MSG = 'Do not upload files without workhorse acceleration. Please refer to https://docs.gitlab.com/ee/development/uploads.html' MSG = 'Do not upload files without workhorse acceleration. ' \
'Please refer to https://docs.gitlab.com/ee/development/uploads.html'
def_node_search :file_type_params?, <<~PATTERN
(send nil? {:requires :optional} (sym _) (hash <(pair (sym :type)(const nil? :File)) ...>)) def_node_matcher :file_in_type, <<~PATTERN
PATTERN (send nil? {:requires :optional}
(sym _)
def_node_search :file_types_params?, <<~PATTERN (hash
(send nil? {:requires :optional} (sym _) (hash <(pair (sym :types)(array <(const nil? :File) ...>)) ...>)) {
<(pair (sym :types) (array <$(const nil? :File) ...>)) ...>
<(pair (sym :type) $(const nil? :File)) ...>
}
)
)
PATTERN PATTERN
def be_file_param_usage?(node)
file_type_params?(node) || file_types_params?(node)
end
def on_send(node) def on_send(node)
return unless be_file_param_usage?(node) file_in_type(node) do |file_node|
add_offense(file_node)
add_offense(find_file_param(node)) end
end
private
def find_file_param(node)
node.each_descendant.find { |children| file_node_pattern.match(children) }
end
def file_node_pattern
@file_node_pattern ||= RuboCop::NodePattern.new("(const nil? :File)")
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册