Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b7fb0ea1
Commit
b7fb0ea1
authored
Aug 09, 2021
by
Luke Duncalfe
Committed by
Thong Kuah
Aug 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce GraphQL descriptions styleguide for A/The
parent
a87a3d2c
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
373 additions
and
18 deletions
+373
-18
.rubocop_manual_todo.yml
.rubocop_manual_todo.yml
+267
-0
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+1
-1
rubocop/cop/graphql/descriptions.rb
rubocop/cop/graphql/descriptions.rb
+17
-7
spec/rubocop/cop/graphql/descriptions_spec.rb
spec/rubocop/cop/graphql/descriptions_spec.rb
+88
-10
No files found.
.rubocop_manual_todo.yml
View file @
b7fb0ea1
This diff is collapsed.
Click to expand it.
doc/development/api_graphql_styleguide.md
View file @
b7fb0ea1
...
...
@@ -837,7 +837,7 @@ descriptions:
-
Mention the name of the resource in the description. Example:
`'Labels of the issue'`
(issue being the resource).
-
Use
`"{x} of the {y}"`
where possible. Example:
`'Title of the issue'`
.
Do not start descriptions with
`The`
.
Do not start descriptions with
`The`
or
`A`
, for consistency and conciseness
.
-
Descriptions of
`GraphQL::Types::Boolean`
fields should answer the question: "What does
this field do?". Example:
`'Indicates project has a Git repository'`
.
-
Always include the word
`"timestamp"`
when describing an argument or
...
...
rubocop/cop/graphql/descriptions.rb
View file @
b7fb0ea1
...
...
@@ -32,7 +32,7 @@
#
# field :some_field,
# GraphQL::Types::String,
# description: "
A t
horough and compelling description."
# description: "
T
horough 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?
...
...
spec/rubocop/cop/graphql/descriptions_spec.rb
View file @
b7fb0ea1
...
...
@@ -12,7 +12,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
Please add a `description` property.
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_DESCRIPTION
}
GraphQL::Types::String,
null: false
end
...
...
@@ -25,10 +25,38 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
`description` strings must end with a `.`.
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_PERIOD
}
GraphQL::Types::String,
null: false,
description: 'A descriptive description'
description: 'Description of a thing'
end
end
TYPE
end
it
'adds an offense when description begins with "A"'
do
expect_offense
(
<<~
TYPE
)
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
GraphQL::Types::String,
null: false,
description: 'A description of the thing.'
end
end
TYPE
end
it
'adds an offense when description begins with "The"'
do
expect_offense
(
<<~
TYPE
)
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
GraphQL::Types::String,
null: false,
description: 'The description of the thing.'
end
end
TYPE
...
...
@@ -41,7 +69,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
field :a_thing,
GraphQL::Types::String,
null: false,
description: '
A descriptive description
.'
description: '
Description of a thing
.'
end
end
TYPE
...
...
@@ -64,7 +92,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
argument :a_thing,
^^^^^^^^^^^^^^^^^^
Please add a `description` property.
^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_DESCRIPTION
}
GraphQL::Types::String,
null: false
end
...
...
@@ -77,7 +105,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
argument :a_thing,
^^^^^^^^^^^^^^^^^^
`description` strings must end with a `.`.
^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_PERIOD
}
GraphQL::Types::String,
null: false,
description: 'Behold! A description'
...
...
@@ -86,6 +114,34 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
TYPE
end
it
'adds an offense when description begins with "A"'
do
expect_offense
(
<<~
TYPE
)
module Types
class FakeType < BaseObject
argument :a_thing,
^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
GraphQL::Types::String,
null: false,
description: 'A description.'
end
end
TYPE
end
it
'adds an offense when description begins with "The"'
do
expect_offense
(
<<~
TYPE
)
module Types
class FakeType < BaseObject
argument :a_thing,
^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
GraphQL::Types::String,
null: false,
description: 'The description.'
end
end
TYPE
end
it
'does not add an offense when description is correct'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
...
...
@@ -106,7 +162,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo'
^^^^^^^^^^^^^^^^^^^^^^^^^
Please add a `description` property.
^^^^^^^^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_DESCRIPTION
}
end
end
TYPE
...
...
@@ -117,7 +173,29 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo', description: 'bar'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_PERIOD
}
end
end
TYPE
end
it
'adds an offense when description begins with "The"'
do
expect_offense
(
<<~
TYPE
.
strip
)
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo', description: 'The description.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
end
end
TYPE
end
it
'adds an offense when description begins with "A"'
do
expect_offense
(
<<~
TYPE
.
strip
)
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo', description: 'A description.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#{
described_class
::
MSG_BAD_START
}
end
end
TYPE
...
...
@@ -150,7 +228,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
`description` strings must end with a `.`.
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_PERIOD
}
GraphQL::Types::String,
null: false,
description: 'Behold! A description'
...
...
@@ -175,7 +253,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
^^^^^^^^^^^^^^^
`description` strings must end with a `.`.
^^^^^^^^^^^^^^^
#{
described_class
::
MSG_NO_PERIOD
}
GraphQL::Types::String,
null: false,
description: <<~DESC
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment