diff options
Diffstat (limited to 'rubocop/cop/gitlab')
-rw-r--r-- | rubocop/cop/gitlab/avoid_feature_category_not_owned.rb | 43 | ||||
-rw-r--r-- | rubocop/cop/gitlab/mark_used_feature_flags.rb | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/avoid_feature_category_not_owned.rb b/rubocop/cop/gitlab/avoid_feature_category_not_owned.rb new file mode 100644 index 00000000000..fb790f44a96 --- /dev/null +++ b/rubocop/cop/gitlab/avoid_feature_category_not_owned.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require_relative '../../code_reuse_helpers' + +module RuboCop + module Cop + module Gitlab + class AvoidFeatureCategoryNotOwned < RuboCop::Cop::Cop + include ::RuboCop::CodeReuseHelpers + + MSG = 'Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization' + RESTRICT_ON_SEND = %i[feature_category get post put patch delete].freeze + + def_node_matcher :feature_category_not_owned?, <<~PATTERN + (send _ :feature_category (sym :not_owned) ...) + PATTERN + + def_node_matcher :feature_category_not_owned_api?, <<~PATTERN + (send nil? {:get :post :put :patch :delete} _ + (hash <(pair (sym :feature_category) (sym :not_owned)) ...>) + ) + PATTERN + + def on_send(node) + return unless file_needs_feature_category?(node) + return unless setting_not_owned?(node) + + add_offense(node, location: :expression) + end + + private + + def file_needs_feature_category?(node) + in_controller?(node) || in_worker?(node) || in_api?(node) + end + + def setting_not_owned?(node) + feature_category_not_owned?(node) || feature_category_not_owned_api?(node) + end + end + end + end +end diff --git a/rubocop/cop/gitlab/mark_used_feature_flags.rb b/rubocop/cop/gitlab/mark_used_feature_flags.rb index 7e01c2765c9..290e62436e2 100644 --- a/rubocop/cop/gitlab/mark_used_feature_flags.rb +++ b/rubocop/cop/gitlab/mark_used_feature_flags.rb @@ -31,6 +31,7 @@ module RuboCop ].freeze SELF_METHODS = %i[ push_frontend_feature_flag + push_force_frontend_feature_flag limit_feature_flag= limit_feature_flag_for_override= ].freeze + EXPERIMENT_METHODS + RUGGED_METHODS + WORKER_METHODS |