rubocop-petal 0.6.0 → 0.7.0

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: c7d73cfbe6b4f194f1c60d25235331cf7a08b04b516411efeabeafce9e6e7886
4
- data.tar.gz: 193dd79a6efd61cdd2edbb5bfae7158497ca7cc2bb52da38b02dfecd776eadfa
3
+ metadata.gz: 7943295b53d5afb66efeedd6b5801405d67f41ca3e87cbe80afe6310e8dfa65a
4
+ data.tar.gz: 2ee305587c6e13494669395c45ce9e405d902ca3a05727f9fac28858af800c0e
5
5
  SHA512:
6
- metadata.gz: 15ef827ea4cf56872e2c85178463e2d3a05a6a47411832439c81cb4dd9a9ff9221efb61603d2a9e6b38d5859fe0aa2745499bd1d98ef516169e1947065bf1ebb
7
- data.tar.gz: 0c14a8c68e7af71afbd81cd827fdd76dfbcc8780e06ab7f1f2f662cc7409fe505b2afc05fa6260f18c6d3a1dd8df05176d51c965c71b68c4f75501abe4a9aa96
6
+ metadata.gz: db9b94e57d4ce9c6656488786e91c7a9f89d71b93e7ee816535610a2877b2e2a29ffbec578c2f97eec195b68e5d86e54d35a27208b23986a46956a2b034b5817
7
+ data.tar.gz: 9bff7fea4ee7d6df84a93f6acac7518591fbe6a75dda9ba2b9fd8a894ce305c028076e1c7bd9e3bf5cf4b5ae03d82c01ca594df4218eda7b6ad12e1860c867b7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  # main
4
4
 
5
+ # v0.7.0
6
+
7
+ * Support more cases for `Grape/UnnecessaryNamespace`. ([#26](https://github.com/petalmd/rubocop-petal/pull/26))
8
+
5
9
  # v0.6.0
6
10
 
7
11
  * Added cop `RSpec::SidekiqInline` ([#24](https://github.com/petalmd/rubocop-petal/pull/24))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-petal (0.6.0)
4
+ rubocop-petal (0.7.0)
5
5
  rubocop (>= 1.7.0, < 2.0)
6
6
  rubocop-rails (~> 2.10)
7
7
 
@@ -6,17 +6,17 @@ module RuboCop
6
6
  # Detect unnecessary usage of Grape namespace.
7
7
  #
8
8
  # # bad
9
- # namespace :my_namespace
9
+ # namespace :some_path do
10
10
  # get {}
11
11
  # end
12
12
  #
13
13
  # # good
14
- # get :my_namespace {}
14
+ # get :some_path {}
15
15
  #
16
16
  class UnnecessaryNamespace < Base
17
17
  MSG = 'Unnecessary usage of Grape namespace. '\
18
- 'Specify endpoint name with a argument: `get :my_namespace`.'
19
- HTTP_ACTIONS = Set.new(%i[get put post patch delete])
18
+ 'Specify endpoint name with an argument: `get :some_path`.'
19
+ HTTP_ACTIONS = Set.new(%i[get head put post patch delete])
20
20
  GRAPE_NAMESPACE_ALIAS = Set.new(%i[namespace resource resources])
21
21
  METHOD_JUSTIFY_NAMESPACE = Set.new(%i[route_param namespaces resource resources version])
22
22
 
@@ -28,8 +28,12 @@ module RuboCop
28
28
  (block (send nil? METHOD_JUSTIFY_NAMESPACE ...) ...)
29
29
  PATTERN
30
30
 
31
- def_node_matcher :http_action?, <<~PATTERN
32
- (block (send nil? HTTP_ACTIONS) ...)
31
+ def_node_matcher :http_action_with_path?, <<~PATTERN
32
+ (block (send nil? HTTP_ACTIONS ({sym | str} $_)? ...) ...)
33
+ PATTERN
34
+
35
+ def_node_matcher :http_action_with_options?, <<~PATTERN
36
+ (block (send nil? HTTP_ACTIONS ...) ...)
33
37
  PATTERN
34
38
 
35
39
  def on_send(node)
@@ -42,13 +46,21 @@ module RuboCop
42
46
  end
43
47
 
44
48
  http_action_node = select_http_action_block_node(node_to_select_http_action)
45
- add_offense(node) if http_action_node.size == 1
49
+
50
+ return if http_action_node.size != 1
51
+
52
+ paths = paths_added_with_http_action(http_action_node.first)
53
+ add_offense(node) if paths.size.zero?
46
54
  end
47
55
 
48
56
  private
49
57
 
58
+ def paths_added_with_http_action(node)
59
+ http_action_with_path?(node).yield_self.to_a.flatten.compact
60
+ end
61
+
50
62
  def select_http_action_block_node(nodes)
51
- nodes.select { |node| http_action?(node) }
63
+ nodes.select { |node| http_action_with_path?(node) || http_action_with_options?(node) }
52
64
  end
53
65
 
54
66
  def namespace_node(node)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Petal
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-petal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Francis Bastien
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop