diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-07 18:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-07 18:07:51 +0000 |
commit | 6cae2159b8ce1e84fad48f3dbd5368995cbd87b1 (patch) | |
tree | 46d6b7cbd78d72fe5dcb5d6b1ed973b30deadc71 /rubocop | |
parent | 84f9f0cb8137637708a41152347e7754c1e9fb83 (diff) | |
download | gitlab-ce-6cae2159b8ce1e84fad48f3dbd5368995cbd87b1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/scalability/file_uploads.rb | 41 | ||||
-rw-r--r-- | rubocop/rubocop-ruby27.yml | 2 |
2 files changed, 17 insertions, 26 deletions
diff --git a/rubocop/cop/scalability/file_uploads.rb b/rubocop/cop/scalability/file_uploads.rb index 3ccb9110e79..fc52444c551 100644 --- a/rubocop/cop/scalability/file_uploads.rb +++ b/rubocop/cop/scalability/file_uploads.rb @@ -26,34 +26,25 @@ module RuboCop # 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 diff --git a/rubocop/rubocop-ruby27.yml b/rubocop/rubocop-ruby27.yml index 5c1b71f81e2..29957defeb0 100644 --- a/rubocop/rubocop-ruby27.yml +++ b/rubocop/rubocop-ruby27.yml @@ -2,7 +2,7 @@ # Ruby 3.0. This configuration should be removed after the transition has been # completed. -# These cops are disabled in Ruby 3.0 (rubocop-30.yml). +# These cops are enabled in Ruby 3.0 (rubocop-30.yml). Style/MutableConstant: Enabled: false Style/RedundantFreeze: |