rubocop-graphql 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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/config/default.yml +72 -0
- data/lib/rubocop-graphql.rb +22 -0
- data/lib/rubocop/cop/graphql/argument_description.rb +36 -0
- data/lib/rubocop/cop/graphql/argument_name.rb +39 -0
- data/lib/rubocop/cop/graphql/cop.rb +92 -0
- data/lib/rubocop/cop/graphql/extract_input_type.rb +41 -0
- data/lib/rubocop/cop/graphql/extract_type.rb +98 -0
- data/lib/rubocop/cop/graphql/field_definitions.rb +159 -0
- data/lib/rubocop/cop/graphql/field_description.rb +36 -0
- data/lib/rubocop/cop/graphql/field_method.rb +79 -0
- data/lib/rubocop/cop/graphql/field_name.rb +39 -0
- data/lib/rubocop/cop/graphql/object_description.rb +67 -0
- data/lib/rubocop/cop/graphql/resolver_method_length.rb +40 -0
- data/lib/rubocop/cop/graphql_cops.rb +14 -0
- data/lib/rubocop/graphql.rb +12 -0
- data/lib/rubocop/graphql/argument.rb +39 -0
- data/lib/rubocop/graphql/argument/block.rb +31 -0
- data/lib/rubocop/graphql/argument/kwargs.rb +32 -0
- data/lib/rubocop/graphql/ext/snake_case.rb +17 -0
- data/lib/rubocop/graphql/field.rb +80 -0
- data/lib/rubocop/graphql/field/block.rb +31 -0
- data/lib/rubocop/graphql/field/kwargs.rb +64 -0
- data/lib/rubocop/graphql/inject.rb +18 -0
- data/lib/rubocop/graphql/node_pattern.rb +28 -0
- data/lib/rubocop/graphql/schema_member.rb +35 -0
- data/lib/rubocop/graphql/version.rb +5 -0
- metadata +130 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Argument
|
6
|
+
extend RuboCop::NodePattern::Macros
|
7
|
+
|
8
|
+
def_node_matcher :argument_description, <<~PATTERN
|
9
|
+
(send nil? :argument _ _ (:str $_) ...)
|
10
|
+
PATTERN
|
11
|
+
|
12
|
+
def_node_matcher :argument_name, <<~PATTERN
|
13
|
+
(send nil? :argument (:sym $_) ...)
|
14
|
+
PATTERN
|
15
|
+
|
16
|
+
attr_reader :node
|
17
|
+
|
18
|
+
def initialize(node)
|
19
|
+
@node = node
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@name ||= argument_name(@node)
|
24
|
+
end
|
25
|
+
|
26
|
+
def description
|
27
|
+
@description ||= argument_description(@node) || kwargs.description || block.description
|
28
|
+
end
|
29
|
+
|
30
|
+
def kwargs
|
31
|
+
@kwargs ||= Argument::Kwargs.new(@node)
|
32
|
+
end
|
33
|
+
|
34
|
+
def block
|
35
|
+
@block ||= Argument::Block.new(@node.parent)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Argument
|
6
|
+
class Block
|
7
|
+
extend RuboCop::NodePattern::Macros
|
8
|
+
|
9
|
+
def_node_matcher :argument_block, <<~PATTERN
|
10
|
+
(block
|
11
|
+
(send nil? :argument ...)
|
12
|
+
(args)
|
13
|
+
$...
|
14
|
+
)
|
15
|
+
PATTERN
|
16
|
+
|
17
|
+
def_node_matcher :description_kwarg?, <<~PATTERN
|
18
|
+
(send nil? :description (str ...))
|
19
|
+
PATTERN
|
20
|
+
|
21
|
+
def initialize(argument_node)
|
22
|
+
@nodes = argument_block(argument_node) || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
@nodes.find { |kwarg| description_kwarg?(kwarg) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Argument
|
6
|
+
class Kwargs
|
7
|
+
extend RuboCop::NodePattern::Macros
|
8
|
+
|
9
|
+
def_node_matcher :argument_kwargs, <<~PATTERN
|
10
|
+
(send nil? :argument
|
11
|
+
...
|
12
|
+
(hash
|
13
|
+
$...
|
14
|
+
)
|
15
|
+
)
|
16
|
+
PATTERN
|
17
|
+
|
18
|
+
def_node_matcher :description_kwarg?, <<~PATTERN
|
19
|
+
(pair (sym :description) ...)
|
20
|
+
PATTERN
|
21
|
+
|
22
|
+
def initialize(argument_node)
|
23
|
+
@nodes = argument_kwargs(argument_node)
|
24
|
+
end
|
25
|
+
|
26
|
+
def description
|
27
|
+
@nodes.find { |kwarg| description_kwarg?(kwarg) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Field
|
6
|
+
extend Forwardable
|
7
|
+
extend RuboCop::NodePattern::Macros
|
8
|
+
|
9
|
+
def_delegators :@node, :sibling_index, :parent
|
10
|
+
|
11
|
+
def_node_matcher :field_name, <<~PATTERN
|
12
|
+
(send nil? :field (:sym $_) ...)
|
13
|
+
PATTERN
|
14
|
+
|
15
|
+
def_node_matcher :field_with_body_name, <<~PATTERN
|
16
|
+
(block
|
17
|
+
(send nil? :field (:sym $_) ...)...)
|
18
|
+
PATTERN
|
19
|
+
|
20
|
+
def_node_matcher :field_description, <<~PATTERN
|
21
|
+
(send nil? :field _ _ (:str $_) ...)
|
22
|
+
PATTERN
|
23
|
+
|
24
|
+
attr_reader :node
|
25
|
+
|
26
|
+
def initialize(node)
|
27
|
+
@node = node
|
28
|
+
end
|
29
|
+
|
30
|
+
def name
|
31
|
+
@name ||= field_name(@node) || field_with_body_name(@node)
|
32
|
+
end
|
33
|
+
|
34
|
+
def underscore_name
|
35
|
+
@underscore_name ||= begin
|
36
|
+
word = name.to_s.dup
|
37
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
38
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
39
|
+
word.tr!("-", "_")
|
40
|
+
word.downcase!
|
41
|
+
word
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def description
|
46
|
+
@description ||= field_description(@node) || kwargs.description || block.description
|
47
|
+
end
|
48
|
+
|
49
|
+
def resolver_method_name
|
50
|
+
kwargs.resolver_method_name || name
|
51
|
+
end
|
52
|
+
|
53
|
+
def kwargs
|
54
|
+
@kwargs ||= Field::Kwargs.new(@node)
|
55
|
+
end
|
56
|
+
|
57
|
+
def block
|
58
|
+
@block ||= Field::Block.new(@node.parent)
|
59
|
+
end
|
60
|
+
|
61
|
+
def schema_member
|
62
|
+
@schema_member ||= SchemaMember.new(root_node)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def root_node
|
68
|
+
@node.ancestors.find { |parent| root_node?(parent) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def root_node?(node)
|
72
|
+
node.parent.nil? || root_with_siblings?(node.parent)
|
73
|
+
end
|
74
|
+
|
75
|
+
def root_with_siblings?(node)
|
76
|
+
node.begin_type? && node.parent.nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Field
|
6
|
+
class Block
|
7
|
+
extend RuboCop::NodePattern::Macros
|
8
|
+
|
9
|
+
def_node_matcher :field_block, <<~PATTERN
|
10
|
+
(block
|
11
|
+
(send nil? :field ...)
|
12
|
+
(args)
|
13
|
+
$...
|
14
|
+
)
|
15
|
+
PATTERN
|
16
|
+
|
17
|
+
def_node_matcher :description_kwarg?, <<~PATTERN
|
18
|
+
(send nil? :description (str ...))
|
19
|
+
PATTERN
|
20
|
+
|
21
|
+
def initialize(field_node)
|
22
|
+
@nodes = field_block(field_node) || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
@nodes.find { |kwarg| description_kwarg?(kwarg) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class Field
|
6
|
+
class Kwargs
|
7
|
+
extend RuboCop::NodePattern::Macros
|
8
|
+
|
9
|
+
def_node_matcher :field_kwargs, <<~PATTERN
|
10
|
+
(send nil? :field
|
11
|
+
...
|
12
|
+
(hash
|
13
|
+
$...
|
14
|
+
)
|
15
|
+
)
|
16
|
+
PATTERN
|
17
|
+
|
18
|
+
def_node_matcher :resolver_kwarg?, <<~PATTERN
|
19
|
+
(pair (sym :resolver) ...)
|
20
|
+
PATTERN
|
21
|
+
|
22
|
+
def_node_matcher :method_kwarg?, <<~PATTERN
|
23
|
+
(pair (sym :method) ...)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def_node_matcher :hash_key_kwarg?, <<~PATTERN
|
27
|
+
(pair (sym :hash_key) ...)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def_node_matcher :description_kwarg?, <<~PATTERN
|
31
|
+
(pair (sym :description) ...)
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
def_node_matcher :resolver_method_option, <<~PATTERN
|
35
|
+
(pair (sym :resolver_method) (sym $...))
|
36
|
+
PATTERN
|
37
|
+
|
38
|
+
def initialize(field_node)
|
39
|
+
@nodes = field_kwargs(field_node) || []
|
40
|
+
end
|
41
|
+
|
42
|
+
def resolver
|
43
|
+
@nodes.find { |kwarg| resolver_kwarg?(kwarg) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def method
|
47
|
+
@nodes.find { |kwarg| method_kwarg?(kwarg) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def hash_key
|
51
|
+
@nodes.find { |kwarg| hash_key_kwarg?(kwarg) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def description
|
55
|
+
@nodes.find { |kwarg| description_kwarg?(kwarg) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def resolver_method_name
|
59
|
+
@resolver_method_name ||= @nodes.flat_map { |kwarg| resolver_method_option(kwarg) }.compact.first
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
6
|
+
# bit of our configuration.
|
7
|
+
module Inject
|
8
|
+
def self.defaults!
|
9
|
+
path = CONFIG_DEFAULT.to_s
|
10
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
11
|
+
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
12
|
+
puts "configuration from \#{path}" if ConfigLoader.debug?
|
13
|
+
config = ConfigLoader.merge_with_default(config, path)
|
14
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
module NodePattern
|
6
|
+
extend RuboCop::NodePattern::Macros
|
7
|
+
|
8
|
+
def_node_matcher :field_definition?, <<~PATTERN
|
9
|
+
(send nil? :field (:sym _) ...)
|
10
|
+
PATTERN
|
11
|
+
|
12
|
+
def_node_matcher :field_definition_with_body?, <<~PATTERN
|
13
|
+
(block
|
14
|
+
(send nil? :field (:sym _) ...)
|
15
|
+
...
|
16
|
+
)
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def_node_matcher :argument?, <<~PATTERN
|
20
|
+
(send nil? :argument (:sym _) ...)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def field?(node)
|
24
|
+
field_definition?(node) || field_definition_with_body?(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
class SchemaMember
|
6
|
+
extend RuboCop::NodePattern::Macros
|
7
|
+
|
8
|
+
def_node_matcher :class_contents, <<~PATTERN
|
9
|
+
(class _ _ $_)
|
10
|
+
PATTERN
|
11
|
+
|
12
|
+
attr_reader :node
|
13
|
+
|
14
|
+
def initialize(node)
|
15
|
+
@node = node
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_method_definition(method_name)
|
19
|
+
body.find { |node| node.def_type? && node.method_name == method_name }
|
20
|
+
end
|
21
|
+
|
22
|
+
def body
|
23
|
+
contents = class_contents(@node)
|
24
|
+
|
25
|
+
if contents.nil?
|
26
|
+
[]
|
27
|
+
elsif contents.begin_type?
|
28
|
+
contents.child_nodes
|
29
|
+
else
|
30
|
+
[contents]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-graphql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Tsepelev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: standard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.71.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.71.0
|
69
|
+
description: A collection of RuboCop cops to improve GraphQL-related code
|
70
|
+
email:
|
71
|
+
- dmitry.a.tsepelev@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- config/default.yml
|
79
|
+
- lib/rubocop-graphql.rb
|
80
|
+
- lib/rubocop/cop/graphql/argument_description.rb
|
81
|
+
- lib/rubocop/cop/graphql/argument_name.rb
|
82
|
+
- lib/rubocop/cop/graphql/cop.rb
|
83
|
+
- lib/rubocop/cop/graphql/extract_input_type.rb
|
84
|
+
- lib/rubocop/cop/graphql/extract_type.rb
|
85
|
+
- lib/rubocop/cop/graphql/field_definitions.rb
|
86
|
+
- lib/rubocop/cop/graphql/field_description.rb
|
87
|
+
- lib/rubocop/cop/graphql/field_method.rb
|
88
|
+
- lib/rubocop/cop/graphql/field_name.rb
|
89
|
+
- lib/rubocop/cop/graphql/object_description.rb
|
90
|
+
- lib/rubocop/cop/graphql/resolver_method_length.rb
|
91
|
+
- lib/rubocop/cop/graphql_cops.rb
|
92
|
+
- lib/rubocop/graphql.rb
|
93
|
+
- lib/rubocop/graphql/argument.rb
|
94
|
+
- lib/rubocop/graphql/argument/block.rb
|
95
|
+
- lib/rubocop/graphql/argument/kwargs.rb
|
96
|
+
- lib/rubocop/graphql/ext/snake_case.rb
|
97
|
+
- lib/rubocop/graphql/field.rb
|
98
|
+
- lib/rubocop/graphql/field/block.rb
|
99
|
+
- lib/rubocop/graphql/field/kwargs.rb
|
100
|
+
- lib/rubocop/graphql/inject.rb
|
101
|
+
- lib/rubocop/graphql/node_pattern.rb
|
102
|
+
- lib/rubocop/graphql/schema_member.rb
|
103
|
+
- lib/rubocop/graphql/version.rb
|
104
|
+
homepage: https://github.com/DmitryTsepelev/rubocop-graphql
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata:
|
108
|
+
homepage_uri: https://github.com/DmitryTsepelev/rubocop-graphql
|
109
|
+
source_code_uri: https://github.com/DmitryTsepelev/rubocop-graphql
|
110
|
+
changelog_uri: https://github.com/DmitryTsepelev/rubocop-graphql/CHANGELOG.md
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.0.3
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Automatic performance checking tool for Ruby code.
|
130
|
+
test_files: []
|