diff --git a/.rubocop_todo/rspec/missing_feature_category.yml b/.rubocop_todo/rspec/missing_feature_category.yml index c38fc19d7626c134cdf1269e9811c559c48590a7..3386eb650f34afea62b50a4d039f8a97140bd6c7 100644 --- a/.rubocop_todo/rspec/missing_feature_category.yml +++ b/.rubocop_todo/rspec/missing_feature_category.yml @@ -7019,7 +7019,6 @@ RSpec/MissingFeatureCategory: - 'spec/rubocop/cop/safe_params_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/file_uploads_spec.rb' - 'spec/rubocop/cop/scalability/idempotent_worker_spec.rb' - 'spec/rubocop/cop/sidekiq_api_usage_spec.rb' - 'spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb' diff --git a/lib/api/appearance.rb b/lib/api/appearance.rb index 2023c43b46332b47b4047e46b9eef3b20eb3b7fc..f8e4f5d2ab2e06eefaec29b5294d5de18c83cfa6 100644 --- a/lib/api/appearance.rb +++ b/lib/api/appearance.rb @@ -31,10 +31,10 @@ def current_appearance 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' # 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 :pwa_icon, type: File, desc: 'Icon used for Progressive Web App' # rubocop:disable Scalability/FileUploads - optional :header_logo, type: File, desc: 'Instance image used for the main navigation bar' # rubocop:disable Scalability/FileUploads - optional :favicon, type: File, desc: 'Instance favicon in .ico/.png format' # 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:todo 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:todo Scalability/FileUploads 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 :header_message, type: String, desc: 'Message within the system header bar' diff --git a/lib/api/pages_domains.rb b/lib/api/pages_domains.rb index 15c1a78839f6ae65c321a3feba3cb31a06fdbda6..db1561864585f57a63b319091b81b778653f4e45 100644 --- a/lib/api/pages_domains.rb +++ b/lib/api/pages_domains.rb @@ -94,7 +94,7 @@ def normalize_params_file_to_string end params do 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 optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate optional :key, types: [File, String], desc: 'The key', as: :user_provided_key @@ -122,7 +122,7 @@ def normalize_params_file_to_string desc 'Updates a pages domain' params do 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 optional :certificate, types: [File, String], desc: 'The certificate', as: :user_provided_certificate optional :key, types: [File, String], desc: 'The key', as: :user_provided_key diff --git a/rubocop/cop/scalability/file_uploads.rb b/rubocop/cop/scalability/file_uploads.rb index 3ccb9110e798e63a18ebb3411bbc5a034beac3db..fc52444c551228050cb4c8587b7e52a9bc06e843 100644 --- a/rubocop/cop/scalability/file_uploads.rb +++ b/rubocop/cop/scalability/file_uploads.rb @@ -26,34 +26,25 @@ module Scalability # 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_search :file_type_params?, <<~PATTERN - (send nil? {:requires :optional} (sym _) (hash <(pair (sym :type)(const nil? :File)) ...>)) - PATTERN - - def_node_search :file_types_params?, <<~PATTERN - (send nil? {:requires :optional} (sym _) (hash <(pair (sym :types)(array <(const nil? :File) ...>)) ...>)) + 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 be_file_param_usage?(node) - file_type_params?(node) || file_types_params?(node) - end - def on_send(node) - return unless be_file_param_usage?(node) - - add_offense(find_file_param(node)) - 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)") + file_in_type(node) do |file_node| + add_offense(file_node) + end end end end