diff options
Diffstat (limited to 'rubocop/cop/gitlab/avoid_feature_get.rb')
-rw-r--r-- | rubocop/cop/gitlab/avoid_feature_get.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/rubocop/cop/gitlab/avoid_feature_get.rb b/rubocop/cop/gitlab/avoid_feature_get.rb index 1bce89268d9..68aaff8aeff 100644 --- a/rubocop/cop/gitlab/avoid_feature_get.rb +++ b/rubocop/cop/gitlab/avoid_feature_get.rb @@ -3,23 +3,35 @@ module RuboCop module Cop module Gitlab - # Cop that blacklists the use of `Feature.get`. - class AvoidFeatureGet < RuboCop::Cop::Cop + # 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? :Feature) :get ...) - PATTERN - - def_node_matcher :global_feature_get?, <<~PATTERN - (send (const (cbase) :Feature) :get ...) + (send (const {nil? cbase} :Feature) :get ...) PATTERN def on_send(node) - return unless feature_get?(node) || global_feature_get?(node) + return unless feature_get?(node) - add_offense(node, location: :selector) + add_offense(node.loc.selector) end end end |