rubocop-graphql 0.9.0 → 0.10.3
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 +11 -0
- data/lib/refinements/underscore_string.rb +23 -0
- data/lib/rubocop/cop/graphql/field_hash_key.rb +1 -1
- data/lib/rubocop/cop/graphql/field_name.rb +16 -1
- data/lib/rubocop/cop/graphql/ordered_fields.rb +1 -1
- data/lib/rubocop/graphql/field/block.rb +1 -1
- data/lib/rubocop/graphql/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60522da6cb205f7667084ee8a44f5500a426e4e52d677c60dee314d7e11e2129
|
4
|
+
data.tar.gz: 6d091ec89349bd1b2d9ca160c53566fd11cd2dc0a786f33e81a12e7b46e9a20e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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.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-
|
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.
|
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.
|