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 +4 -4
- data/config/default.yml +1 -0
- data/lib/refinements/underscore_string.rb +23 -0
- data/lib/rubocop/cop/graphql/field_name.rb +16 -1
- 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: 0d039f4e52b3e606bee7cfc92f14743ead168fd8e9afeefc9c3f73a5e8f97acb
|
4
|
+
data.tar.gz: 443920f9aa279503373dc467b91d5f8bb3e8fe510037c12e791a6231a1612cb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 475dd5aa2de580c3ddc072fa66bc9cc09818dbf0e720bd1a2b874c56cba537dbd3dd63aa99e5bf30e33612981fddd4bb547f9224d5bab3352568564c93f1814e
|
7
|
+
data.tar.gz: c6faab3fb41885f25938ff17f8b18eafe4c2c6ba5a951a118ddeba5985448907597527242a35c1944f9f9a43067be2ec8e5849e605f206530c085c6c4e1da24c
|
data/config/default.yml
CHANGED
@@ -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
|
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.
|
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-
|
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
|