rubocop-graphql 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/graphql/cop.rb +92 -0
- data/lib/rubocop/cop/graphql_cops.rb +2 -0
- 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: 75ede967be105c3771fc0c6c648632bf3c8fc49c1e81bb1f89d8b475c0403555
|
4
|
+
data.tar.gz: ec1ced3e202cac94d70c24ecf890c63c0c7cca819edd623476bf7e831083bd1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccca643eb811b6c25a4b8f2918b7c094a943b8c3a477d9c4b17c8e0bb4e75fa0d11b167c652790619e356716f6bc6c501446334c6f4d65f4ea75ffa4da2dfa3a
|
7
|
+
data.tar.gz: 62d6ec1ae491c25c1c35b3c8a2d90fbec5a938034bbbc8d4abb7a38c3a7a50f2f359433f845e308f2e5257d9614ff7d3c43a403d56a34c61e575738eee2433ff
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# Inspied by https://github.com/rubocop-hq/rubocop-rspec/blob/3a2088f79737e2e8e0e21482783f7d61411bf021/lib/rubocop/cop/rspec/cop.rb
|
5
|
+
module Cop
|
6
|
+
WorkaroundGraphqlCop = Cop.dup
|
7
|
+
|
8
|
+
# Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
|
9
|
+
# the inherited method without breaking functionality
|
10
|
+
class WorkaroundGraphqlCop
|
11
|
+
# Remove the Cop.inherited method to be a noop. Our RSpec::Cop
|
12
|
+
# class will invoke the inherited hook instead
|
13
|
+
class << self
|
14
|
+
undef inherited
|
15
|
+
def inherited(*)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Special case `Module#<` so that the rspec support rubocop exports
|
20
|
+
# is compatible with our subclass
|
21
|
+
def self.<(other)
|
22
|
+
other.equal?(RuboCop::Cop::Cop) || super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
private_constant(:WorkaroundGraphqlCop)
|
26
|
+
|
27
|
+
module GraphQL
|
28
|
+
# @abstract parent class to graphql-ruby cops
|
29
|
+
#
|
30
|
+
# The criteria for whether rubocop-rspec analyzes a certain ruby file
|
31
|
+
# is configured via `AllCops/GraphQL`. For example, if you want to
|
32
|
+
# customize your project to scan all files within a `graph/` directory
|
33
|
+
# then you could add this to your configuration:
|
34
|
+
#
|
35
|
+
# @example configuring analyzed paths
|
36
|
+
#
|
37
|
+
# AllCops:
|
38
|
+
# GraphQL:
|
39
|
+
# Patterns:
|
40
|
+
# - '(?:^|/)graph/'
|
41
|
+
class Cop < WorkaroundGraphqlCop
|
42
|
+
DEFAULT_CONFIGURATION =
|
43
|
+
RuboCop::GraphQL::CONFIG.fetch("AllCops").fetch("GraphQL")
|
44
|
+
|
45
|
+
DEFAULT_PATTERN_RE = Regexp.union(
|
46
|
+
DEFAULT_CONFIGURATION.fetch("Patterns")
|
47
|
+
.map(&Regexp.public_method(:new))
|
48
|
+
)
|
49
|
+
|
50
|
+
# Invoke the original inherited hook so our cops are recognized
|
51
|
+
def self.inherited(subclass)
|
52
|
+
RuboCop::Cop::Cop.inherited(subclass)
|
53
|
+
end
|
54
|
+
|
55
|
+
def relevant_file?(file)
|
56
|
+
relevant_rubocop_graphql_file?(file) && super
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def relevant_rubocop_graphql_file?(file)
|
62
|
+
graphql_pattern =~ file
|
63
|
+
end
|
64
|
+
|
65
|
+
def graphql_pattern
|
66
|
+
if rspec_graphql_config?
|
67
|
+
Regexp.union(rspec_graphql_config.map(&Regexp.public_method(:new)))
|
68
|
+
else
|
69
|
+
DEFAULT_PATTERN_RE
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def all_cops_config
|
74
|
+
config
|
75
|
+
.for_all_cops
|
76
|
+
end
|
77
|
+
|
78
|
+
def rspec_graphql_config?
|
79
|
+
return unless all_cops_config.key?("GraphQL")
|
80
|
+
|
81
|
+
all_cops_config.fetch("GraphQL").key?("Patterns")
|
82
|
+
end
|
83
|
+
|
84
|
+
def rspec_graphql_config
|
85
|
+
all_cops_config
|
86
|
+
.fetch("GraphQL", DEFAULT_CONFIGURATION)
|
87
|
+
.fetch("Patterns")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
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.1.
|
4
|
+
version: 0.1.1
|
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-05-
|
11
|
+
date: 2020-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- README.md
|
78
78
|
- config/default.yml
|
79
79
|
- lib/rubocop-graphql.rb
|
80
|
+
- lib/rubocop/cop/graphql/cop.rb
|
80
81
|
- lib/rubocop/cop/graphql/field_definitions.rb
|
81
82
|
- lib/rubocop/cop/graphql/field_description.rb
|
82
83
|
- lib/rubocop/cop/graphql/resolver_method_length.rb
|