diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 13:37:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 13:37:47 +0000 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /rubocop | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) | |
download | gitlab-ce-aee0a117a889461ce8ced6fcf73207fe017f1d99.tar.gz |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/code_reuse_helpers.rb | 8 | ||||
-rw-r--r-- | rubocop/cop/gitlab/mark_used_feature_flags.rb | 6 | ||||
-rw-r--r-- | rubocop/cop/graphql/authorize_types.rb | 4 | ||||
-rw-r--r-- | rubocop/cop/graphql/old_types.rb | 3 | ||||
-rw-r--r-- | rubocop/cop/migration/schedule_async.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/project_path_helper.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/qa/testcase_link_format.rb | 45 | ||||
-rw-r--r-- | rubocop/cop/static_translation_definition.rb | 10 |
8 files changed, 68 insertions, 12 deletions
diff --git a/rubocop/code_reuse_helpers.rb b/rubocop/code_reuse_helpers.rb index 283c43de227..6ea12999cae 100644 --- a/rubocop/code_reuse_helpers.rb +++ b/rubocop/code_reuse_helpers.rb @@ -180,5 +180,13 @@ module RuboCop def rails_root File.expand_path('..', __dir__) end + + def ee? + File.exist?(File.expand_path('../ee/app/models/license.rb', __dir__)) && !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) + end + + def jh? + ee? && Dir.exist?(File.expand_path('../jh', __dir__)) && !%w[true 1].include?(ENV['EE_ONLY'].to_s) + end end end diff --git a/rubocop/cop/gitlab/mark_used_feature_flags.rb b/rubocop/cop/gitlab/mark_used_feature_flags.rb index d3c5cfb827e..4d9fc6148fa 100644 --- a/rubocop/cop/gitlab/mark_used_feature_flags.rb +++ b/rubocop/cop/gitlab/mark_used_feature_flags.rb @@ -255,14 +255,12 @@ module RuboCop ] # For EE additionally process `ee/` feature flags - is_ee = File.exist?(File.expand_path('../../../ee/app/models/license.rb', __dir__)) && !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) - if is_ee + if ee? flags_paths << 'ee/config/feature_flags/**/*.yml' end # For JH additionally process `jh/` feature flags - is_jh = is_ee && Dir.exist?(File.expand_path('../../../jh', __dir__)) && !%w[true 1].include?(ENV['EE_ONLY'].to_s) - if is_jh + if jh? flags_paths << 'jh/config/feature_flags/**/*.yml' end diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb index 180a1a27a85..c96919343d6 100644 --- a/rubocop/cop/graphql/authorize_types.rb +++ b/rubocop/cop/graphql/authorize_types.rb @@ -5,10 +5,10 @@ module RuboCop module Graphql class AuthorizeTypes < RuboCop::Cop::Cop MSG = 'Add an `authorize :ability` call to the type: '\ - 'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization' + 'https://docs.gitlab.com/ee/development/graphql_guide/authorization.html#type-authorization' # We want to exclude our own basetypes and scalars - ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType SubscriptionType + ALLOWED_TYPES = %w[BaseEnum BaseEdge BaseScalar BasePermissionType MutationType SubscriptionType QueryType GraphQL::Schema BaseUnion BaseInputObject].freeze def_node_search :authorize?, <<~PATTERN diff --git a/rubocop/cop/graphql/old_types.rb b/rubocop/cop/graphql/old_types.rb index 2df594c7016..61e8ac92dc7 100644 --- a/rubocop/cop/graphql/old_types.rb +++ b/rubocop/cop/graphql/old_types.rb @@ -24,11 +24,12 @@ module RuboCop MSG_INT = 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead' MSG_STRING = 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead' MSG_BOOLEAN = 'Avoid using GraphQL::BOOLEAN_TYPE. Use GraphQL::Types::Boolean instead' + MSG_FLOAT = 'Avoid using GraphQL::FLOAT_TYPE. Use GraphQL::Types::Float instead' def_node_matcher :has_old_type?, <<~PATTERN (send nil? {:field :argument} (sym _) - (const (const nil? :GraphQL) ${:ID_TYPE :INT_TYPE :STRING_TYPE :BOOLEAN_TYPE}) + (const {(const nil? :GraphQL) (const (cbase) :GraphQL)} ${:ID_TYPE :INT_TYPE :STRING_TYPE :BOOLEAN_TYPE :FLOAT_TYPE}) (...)?) PATTERN diff --git a/rubocop/cop/migration/schedule_async.rb b/rubocop/cop/migration/schedule_async.rb index f296628c3d6..74bd2baffa9 100644 --- a/rubocop/cop/migration/schedule_async.rb +++ b/rubocop/cop/migration/schedule_async.rb @@ -46,7 +46,7 @@ module RuboCop end def arguments(node) - node.children[2..-1] + node.children[2..] end end end diff --git a/rubocop/cop/project_path_helper.rb b/rubocop/cop/project_path_helper.rb index ec3f847faf9..0d12f2d2b12 100644 --- a/rubocop/cop/project_path_helper.rb +++ b/rubocop/cop/project_path_helper.rb @@ -46,7 +46,7 @@ module RuboCop end def arguments(node) - node.children[2..-1] + node.children[2..] end end end diff --git a/rubocop/cop/qa/testcase_link_format.rb b/rubocop/cop/qa/testcase_link_format.rb new file mode 100644 index 00000000000..683098e6eec --- /dev/null +++ b/rubocop/cop/qa/testcase_link_format.rb @@ -0,0 +1,45 @@ +# 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 diff --git a/rubocop/cop/static_translation_definition.rb b/rubocop/cop/static_translation_definition.rb index ac50fd94884..3475a2b3dca 100644 --- a/rubocop/cop/static_translation_definition.rb +++ b/rubocop/cop/static_translation_definition.rb @@ -8,11 +8,15 @@ module RuboCop TRANSLATION_METHODS = %i[_ s_ n_].freeze def_node_matcher :translation_method?, <<~PATTERN - (send _ _ str*) + (send _ _ str*) PATTERN def_node_matcher :lambda_node?, <<~PATTERN - (send _ :lambda) + (send _ :lambda) + PATTERN + + def_node_matcher :struct_constant_assignment?, <<~PATTERN + (casgn _ _ `(const _ :Struct)) PATTERN def on_send(node) @@ -27,7 +31,7 @@ module RuboCop receiver, _ = *ancestor break if lambda_node?(receiver) # translations defined in lambda nodes should be allowed - if constant_assignment?(ancestor) + if constant_assignment?(ancestor) && !struct_constant_assignment?(ancestor) add_offense(node, location: :expression) break |