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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-09 12:22:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-09 12:22:41 +0300
commit65688a509249eb3be8ea4687d3fe6d1432a47392 (patch)
treedffc9c087dc2eda02e4656d5a0b16b5d7051e69f /rubocop
parent4b8939db3d80469826a62f1409b921f96dac2498 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/graphql/descriptions.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/rubocop/cop/graphql/descriptions.rb b/rubocop/cop/graphql/descriptions.rb
index a93ebf20e1b..0d69fd55931 100644
--- a/rubocop/cop/graphql/descriptions.rb
+++ b/rubocop/cop/graphql/descriptions.rb
@@ -32,7 +32,7 @@
#
# field :some_field,
# GraphQL::Types::String,
-# description: "A thorough and compelling description."
+# description: "Thorough and compelling description."
# end
#
# class GoodEnum
@@ -43,8 +43,10 @@ module RuboCop
module Cop
module Graphql
class Descriptions < RuboCop::Cop::Cop
- MSG_NO_DESCRIPTION = 'Please add a `description` property.'
- MSG_NO_PERIOD = '`description` strings must end with a `.`.'
+ 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}"
+ MSG_BAD_START = "`description` strings should not start with \"A...\" or \"The...\". #{MSG_STYLE_GUIDE_LINK}"
def_node_matcher :graphql_describable?, <<~PATTERN
(send nil? {:field :argument :value} ...)
@@ -75,6 +77,7 @@ module RuboCop
return add_offense(node, location: :expression, message: MSG_NO_DESCRIPTION) unless description
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
# Autocorrect missing periods at end of description.
@@ -100,12 +103,19 @@ module RuboCop
end
def no_period?(description)
- # Test that the description node is a `:str` (as opposed to
- # a `#copy_field_description` call) before checking.
- description.type == :str && !description.value.strip.end_with?('.')
+ string?(description) && !description.value.strip.end_with?('.')
end
- # Returns a Parser::Source::Range that ends just before the final String delimiter.
+ def bad_start?(description)
+ string?(description) && description.value.strip.downcase.start_with?('a ', 'the ')
+ end
+
+ # Returns true if `description` node is a `:str` (as opposed to a `#copy_field_description` call)
+ def string?(description)
+ description.type == :str
+ end
+
+ # Returns a `Parser::Source::Range` that ends just before the final `String` delimiter.
def before_end_quote(string)
return string.source_range.adjust(end_pos: -1) unless string.heredoc?