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

avoid_feature_get.rb « gitlab « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68aaff8aeffe8cb87cd5e691d53ed8ef7acbf908 (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
# frozen_string_literal: true

module RuboCop
  module Cop
    module Gitlab
      # Bans the use of `Feature.get`.
      #
      # @example
      #
      # # bad
      #
      # Feature.get(:x).enable
      # Feature.get(:x).enable_percentage_of_time(100)
      # Feature.get(:x).remove
      #
      # # good
      #
      # stub_feature_flags(x: true)
      # Feature.enable(:x)
      # Feature.enable_percentage_of_time(:x, 100)
      # Feature.remove(:x)
      #
      class AvoidFeatureGet < RuboCop::Cop::Base
        MSG = 'Use `stub_feature_flags` method instead of `Feature.get`. ' \
          'See doc/development/feature_flags/index.md#feature-flags-in-tests for more information.'

        def_node_matcher :feature_get?, <<~PATTERN
          (send (const {nil? cbase} :Feature) :get ...)
        PATTERN

        def on_send(node)
          return unless feature_get?(node)

          add_offense(node.loc.selector)
        end
      end
    end
  end
end