From 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 19 May 2021 15:44:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-12-stable-ee --- .../cop/active_model_errors_direct_manipulation.rb | 60 ++++++++++++++++++++++ rubocop/cop/code_reuse/presenter.rb | 2 +- rubocop/cop/code_reuse/serializer.rb | 2 +- rubocop/cop/code_reuse/service_class.rb | 2 +- rubocop/cop/code_reuse/worker.rb | 2 +- rubocop/cop/graphql/authorize_types.rb | 2 +- rubocop/cop/inject_enterprise_edition_module.rb | 14 ++--- rubocop/cop/scalability/idempotent_worker.rb | 2 +- rubocop/rubocop-code_reuse.yml | 1 + 9 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 rubocop/cop/active_model_errors_direct_manipulation.rb (limited to 'rubocop') diff --git a/rubocop/cop/active_model_errors_direct_manipulation.rb b/rubocop/cop/active_model_errors_direct_manipulation.rb new file mode 100644 index 00000000000..e1e2840f37c --- /dev/null +++ b/rubocop/cop/active_model_errors_direct_manipulation.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + # Cop that avoid direct manipulation of ActiveModel#errors hash, + # in preparation to upgrade to Rails 6.1 + # + # See https://gitlab.com/gitlab-org/gitlab/-/issues/225874 + class ActiveModelErrorsDirectManipulation < RuboCop::Cop::Cop + MSG = 'Avoid manipulating errors hash directly. For more details check https://gitlab.com/gitlab-org/gitlab/-/issues/225874' + + MANIPULATIVE_METHODS = ":<< :append :clear :collect! :compact! :concat :delete :delete_at :delete_if :drop :drop_while :fill :filter! :keep_if :flatten! :insert :map! :pop :prepend :push :reject! :replace :reverse! :rotate! :select! :shift :shuffle! :slice! :sort! :sort_by! :uniq! :unshift" + + def_node_matcher :active_model_errors_root_manipulation?, <<~PATTERN + (send + (send + (send {send ivar lvar} :errors) + :[] + ...) + {#{MANIPULATIVE_METHODS}} + ...) + PATTERN + + def_node_matcher :active_model_errors_root_assignment?, <<~PATTERN + (send + (send {send ivar lvar} :errors) + :[]= + ...) + PATTERN + + def_node_matcher :active_model_errors_manipulation?, <<~PATTERN + (send + (send + (send + (send {send ivar lvar} :errors) + {:messages :details}) + :[] + ...) + {#{MANIPULATIVE_METHODS}} + ...) + PATTERN + + def_node_matcher :active_model_errors_assignment?, <<~PATTERN + (send + (send + (send {send ivar lvar} :errors) + {:messages :details}) + :[]= + ...) + PATTERN + + def on_send(node) + add_offense(node, location: :expression) if active_model_errors_root_assignment?(node) + add_offense(node, location: :expression) if active_model_errors_root_manipulation?(node) + add_offense(node, location: :expression) if active_model_errors_manipulation?(node) + add_offense(node, location: :expression) if active_model_errors_assignment?(node) + end + end + end +end diff --git a/rubocop/cop/code_reuse/presenter.rb b/rubocop/cop/code_reuse/presenter.rb index 5f8f2839ca6..6eef5e5a4b0 100644 --- a/rubocop/cop/code_reuse/presenter.rb +++ b/rubocop/cop/code_reuse/presenter.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../code_reuse_helpers.rb' +require_relative '../../code_reuse_helpers' module RuboCop module Cop diff --git a/rubocop/cop/code_reuse/serializer.rb b/rubocop/cop/code_reuse/serializer.rb index 2212c50514e..17a84ec31f7 100644 --- a/rubocop/cop/code_reuse/serializer.rb +++ b/rubocop/cop/code_reuse/serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../code_reuse_helpers.rb' +require_relative '../../code_reuse_helpers' module RuboCop module Cop diff --git a/rubocop/cop/code_reuse/service_class.rb b/rubocop/cop/code_reuse/service_class.rb index 768b43fb684..e403a87093c 100644 --- a/rubocop/cop/code_reuse/service_class.rb +++ b/rubocop/cop/code_reuse/service_class.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../code_reuse_helpers.rb' +require_relative '../../code_reuse_helpers' module RuboCop module Cop diff --git a/rubocop/cop/code_reuse/worker.rb b/rubocop/cop/code_reuse/worker.rb index e38d2783d0f..4902920234f 100644 --- a/rubocop/cop/code_reuse/worker.rb +++ b/rubocop/cop/code_reuse/worker.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../code_reuse_helpers.rb' +require_relative '../../code_reuse_helpers' module RuboCop module Cop diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb index 9bfd93aa3db..180a1a27a85 100644 --- a/rubocop/cop/graphql/authorize_types.rb +++ b/rubocop/cop/graphql/authorize_types.rb @@ -8,7 +8,7 @@ module RuboCop 'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization' # We want to exclude our own basetypes and scalars - ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType + ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType SubscriptionType QueryType GraphQL::Schema BaseUnion BaseInputObject].freeze def_node_search :authorize?, <<~PATTERN diff --git a/rubocop/cop/inject_enterprise_edition_module.rb b/rubocop/cop/inject_enterprise_edition_module.rb index 16e4b647265..785f1494354 100644 --- a/rubocop/cop/inject_enterprise_edition_module.rb +++ b/rubocop/cop/inject_enterprise_edition_module.rb @@ -2,19 +2,19 @@ module RuboCop module Cop - # Cop that blacklists the injecting of EE specific modules before any lines which are not already injecting another module. + # Cop that blacklists the injecting of extension specific modules before any lines which are not already injecting another module. # It allows multiple module injections as long as they're all at the end. class InjectEnterpriseEditionModule < RuboCop::Cop::Cop - INVALID_LINE = 'Injecting EE modules must be done on the last line of this file' \ + INVALID_LINE = 'Injecting extension modules must be done on the last line of this file' \ ', outside of any class or module definitions' DISALLOWED_METHOD = - 'EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`' + 'EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`' - INVALID_ARGUMENT = 'EE modules to inject must be specified as a String' + INVALID_ARGUMENT = 'extension modules to inject must be specified as a String' CHECK_LINE_METHODS = - Set.new(%i[include_if_ee extend_if_ee prepend_if_ee]).freeze + Set.new(%i[include_mod_with extend_mod_with prepend_mod_with]).freeze DISALLOW_METHODS = Set.new(%i[include extend prepend]).freeze @@ -67,10 +67,10 @@ module RuboCop def check_method?(node) name = node.children[1] - if CHECK_LINE_METHODS.include?(name) || DISALLOW_METHODS.include?(name) + if DISALLOW_METHODS.include?(name) ee_const?(node.children[2]) else - false + CHECK_LINE_METHODS.include?(name) end end diff --git a/rubocop/cop/scalability/idempotent_worker.rb b/rubocop/cop/scalability/idempotent_worker.rb index a38b457b7c7..7abde54ce7e 100644 --- a/rubocop/cop/scalability/idempotent_worker.rb +++ b/rubocop/cop/scalability/idempotent_worker.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../code_reuse_helpers.rb' +require_relative '../../code_reuse_helpers' module RuboCop module Cop diff --git a/rubocop/rubocop-code_reuse.yml b/rubocop/rubocop-code_reuse.yml index 64e51c859f4..a3b75117621 100644 --- a/rubocop/rubocop-code_reuse.yml +++ b/rubocop/rubocop-code_reuse.yml @@ -31,6 +31,7 @@ CodeReuse/ActiveRecord: - lib/gitlab/import_export/**/*.rb - lib/gitlab/project_authorizations.rb - lib/gitlab/sql/**/*.rb + - lib/gitlab/usage/metrics/instrumentations/**/*.rb - lib/system_check/**/*.rb - qa/**/*.rb - rubocop/**/*.rb -- cgit v1.2.1