rubocop-graphql 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/graphql/argument_description.rb +2 -2
- data/lib/rubocop/cop/graphql/object_description.rb +67 -0
- data/lib/rubocop/cop/graphql_cops.rb +1 -0
- data/lib/rubocop/graphql/field/kwargs.rb +1 -1
- data/lib/rubocop/graphql/node_pattern.rb +3 -3
- data/lib/rubocop/graphql/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 328663a392bcbb8e7a53bfaf2ba8e7323e9382893c8f290fa6b40e965155ebe1
|
4
|
+
data.tar.gz: cb76dad975e6dab191f1fac2ae6c45b677fb06bddbb26f36494a18108e1acf56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a87c4e9ee55fb176eaf98ba520a7942c7a4ee4af3531b7cc90a0039f739a5e5400ce4e21b0d694e59b00ca0bb2771585f07a50699c55496a8794eec1a38900f3
|
7
|
+
data.tar.gz: cedeb68f255f806a1e12de6776722f3aadce5f82fe7c0e4ace7979593d7f84abc8f27fee1cff5ced953076f88247e4aadf0599f30b02b5a35436d946f976a353
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RuboCop::GraphQL
|
2
2
|
|
3
3
|
[Rubocop](https://github.com/rubocop-hq/rubocop) extension for enforcing [graphql-ruby](https://github.com/rmosolgo/graphql-ruby) best practices.
|
4
4
|
|
@@ -24,7 +24,7 @@ gem 'rubocop-graphql', require: false
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
You need to tell RuboCop to load the
|
27
|
+
You need to tell RuboCop to load the GraphQL extension. There are three ways to do this:
|
28
28
|
|
29
29
|
### RuboCop configuration file
|
30
30
|
|
@@ -42,7 +42,7 @@ require:
|
|
42
42
|
- rubocop-graphql
|
43
43
|
```
|
44
44
|
|
45
|
-
Now you can run `rubocop` and it will automatically load the RuboCop
|
45
|
+
Now you can run `rubocop` and it will automatically load the RuboCop GraphQL cops together with the standard cops.
|
46
46
|
|
47
47
|
### Command line
|
48
48
|
|
@@ -62,7 +62,7 @@ end
|
|
62
62
|
|
63
63
|
All cops are located under [`lib/rubocop/cop/graphql`](lib/rubocop/cop/graphql), and contain examples and documentation.
|
64
64
|
|
65
|
-
In your `.rubocop.yml`, you may treat the
|
65
|
+
In your `.rubocop.yml`, you may treat the GraphQL cops just like any other cop. For example:
|
66
66
|
|
67
67
|
```yaml
|
68
68
|
GraphQL/ResolverMethodLength:
|
data/config/default.yml
CHANGED
@@ -9,13 +9,13 @@ module RuboCop
|
|
9
9
|
# # good
|
10
10
|
#
|
11
11
|
# class BanUser < BaseMutation
|
12
|
-
# argument :uuid, ID, required: true
|
12
|
+
# argument :uuid, ID, required: true, description: "UUID of the user to ban"
|
13
13
|
# end
|
14
14
|
#
|
15
15
|
# # bad
|
16
16
|
#
|
17
17
|
# class BanUser < BaseMutation
|
18
|
-
# argument :uuid, ID, required: true
|
18
|
+
# argument :uuid, ID, required: true
|
19
19
|
# end
|
20
20
|
#
|
21
21
|
class ArgumentDescription < Cop
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module GraphQL
|
6
|
+
# This cop checks if a type (object, input, interface, scalar, union, mutation, subscription, and resolver) has a description.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # good
|
10
|
+
#
|
11
|
+
# class Types::UserType < Types::BaseObject
|
12
|
+
# description "Represents application user"
|
13
|
+
# # ...
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
#
|
18
|
+
# class Types::UserType < Types::BaseObject
|
19
|
+
# # ...
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class ObjectDescription < Cop
|
23
|
+
include RuboCop::GraphQL::NodePattern
|
24
|
+
|
25
|
+
MSG = "Missing type description"
|
26
|
+
|
27
|
+
def_node_matcher :has_i18n_description?, <<~PATTERN
|
28
|
+
(send nil? :description (send (const nil? :I18n) :t ...))
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def_node_matcher :has_string_description?, <<~PATTERN
|
32
|
+
(send nil? :description (:str $_))
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :interface?, <<~PATTERN
|
36
|
+
(send nil? :include (const ...))
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_class(node)
|
40
|
+
return if child_nodes(node).find { |child_node| has_description?(child_node) }
|
41
|
+
|
42
|
+
add_offense(node.identifier)
|
43
|
+
end
|
44
|
+
|
45
|
+
def on_module(node)
|
46
|
+
return if child_nodes(node).none? { |child_node| interface?(child_node) }
|
47
|
+
|
48
|
+
add_offense(node.identifier) if child_nodes(node).none? { |child_node| has_description?(child_node) }
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def has_description?(node)
|
54
|
+
has_i18n_description?(node) || has_string_description?(node)
|
55
|
+
end
|
56
|
+
|
57
|
+
def child_nodes(node)
|
58
|
+
if node.body.instance_of? RuboCop::AST::Node
|
59
|
+
node.body.child_nodes
|
60
|
+
else
|
61
|
+
node.child_nodes
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -6,18 +6,18 @@ module RuboCop
|
|
6
6
|
extend RuboCop::NodePattern::Macros
|
7
7
|
|
8
8
|
def_node_matcher :field_definition?, <<~PATTERN
|
9
|
-
(send nil? :field ...)
|
9
|
+
(send nil? :field (:sym _) ...)
|
10
10
|
PATTERN
|
11
11
|
|
12
12
|
def_node_matcher :field_definition_with_body?, <<~PATTERN
|
13
13
|
(block
|
14
|
-
(send nil? :field ...)
|
14
|
+
(send nil? :field (:sym _) ...)
|
15
15
|
...
|
16
16
|
)
|
17
17
|
PATTERN
|
18
18
|
|
19
19
|
def_node_matcher :argument?, <<~PATTERN
|
20
|
-
(send nil? :argument ...)
|
20
|
+
(send nil? :argument (:sym _) ...)
|
21
21
|
PATTERN
|
22
22
|
|
23
23
|
def field?(node)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Tsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/rubocop/cop/graphql/field_description.rb
|
87
87
|
- lib/rubocop/cop/graphql/field_method.rb
|
88
88
|
- lib/rubocop/cop/graphql/field_name.rb
|
89
|
+
- lib/rubocop/cop/graphql/object_description.rb
|
89
90
|
- lib/rubocop/cop/graphql/resolver_method_length.rb
|
90
91
|
- lib/rubocop/cop/graphql_cops.rb
|
91
92
|
- lib/rubocop/graphql.rb
|