blob: 962a58cfb4a9844970ac7bf4e004e5150d0124f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
|