diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-13 12:08:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-13 12:08:20 +0300 |
commit | 2d8c28f1d32709280506507f3b6e6d2da7440da9 (patch) | |
tree | 9ed8319e6cdddd1e03493b82c552ec8df590027f /rubocop | |
parent | 99bb3eedd09ba55be5934da8138e2678a3e1be4d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/graphql/descriptions.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/descriptions.rb b/rubocop/cop/graphql/descriptions.rb index 0234ad99521..239f5b966a4 100644 --- a/rubocop/cop/graphql/descriptions.rb +++ b/rubocop/cop/graphql/descriptions.rb @@ -3,6 +3,11 @@ # This cop checks for missing GraphQL descriptions and enforces the description style guide: # https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#description-style-guide # +# @safety +# This cop is unsafe because not all cases of "this" can be substituted with +# "the". This will require a technical writer to assist with the alternative, +# proper grammar that can be used for that particular GraphQL descriptions. +# # @examples # # # bad @@ -94,6 +99,7 @@ module RuboCop next unless description corrector.insert_after(before_end_quote(description), '.') if no_period?(description) + corrector.replace(locate_this(description), 'the') if contains_demonstrative_this?(description) end end @@ -134,6 +140,14 @@ module RuboCop adjust = heredoc_source.index(/\s+\Z/) - heredoc_source.length string.location.heredoc_body.adjust(end_pos: adjust) end + + # Returns a `Parser::Source::Range` of the first `this` encountered + def locate_this(string) + target = 'this' + range = string.heredoc? ? string.location.heredoc_body : string.location.expression + index = range.source.index(target) + range.adjust(begin_pos: index, end_pos: (index + target.length) - range.length) + end end end end |