rubocop-graphql 0.9.0 → 0.10.0

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: e63911b5c7c77f1d207fc9a1d411c61b874f51b372507bd7fd4c8072addd0663
4
- data.tar.gz: 5581dcb49597ece10a23dba6f191b531d80d313e265fb6a61ec6db172691ad75
3
+ metadata.gz: 0d039f4e52b3e606bee7cfc92f14743ead168fd8e9afeefc9c3f73a5e8f97acb
4
+ data.tar.gz: 443920f9aa279503373dc467b91d5f8bb3e8fe510037c12e791a6231a1612cb3
5
5
  SHA512:
6
- metadata.gz: ff897f7cfd8f63f3435915d3c9203803b7d81cb4d3997b5ef6e8e3822cb95ae77cc7eb3573bc6c50aa54c630eec59c550b35dca07d12412bcf7a460e00e3290f
7
- data.tar.gz: cb02df1ef01c442dd7c3ad1abd89b6e8457bf83aa52391c78ead27e7c8d0793f8794ac4eb7295e234022763081f640115c3adef8a1f42f81600ef714655f6c06
6
+ metadata.gz: 475dd5aa2de580c3ddc072fa66bc9cc09818dbf0e720bd1a2b874c56cba537dbd3dd63aa99e5bf30e33612981fddd4bb547f9224d5bab3352568564c93f1814e
7
+ data.tar.gz: c6faab3fb41885f25938ff17f8b18eafe4c2c6ba5a951a118ddeba5985448907597527242a35c1944f9f9a43067be2ec8e5849e605f206530c085c6c4e1da24c
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
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.9.0".freeze
3
+ VERSION = "0.10.0".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.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: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-07-23 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