rubocop-graphql 0.9.0 → 0.10.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e63911b5c7c77f1d207fc9a1d411c61b874f51b372507bd7fd4c8072addd0663
4
- data.tar.gz: 5581dcb49597ece10a23dba6f191b531d80d313e265fb6a61ec6db172691ad75
3
+ metadata.gz: 60522da6cb205f7667084ee8a44f5500a426e4e52d677c60dee314d7e11e2129
4
+ data.tar.gz: 6d091ec89349bd1b2d9ca160c53566fd11cd2dc0a786f33e81a12e7b46e9a20e
5
5
  SHA512:
6
- metadata.gz: ff897f7cfd8f63f3435915d3c9203803b7d81cb4d3997b5ef6e8e3822cb95ae77cc7eb3573bc6c50aa54c630eec59c550b35dca07d12412bcf7a460e00e3290f
7
- data.tar.gz: cb02df1ef01c442dd7c3ad1abd89b6e8457bf83aa52391c78ead27e7c8d0793f8794ac4eb7295e234022763081f640115c3adef8a1f42f81600ef714655f6c06
6
+ metadata.gz: 708fbacb5879ce6be4ff0b9a9f34f85d13e1b65945a854c4b63cd96d9a74e145a8f20c1d792fcca9639ac524cb5c5353ddc09dd6f68e556c7e0167fbd4a9c544
7
+ data.tar.gz: e827fa568a4a472b2246185afc47bca7c119b9af60a3cc77e8d9033556866468988f1f79b8e2e2f60a8b43381e97a416f9825e61317a850475961414b29578ac
data/config/default.yml CHANGED
@@ -48,6 +48,7 @@ GraphQL/FieldName:
48
48
  Enabled: true
49
49
  VersionAdded: '0.80'
50
50
  Description: 'This cop checks whether field names are snake_case'
51
+ SafeAutoCorrect: false
51
52
 
52
53
  GraphQL/ExtractInputType:
53
54
  Enabled: true
@@ -79,3 +80,13 @@ GraphQL/ObjectDescription:
79
80
  Exclude:
80
81
  - '**/*_schema.rb'
81
82
  - '**/base_*.rb'
83
+
84
+ GraphQL/OrderedArguments:
85
+ Enabled: true
86
+ VersionAdded: '0.80'
87
+ Description: 'Arguments should be alphabetically sorted within groups'
88
+
89
+ GraphQL/OrderedFields:
90
+ Enabled: true
91
+ VersionAdded: '0.80'
92
+ Description: 'Fields should be alphabetically sorted within groups'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnderscoreString
4
+ refine String do
5
+ # This method was extracted from activesupport in Rails:
6
+ # https://github.com/rails/rails/blob/8dab534ca81dd32c6a83ac03596a1feb7ddaaca7/activesupport/lib/active_support/inflector/methods.rb#L96
7
+
8
+ def underscore
9
+ camel_cased_word = self
10
+ regex = /(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/
11
+ return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
12
+
13
+ word = camel_cased_word.to_s.gsub("::", "/")
14
+ word.gsub!(regex) { "#{Regexp.last_match(1) && '_'}#{Regexp.last_match(2).downcase}" }
15
+ word.gsub!(/([A-Z\d]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
16
+ (Regexp.last_match(1) || Regexp.last_match(2)) << "_"
17
+ end
18
+ word.tr!("-", "_")
19
+ word.downcase!
20
+ word
21
+ end
22
+ end
23
+ end
@@ -34,7 +34,7 @@ module RuboCop
34
34
  (args)
35
35
  (send
36
36
  (send nil? :object) :[]
37
- (_type $_)
37
+ ({sym str} $_)
38
38
  )
39
39
  )
40
40
  PATTERN
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../../../refinements/underscore_string"
4
+
5
+ using UnderscoreString unless String.method_defined?(:underscore)
6
+
3
7
  module RuboCop
4
8
  module Cop
5
9
  module GraphQL
@@ -19,6 +23,7 @@ module RuboCop
19
23
  # end
20
24
  #
21
25
  class FieldName < Base
26
+ extend AutoCorrector
22
27
  include RuboCop::GraphQL::NodePattern
23
28
 
24
29
  using RuboCop::GraphQL::Ext::SnakeCase
@@ -31,7 +36,17 @@ module RuboCop
31
36
  field = RuboCop::GraphQL::Field.new(node)
32
37
  return if field.name.snake_case?
33
38
 
34
- add_offense(node)
39
+ add_offense(node) do |corrector|
40
+ rename_field_name(corrector, field, node)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def rename_field_name(corrector, field, node)
47
+ name_field = field.name.to_s
48
+ new_line = node.source.sub(name_field, name_field.underscore)
49
+ corrector.replace(node, new_line)
35
50
  end
36
51
  end
37
52
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # Field should be alphabetically sorted within groups.
6
+ # Fields should be alphabetically sorted within groups.
7
7
  #
8
8
  # @example
9
9
  # # good
@@ -11,7 +11,7 @@ module RuboCop
11
11
  (block
12
12
  (send nil? :field ...)
13
13
  (args)
14
- $...
14
+ {(begin $...)|$...}
15
15
  )
16
16
  PATTERN
17
17
 
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.9.0".freeze
3
+ VERSION = "0.10.3".freeze
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.9.0
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Tsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - LICENSE.txt
83
83
  - README.md
84
84
  - config/default.yml
85
+ - lib/refinements/underscore_string.rb
85
86
  - lib/rubocop-graphql.rb
86
87
  - lib/rubocop/cop/graphql/argument_description.rb
87
88
  - lib/rubocop/cop/graphql/argument_name.rb
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubygems_version: 3.1.2
138
+ rubygems_version: 3.1.6
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: Automatic performance checking tool for Ruby code.