rubocop-grape 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f369f405421b61d6ad373deee22453343db7c7d661953a3f9a8b3860b561f93
|
4
|
+
data.tar.gz: db25749738766747e43c629bb9fe392759e5605adbb489a99120c217c4b5eb72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17a713bd89ecad8ed274fbdb64e8564c5661815cd15cb3d3199a0c846912f67a7beb4f041e5830fc70bb481e73a7303c0902abe8f7743a77211184586dcea7ef
|
7
|
+
data.tar.gz: 8ee60612e5c0b86046496110477e5bcdf598a20954bdb912de5c28ec3c8a1f9bb88fed2fb5d86e35391f83b6420bfe0834b4a9adbaa0b3d1b646e1514088a831
|
data/config/default.yml
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# # bad
|
9
|
+
# get do
|
10
|
+
# params do
|
11
|
+
# requires :user_id, Integer, desc: 'User ID'
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# params do
|
17
|
+
# requires :user_id, Integer, desc: 'User ID'
|
18
|
+
# end
|
19
|
+
# get do
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class ParamsPosition < Base
|
23
|
+
MSG = "It's no sense to define params in HTTP method's scope"
|
24
|
+
|
25
|
+
def_node_matcher :params_block?, <<~PATTERN
|
26
|
+
(block (send _ :params) ...)
|
27
|
+
PATTERN
|
28
|
+
|
29
|
+
def_node_matcher :http_method_node?, <<~PATTERN
|
30
|
+
(block (send _ :get) ...)
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_block(node)
|
34
|
+
return unless http_method_node?(node)
|
35
|
+
|
36
|
+
collect_violationg_nodes(node).each(&method(:add_offense))
|
37
|
+
end
|
38
|
+
|
39
|
+
def collect_violationg_nodes(node, collector = [])
|
40
|
+
collector.push(node) if node.type == :block && params_block?(node)
|
41
|
+
|
42
|
+
node.children.each do |descendant|
|
43
|
+
collect_violationg_nodes(descendant, collector) if descendant.is_a?(Parser::AST::Node)
|
44
|
+
end
|
45
|
+
|
46
|
+
collector
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -18,13 +18,13 @@ module RuboCop
|
|
18
18
|
class RouteParamType < Base
|
19
19
|
MSG = 'Define Parameter Type'
|
20
20
|
|
21
|
-
def_node_matcher :route_param?, <<~
|
21
|
+
def_node_matcher :route_param?, <<~PATTERN
|
22
22
|
(send _ :route_param ({sym str} _) ...)
|
23
|
-
|
23
|
+
PATTERN
|
24
24
|
|
25
|
-
def_node_matcher :include_key_type?, <<~
|
25
|
+
def_node_matcher :include_key_type?, <<~PATTERN
|
26
26
|
(pair (sym :type) _)
|
27
|
-
|
27
|
+
PATTERN
|
28
28
|
|
29
29
|
def on_send(node)
|
30
30
|
return unless route_param?(node)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akito Hikasa
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- bin/console
|
45
45
|
- config/default.yml
|
46
46
|
- lib/rubocop-grape.rb
|
47
|
+
- lib/rubocop/cop/grape/params_position.rb
|
47
48
|
- lib/rubocop/cop/grape/route_param_type.rb
|
48
49
|
- lib/rubocop/cop/grape_cops.rb
|
49
50
|
- lib/rubocop/grape.rb
|