Commit 567cb9b4 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-rubocop-speedup-mark-used-feature-flags' into 'master'

Mark feature flags in Gitlab/MarkUsedFeatureFlags only once

See merge request gitlab-org/gitlab!69469
parents 370a8ea7 ba4878af
......@@ -47,10 +47,21 @@ module RuboCop
:usage_data_static_site_editor_merge_requests # https://gitlab.com/gitlab-org/gitlab/-/issues/284083
].freeze
class << self
# We track feature flags in `on_new_investigation` only once per
# rubocop whole run instead once per file.
attr_accessor :feature_flags_already_tracked
end
# Called before all on_... have been called
# When refining this method, always call `super`
def on_new_investigation
super
return if self.class.feature_flags_already_tracked
self.class.feature_flags_already_tracked = true
track_dynamic_feature_flags!
track_usage_data_counters_known_events!
end
......@@ -69,7 +80,7 @@ module RuboCop
flag_value = flag_value(node)
return unless flag_value
if flag_arg_is_str_or_sym?(node)
if flag_arg_is_str_or_sym?(flag_arg)
if caller_is_feature_gitaly?(node)
save_used_feature_flag("gitaly_#{flag_value}")
else
......@@ -84,9 +95,9 @@ module RuboCop
save_used_feature_flag(matching_feature_flag)
end
end
elsif flag_arg_is_send_type?(node)
elsif flag_arg_is_send_type?(flag_arg)
puts_if_ci(node, "Feature flag is dynamic: '#{flag_value}.")
elsif flag_arg_is_dstr_or_dsym?(node)
elsif flag_arg_is_dstr_or_dsym?(flag_arg)
str_prefix = flag_arg.children[0]
rest_children = flag_arg.children[1..]
......@@ -159,18 +170,16 @@ module RuboCop
end.to_s.tr("\n/", ' _')
end
def flag_arg_is_str_or_sym?(node)
flag_arg = flag_arg(node)
def flag_arg_is_str_or_sym?(flag_arg)
flag_arg.str_type? || flag_arg.sym_type?
end
def flag_arg_is_send_type?(node)
flag_arg(node).send_type?
def flag_arg_is_send_type?(flag_arg)
flag_arg.send_type?
end
def flag_arg_is_dstr_or_dsym?(node)
flag = flag_arg(node)
(flag.dstr_type? || flag.dsym_type?) && flag.children[0].str_type?
def flag_arg_is_dstr_or_dsym?(flag_arg)
(flag_arg.dstr_type? || flag_arg.dsym_type?) && flag_arg.children[0].str_type?
end
def caller_is_feature?(node)
......
......@@ -36,7 +36,7 @@ class StaticAnalysis
Task.new(%w[bin/rake lint:haml], 562),
# We need to disable the cache for this cop since it creates files under tmp/feature_flags/*.used,
# the cache would prevent these files from being created.
Task.new(%w[bundle exec rubocop --only Gitlab/MarkUsedFeatureFlags --cache false], 800),
Task.new(%w[bundle exec rubocop --only Gitlab/MarkUsedFeatureFlags --cache false], 400),
(Gitlab.ee? ? Task.new(%w[bin/rake gettext:updated_check], 360) : nil),
Task.new(%w[yarn run lint:eslint:all], 312),
Task.new(%w[bundle exec rubocop --parallel], 60),
......
......@@ -16,6 +16,7 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
stub_const("#{described_class}::DYNAMIC_FEATURE_FLAGS", [])
allow(cop).to receive(:defined_feature_flags).and_return(defined_feature_flags)
allow(cop).to receive(:usage_data_counters_known_event_feature_flags).and_return([])
described_class.feature_flags_already_tracked = false
end
def feature_flag_path(feature_flag_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment