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>2023-10-05 21:09:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-05 21:09:33 +0300
commitc20e6edd8a648a2cecb7ba0c4e8be48ce68e25a1 (patch)
tree804cbc1984f4b6636d958bf7b70a00f323a8137f /rubocop
parent3e6c042eb05e09d88c2bd988cb9ef5f9eba67794 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/gitlab/avoid_gitlab_instance_checks.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/avoid_gitlab_instance_checks.rb b/rubocop/cop/gitlab/avoid_gitlab_instance_checks.rb
new file mode 100644
index 00000000000..962a58cfb4a
--- /dev/null
+++ b/rubocop/cop/gitlab/avoid_gitlab_instance_checks.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'rubocop-rspec'
+
+module RuboCop
+ module Cop
+ module Gitlab
+ # This cop checks for use of gitlab instance specific checks.
+ #
+ # @example
+ #
+ # # bad
+ # if Gitlab.com?
+ # Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
+ # else
+ # Ci::Runner::FORM_EDITABLE
+ # end
+ #
+ # # good
+ # if Gitlab::Saas.feature_available?('purchases/additional_minutes')
+ # Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
+ # else
+ # Ci::Runner::FORM_EDITABLE
+ # end
+ #
+ class AvoidGitlabInstanceChecks < RuboCop::Cop::Base
+ MSG = 'Avoid the use of `%{name}`. Use Gitlab::Saas.feature_available?. ' \
+ 'See https://docs.gitlab.com/ee/development/ee_features.html#saas-only-feature'
+ RESTRICT_ON_SEND = %i[
+ com? com_except_jh? com_and_canary? com_but_not_canary? org_or_com? should_check_namespace_plan?
+ ].freeze
+
+ # @!method gitlab?(node)
+ def_node_matcher :gitlab?, <<~PATTERN
+ (send (const {nil? (cbase)} :Gitlab) ...)
+ PATTERN
+
+ # @!method should_check_namespace_plan?(node)
+ def_node_matcher :should_check_namespace_plan?, <<~PATTERN
+ (send
+ (const
+ (const
+ {nil? (cbase)} :Gitlab) :CurrentSettings) :should_check_namespace_plan?)
+ PATTERN
+
+ def on_send(node)
+ return unless gitlab?(node) || should_check_namespace_plan?(node)
+
+ add_offense(node, message: format(MSG, name: node.method_name))
+ end
+ end
+ end
+ end
+end