debian-mirror-gitlab/rubocop/cop/gitlab/avoid_feature_get.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
970 B
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module RuboCop
module Cop
module Gitlab
2022-10-11 01:57:18 +05:30
# 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
2022-07-16 23:28:13 +05:30
MSG = 'Use `stub_feature_flags` method instead of `Feature.get`. ' \
'See doc/development/feature_flags/index.md#feature-flags-in-tests for more information.'
2020-06-23 00:09:42 +05:30
def_node_matcher :feature_get?, <<~PATTERN
2022-10-11 01:57:18 +05:30
(send (const {nil? cbase} :Feature) :get ...)
2020-06-23 00:09:42 +05:30
PATTERN
def on_send(node)
2022-10-11 01:57:18 +05:30
return unless feature_get?(node)
2020-06-23 00:09:42 +05:30
2022-10-11 01:57:18 +05:30
add_offense(node.loc.selector)
2020-06-23 00:09:42 +05:30
end
end
end
end
end