ezcater_rubocop 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -6
- data/README.md +1 -0
- data/config/default.yml +9 -0
- data/lib/ezcater_rubocop.rb +1 -0
- data/lib/ezcater_rubocop/version.rb +1 -1
- data/lib/rubocop/cop/ezcater/graphql_fields_naming.rb +74 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa54b1bc5ab26cb7d499ac8b61e01aeb94bb82de6a7de5c125cbc4a1f4c3c0a
|
4
|
+
data.tar.gz: 4af52c423b5e171436383e3ee85bbfdd72ef1a80e0de7f519a88e44cf21a20ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cc9e1d28ef7cb67418d65e16e17e5d43c850c76d3b417a4a264c30a80cb43d648ed0204441e5f612b2719daf241fea818e2aace75338106c16910345137ec56
|
7
|
+
data.tar.gz: 1760b6cdc245067c9d46d6ea9574b1bce15c7c2c1e0dc1b59d53f733a20ac36db2cf137697754f21992d0a76e3dc2dcfba4d11b8fa15b358b5df324523175d9f
|
data/CHANGELOG.md
CHANGED
@@ -6,20 +6,16 @@ This gem is moving onto its own [Semantic Versioning](https://semver.org/) schem
|
|
6
6
|
|
7
7
|
Prior to v1.0.0 this gem was versioned based on the `MAJOR`.`MINOR` version of RuboCop. The first release of the ezcater_rubocop gem was `v0.49.0`.
|
8
8
|
|
9
|
-
##
|
10
|
-
|
11
|
-
- ...
|
9
|
+
## v1.3.0
|
10
|
+
- Add `Ezcater/GraphqlFieldsNaming` cop.
|
12
11
|
|
13
12
|
## v1.2.0
|
14
|
-
|
15
13
|
- Add `Ezcater/RailsTopLevelSqlExecute` to replace `ActiveRecord::Base.connection.execute` with `execute` in `db/migrate/`.
|
16
14
|
|
17
15
|
## v1.1.1
|
18
|
-
|
19
16
|
- Exclude `lib/tasks/` for `Ezcater/RailsEnv` and `Ezcater/DirectEnvCheck`.
|
20
17
|
|
21
18
|
## v1.1.0
|
22
|
-
|
23
19
|
- Add `Ezcater/RailsEnv` cop.
|
24
20
|
- Add `Ezcater/DirectEnvCheck` cop.
|
25
21
|
|
data/README.md
CHANGED
@@ -82,6 +82,7 @@ This gem is using [Semantic Versioning](https://semver.org/). All version bumps
|
|
82
82
|
1. [RspecRequireFeatureFlagMock](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb) - Enforce use of `mock_feature_flag` helper instead of mocking `FeatureFlag.is_active?` directly.
|
83
83
|
1. [RspecRequireHttpStatusMatcher](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/rspec_require_http_status_matcher.rb) - Use the HTTP status code matcher, like `expect(response).to have_http_status :bad_request`, rather than `expect(response.code).to eq 400`
|
84
84
|
1. [StyleDig](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/style_dig.rb) - Recommend `dig` for deeply nested access.
|
85
|
+
1. [GraphqlFieldsNaming](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/graphql_fields_naming.rb) - Enforce the configured style when naming graphQL fields and arguments.
|
85
86
|
|
86
87
|
## Development
|
87
88
|
|
data/config/default.yml
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
Ezcater/GraphqlFieldsNaming:
|
2
|
+
EnforcedStyle: snake_case
|
3
|
+
Enabled: true
|
4
|
+
SupportedStyles:
|
5
|
+
- snake_case
|
6
|
+
- camelCase
|
7
|
+
Include:
|
8
|
+
- 'app/graphql/**/*.rb'
|
9
|
+
|
1
10
|
Ezcater/RailsConfiguration:
|
2
11
|
Description: 'Enforce the use of `Rails.configuration` instead of `Rails.application.config`.'
|
3
12
|
Enabled: true
|
data/lib/ezcater_rubocop.rb
CHANGED
@@ -15,6 +15,7 @@ config = RuboCop::ConfigLoader.merge_with_default(config, path)
|
|
15
15
|
RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
|
16
16
|
|
17
17
|
require "rubocop/cop/ezcater/direct_env_check"
|
18
|
+
require "rubocop/cop/ezcater/graphql_fields_naming"
|
18
19
|
require "rubocop/cop/ezcater/rails_configuration"
|
19
20
|
require "rubocop/cop/ezcater/rails_env"
|
20
21
|
require "rubocop/cop/ezcater/rails_top_level_sql_execute"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Ezcater
|
6
|
+
# This cop makes sure that GraphQL fields & arguments match the supported style
|
7
|
+
# https://git.io/JeofW
|
8
|
+
#
|
9
|
+
# The cop also ignores when users provide a :camelize option, because
|
10
|
+
# the user is manually requesting to override the value
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# field :fooBar, ID, null: false
|
15
|
+
# argument :barBaz, ID, required: true
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# field :foo_bar, ID, null: true
|
19
|
+
# field :foo_bar, ID, null: true do
|
20
|
+
# argument :bar_baz, ID, required: true
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# field :fooBar, ID, null: true, camelize: true
|
24
|
+
#
|
25
|
+
class GraphqlFieldsNaming < Cop
|
26
|
+
include ConfigurableNaming
|
27
|
+
|
28
|
+
MSG = "Use %<style>s for GraphQL fields & arguments names. " \
|
29
|
+
"See https://git.io/JeofW for our guide. " \
|
30
|
+
"This can be overridden with camelize."
|
31
|
+
FIELD_ADDING_METHODS = %i(field argument).freeze
|
32
|
+
PROCESSABLE_TYPES = %i(sym string).freeze
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
method = method_name(node)
|
36
|
+
first_arg = node.first_argument
|
37
|
+
|
38
|
+
return unless FIELD_ADDING_METHODS.include? method
|
39
|
+
return unless PROCESSABLE_TYPES.include?(first_arg&.type)
|
40
|
+
|
41
|
+
return if includes_camelize?(node)
|
42
|
+
|
43
|
+
check_name(node, first_arg.value, node.first_argument.loc.expression)
|
44
|
+
end
|
45
|
+
|
46
|
+
alias on_super on_send
|
47
|
+
alias on_yield on_send
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def includes_camelize?(node)
|
52
|
+
results = []
|
53
|
+
node.last_argument.each_child_node { |arg| results << args_include_camelize?(arg) }
|
54
|
+
results.any?
|
55
|
+
end
|
56
|
+
|
57
|
+
def args_include_camelize?(arg_pair)
|
58
|
+
key_node = arg_pair.key
|
59
|
+
_value_node = arg_pair.value
|
60
|
+
|
61
|
+
key_node.value.match?(/camelize/)
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_name(node)
|
65
|
+
node.children[1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def message(style)
|
69
|
+
format(MSG, style: style)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezcater_rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ezCater, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/ezcater_rubocop.rb
|
160
160
|
- lib/ezcater_rubocop/version.rb
|
161
161
|
- lib/rubocop/cop/ezcater/direct_env_check.rb
|
162
|
+
- lib/rubocop/cop/ezcater/graphql_fields_naming.rb
|
162
163
|
- lib/rubocop/cop/ezcater/rails_configuration.rb
|
163
164
|
- lib/rubocop/cop/ezcater/rails_env.rb
|
164
165
|
- lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb
|
@@ -190,7 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
191
|
- !ruby/object:Gem::Version
|
191
192
|
version: '0'
|
192
193
|
requirements: []
|
193
|
-
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.7.6
|
194
196
|
signing_key:
|
195
197
|
specification_version: 4
|
196
198
|
summary: ezCater custom cops and shared configuration
|