Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-13 00:10:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-13 00:10:34 +0300
commita9acc0c2fb0f280077edc7a70dbf383c55252af8 (patch)
treeddc5ecf168a9402d35b82f1d215a8153a3b1d542 /rubocop
parent41b2e83ad69056b850e278e4bd0a7a4f3e585376 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/gitlab/service_response.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/service_response.rb b/rubocop/cop/gitlab/service_response.rb
new file mode 100644
index 00000000000..edde662a038
--- /dev/null
+++ b/rubocop/cop/gitlab/service_response.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require_relative '../../code_reuse_helpers'
+
+module RuboCop
+ module Cop
+ module Gitlab
+ class ServiceResponse < ::RuboCop::Cop::Base
+ include CodeReuseHelpers
+
+ # This cop checks that ServiceResponse object is not used with the
+ # deprecated attribute `http_status`.
+ #
+ # @example
+ #
+ # # bad
+ # ServiceResponse.error(message: "...", http_status: :forbidden)
+ #
+ # # good
+ # ServiceResponse.error(message: "...", reason: :insufficient_permissions)
+ MSG = 'Use `reason` instead of the deprecated `http_status`: https://gitlab.com/gitlab-org/gitlab/-/issues/356036'
+
+ RESTRICT_ON_SEND = %i[error success new].freeze
+ METHOD_NAMES = RESTRICT_ON_SEND.map(&:inspect).join(' ').freeze
+
+ def_node_matcher :service_response_with_http_status, <<~PATTERN
+ (send
+ (const {nil? cbase} :ServiceResponse)
+ {#{METHOD_NAMES}}
+ (hash <$(pair (sym :http_status) _) ...>)
+ )
+ PATTERN
+
+ def on_send(node)
+ pair = service_response_with_http_status(node)
+ return unless pair
+
+ add_offense(pair)
+ end
+ end
+ end
+ end
+end