Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/graphql')
-rw-r--r--rubocop/cop/graphql/authorize_types.rb4
-rw-r--r--rubocop/cop/graphql/descriptions.rb20
-rw-r--r--rubocop/cop/graphql/gid_expected_type.rb2
-rw-r--r--rubocop/cop/graphql/graphql_name_position.rb4
-rw-r--r--rubocop/cop/graphql/id_type.rb2
-rw-r--r--rubocop/cop/graphql/json_type.rb4
-rw-r--r--rubocop/cop/graphql/old_types.rb4
-rw-r--r--rubocop/cop/graphql/resolver_type.rb4
8 files changed, 24 insertions, 20 deletions
diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb
index c96919343d6..7bd2cd9f7ef 100644
--- a/rubocop/cop/graphql/authorize_types.rb
+++ b/rubocop/cop/graphql/authorize_types.rb
@@ -3,7 +3,7 @@
module RuboCop
module Cop
module Graphql
- class AuthorizeTypes < RuboCop::Cop::Cop
+ class AuthorizeTypes < RuboCop::Cop::Base
MSG = 'Add an `authorize :ability` call to the type: '\
'https://docs.gitlab.com/ee/development/graphql_guide/authorization.html#type-authorization'
@@ -19,7 +19,7 @@ module RuboCop
return if allowed?(class_constant(node))
return if allowed?(superclass_constant(node))
- add_offense(node, location: :expression) unless authorize?(node)
+ add_offense(node) unless authorize?(node)
end
private
diff --git a/rubocop/cop/graphql/descriptions.rb b/rubocop/cop/graphql/descriptions.rb
index 0d69fd55931..3c945507699 100644
--- a/rubocop/cop/graphql/descriptions.rb
+++ b/rubocop/cop/graphql/descriptions.rb
@@ -42,7 +42,9 @@
module RuboCop
module Cop
module Graphql
- class Descriptions < RuboCop::Cop::Cop
+ class Descriptions < RuboCop::Cop::Base
+ extend RuboCop::Cop::AutoCorrector
+
MSG_STYLE_GUIDE_LINK = 'See the description style guide: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#description-style-guide'
MSG_NO_DESCRIPTION = "Please add a `description` property. #{MSG_STYLE_GUIDE_LINK}"
MSG_NO_PERIOD = "`description` strings must end with a `.`. #{MSG_STYLE_GUIDE_LINK}"
@@ -74,15 +76,17 @@ module RuboCop
description = locate_description(node)
- return add_offense(node, location: :expression, message: MSG_NO_DESCRIPTION) unless description
+ message = if description.nil?
+ MSG_NO_DESCRIPTION
+ elsif no_period?(description)
+ MSG_NO_PERIOD
+ elsif bad_start?(description)
+ MSG_BAD_START
+ end
- add_offense(node, location: :expression, message: MSG_NO_PERIOD) if no_period?(description)
- add_offense(node, location: :expression, message: MSG_BAD_START) if bad_start?(description)
- end
+ return unless message
- # Autocorrect missing periods at end of description.
- def autocorrect(node)
- lambda do |corrector|
+ add_offense(node, message: message) do |corrector|
description = locate_description(node)
next unless description
diff --git a/rubocop/cop/graphql/gid_expected_type.rb b/rubocop/cop/graphql/gid_expected_type.rb
index 354c5516752..7e802e6d2db 100644
--- a/rubocop/cop/graphql/gid_expected_type.rb
+++ b/rubocop/cop/graphql/gid_expected_type.rb
@@ -3,7 +3,7 @@
module RuboCop
module Cop
module Graphql
- class GIDExpectedType < RuboCop::Cop::Cop
+ class GIDExpectedType < RuboCop::Cop::Base
MSG = 'Add an expected_type parameter to #object_from_id calls if possible.'
def_node_search :id_from_object?, <<~PATTERN
diff --git a/rubocop/cop/graphql/graphql_name_position.rb b/rubocop/cop/graphql/graphql_name_position.rb
index f18d65588cc..b876fb5b088 100644
--- a/rubocop/cop/graphql/graphql_name_position.rb
+++ b/rubocop/cop/graphql/graphql_name_position.rb
@@ -20,7 +20,7 @@
module RuboCop
module Cop
module Graphql
- class GraphqlNamePosition < RuboCop::Cop::Cop
+ class GraphqlNamePosition < RuboCop::Cop::Base
MSG = '`graphql_name` should be the first line of the class: '\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#naming-conventions'
@@ -32,7 +32,7 @@ module RuboCop
return unless graphql_name?(node)
return if node.body.single_line?
- add_offense(node, location: :expression) unless graphql_name?(node.body.children.first)
+ add_offense(node) unless graphql_name?(node.body.children.first)
end
end
end
diff --git a/rubocop/cop/graphql/id_type.rb b/rubocop/cop/graphql/id_type.rb
index ba973242efa..eb677aa4507 100644
--- a/rubocop/cop/graphql/id_type.rb
+++ b/rubocop/cop/graphql/id_type.rb
@@ -3,7 +3,7 @@
module RuboCop
module Cop
module Graphql
- class IDType < RuboCop::Cop::Cop
+ class IDType < RuboCop::Cop::Base
MSG = 'Do not use GraphQL::Types::ID, use a specific GlobalIDType instead'
WHITELISTED_ARGUMENTS = %i[iid full_path project_path group_path target_project_path namespace_path].freeze
diff --git a/rubocop/cop/graphql/json_type.rb b/rubocop/cop/graphql/json_type.rb
index 8518a771cbd..2525dc427b8 100644
--- a/rubocop/cop/graphql/json_type.rb
+++ b/rubocop/cop/graphql/json_type.rb
@@ -18,7 +18,7 @@
module RuboCop
module Cop
module Graphql
- class JSONType < RuboCop::Cop::Cop
+ class JSONType < RuboCop::Cop::Base
MSG = 'Avoid using GraphQL::Types::JSON. See: ' \
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#json'
@@ -32,7 +32,7 @@ module RuboCop
PATTERN
def on_send(node)
- add_offense(node, location: :expression) if has_json_type?(node)
+ add_offense(node) if has_json_type?(node)
end
end
end
diff --git a/rubocop/cop/graphql/old_types.rb b/rubocop/cop/graphql/old_types.rb
index 61e8ac92dc7..9bbda4732dd 100644
--- a/rubocop/cop/graphql/old_types.rb
+++ b/rubocop/cop/graphql/old_types.rb
@@ -19,7 +19,7 @@
module RuboCop
module Cop
module Graphql
- class OldTypes < RuboCop::Cop::Cop
+ class OldTypes < RuboCop::Cop::Base
MSG_ID = 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead'
MSG_INT = 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead'
MSG_STRING = 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead'
@@ -37,7 +37,7 @@ module RuboCop
old_constant = has_old_type?(node)
return unless old_constant
- add_offense(node, location: :expression, message: "#{self.class}::MSG_#{old_constant[0..-6]}".constantize)
+ add_offense(node, message: "#{self.class}::MSG_#{old_constant[0..-6]}".constantize)
end
end
end
diff --git a/rubocop/cop/graphql/resolver_type.rb b/rubocop/cop/graphql/resolver_type.rb
index e9fa768fd3e..34f1d43fc2a 100644
--- a/rubocop/cop/graphql/resolver_type.rb
+++ b/rubocop/cop/graphql/resolver_type.rb
@@ -23,7 +23,7 @@
module RuboCop
module Cop
module Graphql
- class ResolverType < RuboCop::Cop::Cop
+ class ResolverType < RuboCop::Cop::Base
MSG = 'Missing type annotation: Please add `type` DSL method call. ' \
'e.g: type UserType.connection_type, null: true'
@@ -32,7 +32,7 @@ module RuboCop
PATTERN
def on_class(node)
- add_offense(node, location: :expression) if resolver?(node) && !typed?(node)
+ add_offense(node) if resolver?(node) && !typed?(node)
end
private