rubocop-grape 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 590df7af3dec0374453d4f8ba4282b6d2981492c4e25d0ea537dd9e7b1de8eca
4
- data.tar.gz: d52f772ffb08ba797df64f30298362ce04872477b36544614430e7dd157540d4
3
+ metadata.gz: 0a10e156b9a117d1d9bd4eb1e3d0c559268669f410d80c786d5c4b38ca79d508
4
+ data.tar.gz: '0287d909c47e61e540fcc98edf2303b97f43ebad7a6fc244fa14444661dbc77f'
5
5
  SHA512:
6
- metadata.gz: 32c44eac0eee98cee4c97de9e3ff829c7f7d65ef532ee5066985804cc430aff642c93402712240023b430a5a02578806f9a2864e1550147dbc6e9a12e56dbf0c
7
- data.tar.gz: 6692df01c1c324431ba0625d5f2042447afb7b882977dd36fa3f556a9bf448f79cf5e9884240a66f9af1263d04b31e70ec8a1fd212975b6e0758816e9d899b29
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
@@ -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
@@ -7,4 +7,5 @@ require_relative 'grape/field_name'
7
7
  require_relative 'grape/ivar'
8
8
  require_relative 'grape/params_position'
9
9
  require_relative 'grape/present_with'
10
+ require_relative 'grape/route_param_grouping'
10
11
  require_relative 'grape/route_param_type'
@@ -7,7 +7,7 @@ module RuboCop
7
7
  extend NodePattern::Macros
8
8
 
9
9
  def_node_matcher :http_method_node?, <<~PATTERN
10
- (block (send _ {:get :post :put :patch :delete} ...) ...)
10
+ (block $(send _ {:get :post :put :patch :delete} ...) ...)
11
11
  PATTERN
12
12
 
13
13
  def_node_matcher :params_node?, <<~PATTERN
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Grape
5
- VERSION = '0.4.2'
5
+ VERSION = '0.4.3'
6
6
  end
7
7
  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.2
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: 2024-04-04 00:00:00.000000000 Z
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -49,6 +49,7 @@ files:
49
49
  - lib/rubocop/cop/grape/ivar.rb
50
50
  - lib/rubocop/cop/grape/params_position.rb
51
51
  - lib/rubocop/cop/grape/present_with.rb
52
+ - lib/rubocop/cop/grape/route_param_grouping.rb
52
53
  - lib/rubocop/cop/grape/route_param_type.rb
53
54
  - lib/rubocop/cop/grape_cops.rb
54
55
  - lib/rubocop/cop/mixin/endpoint_helper.rb