rubocop-petal 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/rubocop/cop/grape/unnecessary_namespace.rb +20 -8
- data/lib/rubocop/petal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7943295b53d5afb66efeedd6b5801405d67f41ca3e87cbe80afe6310e8dfa65a
|
4
|
+
data.tar.gz: 2ee305587c6e13494669395c45ce9e405d902ca3a05727f9fac28858af800c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db9b94e57d4ce9c6656488786e91c7a9f89d71b93e7ee816535610a2877b2e2a29ffbec578c2f97eec195b68e5d86e54d35a27208b23986a46956a2b034b5817
|
7
|
+
data.tar.gz: 9bff7fea4ee7d6df84a93f6acac7518591fbe6a75dda9ba2b9fd8a894ce305c028076e1c7bd9e3bf5cf4b5ae03d82c01ca594df4218eda7b6ad12e1860c867b7
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -6,17 +6,17 @@ module RuboCop
|
|
6
6
|
# Detect unnecessary usage of Grape namespace.
|
7
7
|
#
|
8
8
|
# # bad
|
9
|
-
# namespace :
|
9
|
+
# namespace :some_path do
|
10
10
|
# get {}
|
11
11
|
# end
|
12
12
|
#
|
13
13
|
# # good
|
14
|
-
# get :
|
14
|
+
# get :some_path {}
|
15
15
|
#
|
16
16
|
class UnnecessaryNamespace < Base
|
17
17
|
MSG = 'Unnecessary usage of Grape namespace. '\
|
18
|
-
'Specify endpoint name with
|
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 :
|
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
|
-
|
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|
|
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)
|
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.
|
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-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|