diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /rubocop/cop/gitlab/avoid_feature_get.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
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 |