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: c384295c459e02395aee22afb61dce8fe77a11603b72c57188ea65761bc981c2
4
- data.tar.gz: ff1aff8360ad4014f513af0a5312e5647f866e602e513580509854577dff21be
3
+ metadata.gz: 3f369f405421b61d6ad373deee22453343db7c7d661953a3f9a8b3860b561f93
4
+ data.tar.gz: db25749738766747e43c629bb9fe392759e5605adbb489a99120c217c4b5eb72
5
5
  SHA512:
6
- metadata.gz: 4f8488742a3f79cfdd660154d4ed29db6f8f6797356f945d7761815a53bda297f459fd8d5a77b81928814da124679cc4c38232b089ff5d0a95304d1db3a1bb58
7
- data.tar.gz: 17561aee4d974b9b8642a0ca6e40be8c289e4b6ac942971fe61a022daa69224970f2bff7677be52788332e127a5cdabd4b4d5b07a17c9ac8e21ca64ce59b80e2
6
+ metadata.gz: 17a713bd89ecad8ed274fbdb64e8564c5661815cd15cb3d3199a0c846912f67a7beb4f041e5830fc70bb481e73a7303c0902abe8f7743a77211184586dcea7ef
7
+ data.tar.gz: 8ee60612e5c0b86046496110477e5bcdf598a20954bdb912de5c28ec3c8a1f9bb88fed2fb5d86e35391f83b6420bfe0834b4a9adbaa0b3d1b646e1514088a831
data/config/default.yml CHANGED
@@ -2,3 +2,8 @@ Grape/RouteParamType:
2
2
  Enabled: true
3
3
  Safe: false
4
4
  VersionAdded: '0.1'
5
+
6
+ Grape/ParamsPosition:
7
+ Enabled: true
8
+ Safe: false
9
+ VersionAdded: '0.1'
@@ -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?, <<~RUBY
21
+ def_node_matcher :route_param?, <<~PATTERN
22
22
  (send _ :route_param ({sym str} _) ...)
23
- RUBY
23
+ PATTERN
24
24
 
25
- def_node_matcher :include_key_type?, <<~RUBY
25
+ def_node_matcher :include_key_type?, <<~PATTERN
26
26
  (pair (sym :type) _)
27
- RUBY
27
+ PATTERN
28
28
 
29
29
  def on_send(node)
30
30
  return unless route_param?(node)
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'grape/params_position'
3
4
  require_relative 'grape/route_param_type'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Grape
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
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.0
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