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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44b2a5447e5631dde2523566cca0f2e8e5f38a5d2a0e874c06e0febf9afa8661
4
- data.tar.gz: db95fd1b174deb832d715a9e72d45864c9c3883e828d07768d7b2ad2b13ed606
3
+ metadata.gz: 75ede967be105c3771fc0c6c648632bf3c8fc49c1e81bb1f89d8b475c0403555
4
+ data.tar.gz: ec1ced3e202cac94d70c24ecf890c63c0c7cca819edd623476bf7e831083bd1b
5
5
  SHA512:
6
- metadata.gz: fc9381482049b6de23c6790f94a0828e49fe1f13a55922d8cbc1e565288ed3453f12b4fe6961620504b9bfaed6c9e996b3477725985e88dd32529317988b776c
7
- data.tar.gz: bd246b919704fd783e58578793dba6f8f00e79de20fff9eb313ce5dd2b1c15bb6ad4b21e877a694b7d2f6f4016b2d768ed0975b293d6d405b3571682e798ba71
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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "graphql/cop"
4
+
3
5
  require_relative "graphql/field_definitions"
4
6
  require_relative "graphql/field_description"
5
7
  require_relative "graphql/resolver_method_length"
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  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.0
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-21 00:00:00.000000000 Z
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