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
aa8a5940
Commit
aa8a5940
authored
Oct 09, 2020
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RuboCop: Add cop for GraphQL::ID_TYPE
Let's use the more restrictive Types::GlobalIDType when possible
parent
21dfdd32
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
0 deletions
+112
-0
.rubocop.yml
.rubocop.yml
+6
-0
.rubocop_todo.yml
.rubocop_todo.yml
+41
-0
rubocop/cop/graphql/id_type.rb
rubocop/cop/graphql/id_type.rb
+29
-0
spec/rubocop/cop/graphql/id_type_spec.rb
spec/rubocop/cop/graphql/id_type_spec.rb
+36
-0
No files found.
.rubocop.yml
View file @
aa8a5940
...
...
@@ -371,6 +371,12 @@ Graphql/GIDExpectedType:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
Graphql/IDType
:
Enabled
:
true
Include
:
-
'
app/graphql/**/*'
-
'
ee/app/graphql/**/*'
Graphql/JSONType
:
Enabled
:
true
Include
:
...
...
.rubocop_todo.yml
View file @
aa8a5940
...
...
@@ -1245,3 +1245,44 @@ RSpec/TimecopFreeze:
-
'
spec/support/shared_examples/workers/concerns/reenqueuer_shared_examples.rb'
-
'
spec/workers/concerns/reenqueuer_spec.rb'
-
'
spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb'
# Offense count: 43
Graphql/IDType
:
Exclude
:
-
'
ee/app/graphql/ee/mutations/issues/update.rb'
-
'
ee/app/graphql/ee/types/boards/board_issue_input_base_type.rb'
-
'
ee/app/graphql/mutations/boards/lists/update_limit_metrics.rb'
-
'
ee/app/graphql/mutations/instance_security_dashboard/remove_project.rb'
-
'
ee/app/graphql/mutations/issues/set_epic.rb'
-
'
ee/app/graphql/mutations/issues/set_iteration.rb'
-
'
ee/app/graphql/mutations/iterations/update.rb'
-
'
ee/app/graphql/resolvers/iterations_resolver.rb'
-
'
app/graphql/mutations/boards/create.rb'
-
'
app/graphql/mutations/boards/issues/issue_move_list.rb'
-
'
app/graphql/mutations/boards/lists/update.rb'
-
'
app/graphql/mutations/discussions/toggle_resolve.rb'
-
'
app/graphql/mutations/issues/update.rb'
-
'
app/graphql/mutations/merge_requests/set_milestone.rb'
-
'
app/graphql/mutations/metrics/dashboard/annotations/delete.rb'
-
'
app/graphql/mutations/notes/create/note.rb'
-
'
app/graphql/mutations/notes/update/base.rb'
-
'
app/graphql/mutations/snippets/destroy.rb'
-
'
app/graphql/mutations/snippets/mark_as_spam.rb'
-
'
app/graphql/mutations/snippets/update.rb'
-
'
app/graphql/mutations/todos/mark_done.rb'
-
'
app/graphql/mutations/todos/restore.rb'
-
'
app/graphql/resolvers/board_lists_resolver.rb'
-
'
app/graphql/resolvers/board_resolver.rb'
-
'
app/graphql/resolvers/boards_resolver.rb'
-
'
app/graphql/resolvers/design_management/design_at_version_resolver.rb'
-
'
app/graphql/resolvers/design_management/design_resolver.rb'
-
'
app/graphql/resolvers/design_management/designs_resolver.rb'
-
'
app/graphql/resolvers/design_management/version/design_at_version_resolver.rb'
-
'
app/graphql/resolvers/design_management/version_in_collection_resolver.rb'
-
'
app/graphql/resolvers/design_management/version_resolver.rb'
-
'
app/graphql/resolvers/design_management/versions_resolver.rb'
-
'
app/graphql/resolvers/error_tracking/sentry_detailed_error_resolver.rb'
-
'
app/graphql/resolvers/error_tracking/sentry_error_stack_trace_resolver.rb'
-
'
app/graphql/resolvers/snippets_resolver.rb'
-
'
app/graphql/resolvers/user_merge_requests_resolver.rb'
-
'
app/graphql/resolvers/user_resolver.rb'
rubocop/cop/graphql/id_type.rb
0 → 100644
View file @
aa8a5940
# 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]
.
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
spec/rubocop/cop/graphql/id_type_spec.rb
0 → 100644
View file @
aa8a5940
# frozen_string_literal: true
require
'fast_spec_helper'
require
'rubocop'
require_relative
'../../../../rubocop/cop/graphql/id_type'
RSpec
.
describe
RuboCop
::
Cop
::
Graphql
::
IDType
,
type: :rubocop
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
it
'adds an offense when GraphQL::ID_TYPE is used as a param to #argument'
do
inspect_source
(
<<~
TYPE
)
argument :some_arg, GraphQL::ID_TYPE, some: other, params: do_not_matter
TYPE
expect
(
cop
.
offenses
.
size
).
to
eq
1
end
context
'whitelisted arguments'
do
RuboCop
::
Cop
::
Graphql
::
IDType
::
WHITELISTED_ARGUMENTS
.
each
do
|
arg
|
it
"does not add an offense for calls to #argument with
#{
arg
}
as argument name"
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
argument
#{
arg
}
, GraphQL::ID_TYPE, some: other, params: do_not_matter
TYPE
end
end
end
it
'does not add an offense for calls to #argument without GraphQL::ID_TYPE'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
argument :some_arg, ::Types::GlobalIDType[::Awardable], some: other, params: do_not_matter
TYPE
end
end
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