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 | |
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')
-rw-r--r-- | rubocop/cop/database/disable_referential_integrity.rb | 32 | ||||
-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 | ||||
-rw-r--r-- | rubocop/cop/qa/duplicate_testcase_link.rb | 46 | ||||
-rw-r--r-- | rubocop/cop/qa/testcase_link_format.rb | 45 |
5 files changed, 76 insertions, 91 deletions
diff --git a/rubocop/cop/database/disable_referential_integrity.rb b/rubocop/cop/database/disable_referential_integrity.rb new file mode 100644 index 00000000000..80d52678011 --- /dev/null +++ b/rubocop/cop/database/disable_referential_integrity.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Database + # Cop that checks if 'disable_referential_integrity' method is called. + class DisableReferentialIntegrity < RuboCop::Cop::Cop + MSG = <<~TEXT + Do not use `disable_referential_integrity`, disable triggers in a safe + transaction instead. Follow the format: + BEGIN; + ALTER TABLE my_table DISABLE TRIGGER ALL; + -- execute query that requires disabled triggers + ALTER TABLE my_table ENABLE TRIGGER ALL; + COMMIT; + TEXT + + def_node_matcher :disable_referential_integrity?, <<~PATTERN + (send _ :disable_referential_integrity) + PATTERN + + RESTRICT_ON_SEND = %i[disable_referential_integrity].freeze + + def on_send(node) + return unless disable_referential_integrity?(node) + + add_offense(node) + end + end + end + end +end 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 diff --git a/rubocop/cop/qa/duplicate_testcase_link.rb b/rubocop/cop/qa/duplicate_testcase_link.rb deleted file mode 100644 index 82549707a83..00000000000 --- a/rubocop/cop/qa/duplicate_testcase_link.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module QA - # This cop checks for duplicate testcase links across e2e specs - # - # @example - # - # # bad - # it 'some test', testcase: '(...)/quality/test_cases/1892' - # it 'another test, testcase: '(...)/quality/test_cases/1892' - # - # # good - # it 'some test', testcase: '(...)/quality/test_cases/1892' - # it 'another test, testcase: '(...)/quality/test_cases/1894' - class DuplicateTestcaseLink < RuboCop::Cop::Cop - MESSAGE = "Don't reuse the same testcase link in different tests. Replace one of `%s`." - - @testcase_set = Set.new - - def_node_matcher :duplicate_testcase_link, <<~PATTERN - (block - (send nil? ... - ... - (hash - (pair - (sym :testcase) - (str $_))...)...)...) - PATTERN - - def on_block(node) - duplicate_testcase_link(node) do |link| - break unless self.class.duplicate?(link) - - add_offense(node, message: MESSAGE % link) - end - end - - def self.duplicate?(link) - !@testcase_set.add?(link) - end - end - end - end -end diff --git a/rubocop/cop/qa/testcase_link_format.rb b/rubocop/cop/qa/testcase_link_format.rb deleted file mode 100644 index 683098e6eec..00000000000 --- a/rubocop/cop/qa/testcase_link_format.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../qa_helpers' - -module RuboCop - module Cop - module QA - # This cop checks for correct format of testcase links across e2e specs - # - # @example - # - # # bad - # it 'some test', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/557' - # it 'another test, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/2455' - # - # # good - # it 'some test', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/348312' - # it 'another test, testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/348236' - class TestcaseLinkFormat < RuboCop::Cop::Cop - include QAHelpers - - TESTCASE_FORMAT = %r{https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/\d+}.freeze - MESSAGE = "Testcase link format incorrect. Please link a test case from the GitLab project. See: https://docs.gitlab.com/ee/development/testing_guide/end_to_end/best_practices.html#link-a-test-to-its-test-case." - - def_node_matcher :testcase_link_format, <<~PATTERN - (block - (send nil? ... - ... - (hash - (pair - (sym :testcase) - (str $_))...)...)...) - PATTERN - - def on_block(node) - return unless in_qa_file?(node) - - testcase_link_format(node) do |link| - add_offense(node, message: MESSAGE % link) unless TESTCASE_FORMAT =~ link - end - end - end - end - end -end |