rubocop-grape 0.4.0 → 0.4.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 +10 -0
- data/lib/rubocop/cop/grape/abc_size.rb +1 -4
- data/lib/rubocop/cop/grape/field_name.rb +2 -6
- data/lib/rubocop/cop/grape/params_position.rb +3 -9
- data/lib/rubocop/cop/grape/present_with.rb +49 -0
- data/lib/rubocop/cop/grape/route_param_grouping.rb +34 -0
- data/lib/rubocop/cop/grape_cops.rb +4 -0
- data/lib/rubocop/cop/mixin/endpoint_helper.rb +18 -0
- data/lib/rubocop/grape/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a10e156b9a117d1d9bd4eb1e3d0c559268669f410d80c786d5c4b38ca79d508
|
4
|
+
data.tar.gz: '0287d909c47e61e540fcc98edf2303b97f43ebad7a6fc244fa14444661dbc77f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f01ca9109f953bc9f7f74bebad5a468004fb9db4b738b4d9e01ef0d9265325159e4d6397d16ca35453b3ae5784df27523e7ceea01413de9f030358b4101d9f4e
|
7
|
+
data.tar.gz: e1acec347d818fe04be34f01a012ebd7961730091b00cc370aa720e6097a783eb59b5de54bb2aada39f2f21d7b393b1e26e696d56298ce762ba43243fff3d3a3
|
data/config/default.yml
CHANGED
@@ -19,6 +19,10 @@ Grape/FieldName:
|
|
19
19
|
- snake_case
|
20
20
|
- camelCase
|
21
21
|
|
22
|
+
Grape/RouteParamGrouping:
|
23
|
+
Enabled: true
|
24
|
+
VersionAdded: '0.4.3'
|
25
|
+
|
22
26
|
Grape/RouteParamType:
|
23
27
|
Enabled: true
|
24
28
|
Safe: false
|
@@ -28,3 +32,9 @@ Grape/ParamsPosition:
|
|
28
32
|
Enabled: true
|
29
33
|
Safe: false
|
30
34
|
VersionAdded: '0.1'
|
35
|
+
|
36
|
+
Grape/PresentWith:
|
37
|
+
Enabled: true
|
38
|
+
Safe: false
|
39
|
+
SafeAutoCorrect: false
|
40
|
+
VersionAdded: '0.4.2'
|
@@ -9,15 +9,12 @@ module RuboCop
|
|
9
9
|
# and https://en.wikipedia.org/wiki/ABC_Software_Metric.
|
10
10
|
class AbcSize < Base
|
11
11
|
extend ExcludeLimit
|
12
|
+
include EndpointHelper
|
12
13
|
|
13
14
|
exclude_limit 'Max'
|
14
15
|
|
15
16
|
MSG = 'Assignment Branch Condition size is too high. [%<abc_vector>s %<complexity>d/%<max>d]'
|
16
17
|
|
17
|
-
def_node_matcher :http_method_node?, <<~PATTERN
|
18
|
-
(block (send _ {:get :post :put :patch :delete} ...) ...)
|
19
|
-
PATTERN
|
20
|
-
|
21
18
|
def on_block(node)
|
22
19
|
return unless http_method_node?(node)
|
23
20
|
|
@@ -31,20 +31,16 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
class FieldName < Base
|
33
33
|
include ConfigurableNaming
|
34
|
-
include
|
34
|
+
include EndpointHelper
|
35
35
|
|
36
36
|
MSG = 'Use %<style>s for field names.'
|
37
37
|
|
38
|
-
def_node_matcher :params_block?, <<~PATTERN
|
39
|
-
(block (send _ :params) _ $_)
|
40
|
-
PATTERN
|
41
|
-
|
42
38
|
def_node_matcher :field_name, <<~PATTERN
|
43
39
|
(send _ {:requires :optional} (sym $_) ...)
|
44
40
|
PATTERN
|
45
41
|
|
46
42
|
def on_block(node)
|
47
|
-
return unless (body =
|
43
|
+
return unless (body = params_node?(node))
|
48
44
|
|
49
45
|
find_field_node(body)
|
50
46
|
end
|
@@ -20,15 +20,9 @@ module RuboCop
|
|
20
20
|
# end
|
21
21
|
#
|
22
22
|
class ParamsPosition < Base
|
23
|
-
|
24
|
-
|
25
|
-
def_node_matcher :params_block?, <<~PATTERN
|
26
|
-
(block (send _ :params) ...)
|
27
|
-
PATTERN
|
23
|
+
include EndpointHelper
|
28
24
|
|
29
|
-
|
30
|
-
(block (send _ {:get :post :put :patch :delete} ...) ...)
|
31
|
-
PATTERN
|
25
|
+
MSG = "It's no sense to define params in HTTP method's scope"
|
32
26
|
|
33
27
|
def on_block(node)
|
34
28
|
return unless http_method_node?(node)
|
@@ -37,7 +31,7 @@ module RuboCop
|
|
37
31
|
end
|
38
32
|
|
39
33
|
def collect_violating_nodes(node, collector = [])
|
40
|
-
collector.push(node) if node.type == :block &&
|
34
|
+
collector.push(node) if node.type == :block && params_node?(node)
|
41
35
|
|
42
36
|
node.children.each do |descendant|
|
43
37
|
collect_violating_nodes(descendant, collector) if descendant.is_a?(Parser::AST::Node)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# # bad
|
9
|
+
# get do
|
10
|
+
# present users: users, with: API::Entities::User
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# get do
|
15
|
+
# present :users, users, with: API::Entities::User
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
class PresentWith < Base
|
19
|
+
extend AutoCorrector
|
20
|
+
include EndpointHelper
|
21
|
+
|
22
|
+
MSG_TEMPLATE = 'Maybe you mistyped "`%<current>s`", it should be "`%<correct>s`"'
|
23
|
+
|
24
|
+
def_node_matcher :one_hash_arg_with_key_name_with?, <<~PATTERN
|
25
|
+
(send _ :present
|
26
|
+
(hash
|
27
|
+
(pair (sym $_key)
|
28
|
+
{(send _ $_val) (lvar $_val)})
|
29
|
+
(pair (sym :with) _)))
|
30
|
+
PATTERN
|
31
|
+
|
32
|
+
def on_send(present_node)
|
33
|
+
one_hash_arg_with_key_name_with?(present_node) do |key, val|
|
34
|
+
kwarg = present_node.children.last
|
35
|
+
|
36
|
+
add_offense(kwarg.children.first, message: message(key, val)) do |corrector|
|
37
|
+
corrector.remove(kwarg.children.first)
|
38
|
+
corrector.insert_before(kwarg, ":#{key}, #{val}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def message(key, val)
|
44
|
+
format(MSG_TEMPLATE, current: "#{key}: #{val}", correct: ":#{key}, #{val}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
#
|
9
|
+
# # bad
|
10
|
+
# get ':id' do
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# route_param :id, type: Integer do
|
15
|
+
# get do
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class RouteParamGrouping < Base
|
20
|
+
include EndpointHelper
|
21
|
+
|
22
|
+
MSG = 'Use route_param for route parameter'
|
23
|
+
|
24
|
+
def on_block(node)
|
25
|
+
return unless (method_send_node = http_method_node?(node))
|
26
|
+
return unless (first_argument_node = method_send_node.arguments.first)
|
27
|
+
return unless first_argument_node.value.match?(/:\w/)
|
28
|
+
|
29
|
+
add_offense(first_argument_node)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'mixin/endpoint_helper'
|
4
|
+
|
3
5
|
require_relative 'grape/abc_size'
|
4
6
|
require_relative 'grape/field_name'
|
5
7
|
require_relative 'grape/ivar'
|
6
8
|
require_relative 'grape/params_position'
|
9
|
+
require_relative 'grape/present_with'
|
10
|
+
require_relative 'grape/route_param_grouping'
|
7
11
|
require_relative 'grape/route_param_type'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
# EndpointHelper is a set of AST definitions for endpoint definition by Grape DSL
|
6
|
+
module EndpointHelper
|
7
|
+
extend NodePattern::Macros
|
8
|
+
|
9
|
+
def_node_matcher :http_method_node?, <<~PATTERN
|
10
|
+
(block $(send _ {:get :post :put :patch :delete} ...) ...)
|
11
|
+
PATTERN
|
12
|
+
|
13
|
+
def_node_matcher :params_node?, <<~PATTERN
|
14
|
+
(block (send _ :params) _ $_)
|
15
|
+
PATTERN
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akito Hikasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -48,8 +48,11 @@ files:
|
|
48
48
|
- lib/rubocop/cop/grape/field_name.rb
|
49
49
|
- lib/rubocop/cop/grape/ivar.rb
|
50
50
|
- lib/rubocop/cop/grape/params_position.rb
|
51
|
+
- lib/rubocop/cop/grape/present_with.rb
|
52
|
+
- lib/rubocop/cop/grape/route_param_grouping.rb
|
51
53
|
- lib/rubocop/cop/grape/route_param_type.rb
|
52
54
|
- lib/rubocop/cop/grape_cops.rb
|
55
|
+
- lib/rubocop/cop/mixin/endpoint_helper.rb
|
53
56
|
- lib/rubocop/grape.rb
|
54
57
|
- lib/rubocop/grape/grape_files.rb
|
55
58
|
- lib/rubocop/grape/inject.rb
|
@@ -77,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
80
|
- !ruby/object:Gem::Version
|
78
81
|
version: '0'
|
79
82
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.4.19
|
81
84
|
signing_key:
|
82
85
|
specification_version: 4
|
83
86
|
summary: Automatice Grape code style checking tool.
|