diff options
Diffstat (limited to 'rubocop/cop/gitlab/mark_used_feature_flags.rb')
-rw-r--r-- | rubocop/cop/gitlab/mark_used_feature_flags.rb | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/rubocop/cop/gitlab/mark_used_feature_flags.rb b/rubocop/cop/gitlab/mark_used_feature_flags.rb index 63bccec31c0..8d8c84e78f5 100644 --- a/rubocop/cop/gitlab/mark_used_feature_flags.rb +++ b/rubocop/cop/gitlab/mark_used_feature_flags.rb @@ -9,7 +9,7 @@ module RuboCop # # The files set in `tmp/feature_flags/*.used` can then be used for verification purpose. # - class MarkUsedFeatureFlags < RuboCop::Cop::Cop + class MarkUsedFeatureFlags < RuboCop::Cop::Base include RuboCop::CodeReuseHelpers FEATURE_METHODS = %i[enabled? disabled?].freeze @@ -26,9 +26,6 @@ module RuboCop data_consistency deduplicate ].freeze - GRAPHQL_METHODS = %i[ - field - ].freeze SELF_METHODS = %i[ push_frontend_feature_flag push_force_frontend_feature_flag @@ -36,11 +33,12 @@ module RuboCop limit_feature_flag_for_override= ].freeze + EXPERIMENT_METHODS + RUGGED_METHODS + WORKER_METHODS - RESTRICT_ON_SEND = FEATURE_METHODS + EXPERIMENTATION_METHODS + GRAPHQL_METHODS + SELF_METHODS + RESTRICT_ON_SEND = FEATURE_METHODS + EXPERIMENTATION_METHODS + SELF_METHODS USAGE_DATA_COUNTERS_EVENTS_YAML_GLOBS = [ File.expand_path("../../../config/metrics/aggregates/*.yml", __dir__), - File.expand_path("../../../lib/gitlab/usage_data_counters/known_events/*.yml", __dir__) + File.expand_path("../../../lib/gitlab/usage_data_counters/known_events/*.yml", __dir__), + File.expand_path("../../../ee/lib/ee/gitlab/usage_data_counters/known_events/*.yml", __dir__) ].freeze class << self @@ -86,12 +84,12 @@ module RuboCop # Additionally, mark experiment-related feature flag as used as well matching_feature_flags = defined_feature_flags.select { |flag| flag == "#{flag_value}_experiment_percentage" } matching_feature_flags.each do |matching_feature_flag| - puts_if_ci(node, "The '#{matching_feature_flag}' feature flag tracks the #{flag_value} experiment, which is still in use, so we'll mark it as used.") + puts_if_debug(node, "The '#{matching_feature_flag}' feature flag tracks the #{flag_value} experiment, which is still in use, so we'll mark it as used.") save_used_feature_flag(matching_feature_flag) end end elsif flag_arg_is_send_type?(flag_arg) - puts_if_ci(node, "Feature flag is dynamic: '#{flag_value}.") + puts_if_debug(node, "Feature flag is dynamic: '#{flag_value}.") elsif flag_arg_is_dstr_or_dsym?(flag_arg) str_prefix = flag_arg.children[0] rest_children = flag_arg.children[1..] @@ -99,21 +97,23 @@ module RuboCop if rest_children.none? { |child| child.str_type? } matching_feature_flags = defined_feature_flags.select { |flag| flag.start_with?(str_prefix.value) } matching_feature_flags.each do |matching_feature_flag| - puts_if_ci(node, "The '#{matching_feature_flag}' feature flag starts with '#{str_prefix.value}', so we'll optimistically mark it as used.") + puts_if_debug(node, "The '#{matching_feature_flag}' feature flag starts with '#{str_prefix.value}', so we'll optimistically mark it as used.") save_used_feature_flag(matching_feature_flag) end else - puts_if_ci(node, "Interpolated feature flag name has multiple static string parts, we won't track it.") + puts_if_debug(node, "Interpolated feature flag name has multiple static string parts, we won't track it.") end else - puts_if_ci(node, "Feature flag has an unknown type: #{flag_arg.type}.") + puts_if_debug(node, "Feature flag has an unknown type: #{flag_arg.type}.") end end private - def puts_if_ci(node, text) - puts "#{text} (call: `#{node.source}`, source: #{node.location.expression.source_buffer.name})" if ENV['CI'] + def puts_if_debug(node, text) + return unless RuboCop::ConfigLoader.debug + + warn "#{text} (call: `#{node.source}`, source: #{node.location.expression.source_buffer.name})" end def save_used_feature_flag(feature_flag_name) @@ -138,15 +138,6 @@ module RuboCop node.children[3].each_pair.find do |pair| pair.key.value == :feature_flag end&.value - elsif graphql_method?(node) - return unless node.children.size > 3 - - opts_index = node.children[3].hash_type? ? 3 : 4 - return unless node.children[opts_index] - - node.children[opts_index].each_pair.find do |pair| - pair.key.value == :_deprecated_feature_flag - end&.value else arg_index = rugged_method?(node) ? 3 : 2 @@ -178,7 +169,7 @@ module RuboCop end def caller_is_feature?(node) - class_caller(node) == "Feature" + %w[Feature YamlProcessor::FeatureFlags].include?(class_caller(node)) end def caller_is_feature_gitaly?(node) @@ -209,16 +200,12 @@ module RuboCop WORKER_METHODS.include?(method_name(node)) end - def graphql_method?(node) - GRAPHQL_METHODS.include?(method_name(node)) && in_graphql_types?(node) - end - def self_method?(node) SELF_METHODS.include?(method_name(node)) && class_caller(node).empty? end def trackable_flag?(node) - feature_method?(node) || experimentation_method?(node) || graphql_method?(node) || self_method?(node) + feature_method?(node) || experimentation_method?(node) || self_method?(node) end # Marking all event's feature flags as used as Gitlab::UsageDataCounters::HLLRedisCounter.track_event{,context} |