diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /rubocop/cop/graphql | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'rubocop/cop/graphql')
-rw-r--r-- | rubocop/cop/graphql/gid_expected_type.rb | 21 | ||||
-rw-r--r-- | rubocop/cop/graphql/id_type.rb | 29 |
2 files changed, 50 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/gid_expected_type.rb b/rubocop/cop/graphql/gid_expected_type.rb new file mode 100644 index 00000000000..354c5516752 --- /dev/null +++ b/rubocop/cop/graphql/gid_expected_type.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Graphql + class GIDExpectedType < RuboCop::Cop::Cop + MSG = 'Add an expected_type parameter to #object_from_id calls if possible.' + + def_node_search :id_from_object?, <<~PATTERN + (send ... :object_from_id (...)) + PATTERN + + def on_send(node) + return unless id_from_object?(node) + + add_offense(node) + end + end + end + end +end diff --git a/rubocop/cop/graphql/id_type.rb b/rubocop/cop/graphql/id_type.rb new file mode 100644 index 00000000000..96f90ac136a --- /dev/null +++ b/rubocop/cop/graphql/id_type.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Graphql + class IDType < RuboCop::Cop::Cop + MSG = 'Do not use GraphQL::ID_TYPE, use a specific GlobalIDType instead' + + WHITELISTED_ARGUMENTS = %i[iid full_path project_path group_path target_project_path].freeze + + def_node_search :graphql_id_type?, <<~PATTERN + (send nil? :argument (_ #does_not_match?) (const (const nil? :GraphQL) :ID_TYPE) ...) + PATTERN + + def on_send(node) + return unless graphql_id_type?(node) + + add_offense(node) + end + + private + + def does_not_match?(arg) + !WHITELISTED_ARGUMENTS.include?(arg) + end + end + end + end +end |