diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /rubocop/cop/gitlab/avoid_feature_category_not_owned.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'rubocop/cop/gitlab/avoid_feature_category_not_owned.rb')
-rw-r--r-- | rubocop/cop/gitlab/avoid_feature_category_not_owned.rb | 43 |
1 files changed, 43 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 |