rubocop-nueca 1.2.2 → 1.2.5
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 +4 -4
- data/.github/workflows/publish.yml +5 -1
- data/.github/workflows/rubocop.yml +23 -0
- data/lib/rubocop/cop/shared/collection_context.rb +59 -11
- data/lib/rubocop/nueca/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a3f50ec1bdcbb388b5843fc52caa7424579538bf73f995f3121a8e39e23544
|
4
|
+
data.tar.gz: e94a2e703f0ac39efa1ac5b9886fa711f7c2b5c482a6f27d9a4301af4bdae4eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 330371fdc147e6d9469a230d0a47545cc8855117c2cb9c6a5ab828946eb353357579b238db05658357f3301927dc5b9da868711691a84da4975741cf369c2db6
|
7
|
+
data.tar.gz: b9941dd2e7f84e12f5ceab85b2508e185ab80f04c06d387786f51949770f8faace0c023101f99322be2fb69cc69d020ce19cb814b60be47925242b23a1660938
|
@@ -1,12 +1,16 @@
|
|
1
1
|
name: Publish Gem
|
2
2
|
|
3
3
|
on:
|
4
|
-
|
4
|
+
workflow_run:
|
5
|
+
workflows: ["RuboCop"]
|
6
|
+
types:
|
7
|
+
- completed
|
5
8
|
branches: [ master ]
|
6
9
|
|
7
10
|
jobs:
|
8
11
|
publish:
|
9
12
|
runs-on: ubuntu-latest
|
13
|
+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
10
14
|
|
11
15
|
steps:
|
12
16
|
- uses: actions/checkout@v4
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
rubocop:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v4
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: '3.4'
|
20
|
+
bundler-cache: true
|
21
|
+
|
22
|
+
- name: Run RuboCop
|
23
|
+
run: bundle exec rubocop
|
@@ -3,12 +3,11 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
# rubocop:disable Metrics/ClassLength
|
7
|
-
class CollectionContext
|
6
|
+
class CollectionContext # rubocop:disable Metrics/ClassLength
|
8
7
|
ROUTE_CATEGORIES = {
|
9
8
|
simple: [:get, :post, :put, :patch, :delete, :head, :options, :match, :root],
|
10
9
|
resource: [:resource, :resources],
|
11
|
-
namespace: [:namespace, :scope, :concern],
|
10
|
+
namespace: [:namespace, :scope, :concern, :member, :collection],
|
12
11
|
draw: [:draw]
|
13
12
|
}.freeze
|
14
13
|
|
@@ -45,10 +44,18 @@ module RuboCop
|
|
45
44
|
send_node = node.send_node
|
46
45
|
return unless send_node.send_type? && route_method?(send_node)
|
47
46
|
|
48
|
-
|
47
|
+
add_route_block_if_valid(node) unless [:member, :collection].include?(send_node.method_name)
|
49
48
|
process_nested_context(node)
|
50
49
|
end
|
51
50
|
|
51
|
+
def add_route_block_if_valid(node)
|
52
|
+
send_node = node.send_node
|
53
|
+
return unless route_method?(send_node)
|
54
|
+
|
55
|
+
route_info = build_route_info_from_block(node)
|
56
|
+
@collector.add_route(route_info) if route_info
|
57
|
+
end
|
58
|
+
|
52
59
|
def process_nested_context(node)
|
53
60
|
body = node.body
|
54
61
|
return unless body
|
@@ -60,19 +67,41 @@ module RuboCop
|
|
60
67
|
|
61
68
|
def build_namespace_path(send_node)
|
62
69
|
new_namespace_path = @namespace_path.dup
|
70
|
+
method_name = send_node.method_name
|
63
71
|
|
64
|
-
case
|
72
|
+
case method_name
|
65
73
|
when :namespace
|
66
|
-
|
67
|
-
new_namespace_path << namespace_name if namespace_name
|
74
|
+
add_namespace_to_path(new_namespace_path, send_node)
|
68
75
|
when :scope
|
69
|
-
|
70
|
-
|
76
|
+
add_scope_to_path(new_namespace_path, send_node)
|
77
|
+
when :resources, :resource
|
78
|
+
add_resource_to_path(new_namespace_path, send_node)
|
79
|
+
when :member, :collection
|
80
|
+
add_member_collection_to_path(new_namespace_path, method_name)
|
71
81
|
end
|
72
82
|
|
73
83
|
new_namespace_path
|
74
84
|
end
|
75
85
|
|
86
|
+
def add_namespace_to_path(path, node)
|
87
|
+
namespace_name = extract_namespace_name(node)
|
88
|
+
path << namespace_name if namespace_name
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_scope_to_path(path, node)
|
92
|
+
scope_name = extract_scope_name(node)
|
93
|
+
path << scope_name if scope_name
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_resource_to_path(path, node)
|
97
|
+
resource_name = extract_namespace_name(node)
|
98
|
+
path << resource_name if resource_name
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_member_collection_to_path(path, method_name)
|
102
|
+
path << method_name.to_s
|
103
|
+
end
|
104
|
+
|
76
105
|
def extract_namespace_name(node)
|
77
106
|
first_arg = node.arguments.first
|
78
107
|
return first_arg.value.to_s if first_arg&.sym_type? || first_arg&.str_type?
|
@@ -84,7 +113,6 @@ module RuboCop
|
|
84
113
|
scope_name = extract_scope_option_value(node)
|
85
114
|
return scope_name if scope_name
|
86
115
|
|
87
|
-
# If no module/path specified, use first argument if it's a symbol/string
|
88
116
|
first_arg = node.arguments.first
|
89
117
|
return first_arg.value.to_s if first_arg&.sym_type? || first_arg&.str_type?
|
90
118
|
|
@@ -152,6 +180,26 @@ module RuboCop
|
|
152
180
|
}
|
153
181
|
end
|
154
182
|
|
183
|
+
def build_route_info_from_block(block_node)
|
184
|
+
send_node = block_node.send_node
|
185
|
+
method_name = send_node.method_name
|
186
|
+
route_name = extract_route_name(send_node)
|
187
|
+
return nil unless route_name
|
188
|
+
|
189
|
+
send_range = send_node.source_range
|
190
|
+
block_range = block_node.source_range
|
191
|
+
{
|
192
|
+
node: send_node,
|
193
|
+
method: method_name,
|
194
|
+
name: route_name,
|
195
|
+
line: send_range.line,
|
196
|
+
end_line: block_range.last_line,
|
197
|
+
namespace_level: @namespace_level,
|
198
|
+
namespace_path: @namespace_path.dup,
|
199
|
+
type: categorize_route_method(method_name)
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
155
203
|
def extract_route_name(node)
|
156
204
|
method_name = node.method_name
|
157
205
|
first_arg = node.arguments.first
|
@@ -173,6 +221,7 @@ module RuboCop
|
|
173
221
|
|
174
222
|
def extract_simple_route_name(first_arg)
|
175
223
|
return first_arg.value.to_s if first_arg&.str_type?
|
224
|
+
return first_arg.value.to_s if first_arg&.sym_type?
|
176
225
|
return extract_hash_route_name(first_arg) if first_arg&.hash_type?
|
177
226
|
|
178
227
|
'unknown'
|
@@ -190,7 +239,6 @@ module RuboCop
|
|
190
239
|
:other
|
191
240
|
end
|
192
241
|
end
|
193
|
-
# rubocop:enable Metrics/ClassLength
|
194
242
|
end
|
195
243
|
end
|
196
244
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-nueca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien
|
@@ -134,6 +134,7 @@ extensions: []
|
|
134
134
|
extra_rdoc_files: []
|
135
135
|
files:
|
136
136
|
- ".github/workflows/publish.yml"
|
137
|
+
- ".github/workflows/rubocop.yml"
|
137
138
|
- CODE_OF_CONDUCT.md
|
138
139
|
- LICENSE.txt
|
139
140
|
- README.md
|