rubocop-nueca 1.2.2 → 1.2.3
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 +30 -5
- 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: a3678eac28f6575b9cee5fb58f88a02e46de0c91bf36437a242fc34208cd4da3
|
4
|
+
data.tar.gz: a11bbc18d306047a0b8c1b329430b15d92bff287190adcd99e9994eceb4d33d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ab9039fb41adbeb81026aa2d7bfa8f4f542c6566f01c0c853fce78ee6b987919750c983524eef7cc467902f7b6b1e7921a542ea48c1ff624d8eece8d96e5f1
|
7
|
+
data.tar.gz: '078491a8477ad8a25a19c0a6a6e38541f599cc5d44efc35ec24974e86eec267fd1026c5517063367e7a64163f595014f1d912d6cc467f1fd828c7b044b2eb550'
|
@@ -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,8 +3,7 @@
|
|
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],
|
@@ -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)
|
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
|
@@ -84,7 +91,6 @@ module RuboCop
|
|
84
91
|
scope_name = extract_scope_option_value(node)
|
85
92
|
return scope_name if scope_name
|
86
93
|
|
87
|
-
# If no module/path specified, use first argument if it's a symbol/string
|
88
94
|
first_arg = node.arguments.first
|
89
95
|
return first_arg.value.to_s if first_arg&.sym_type? || first_arg&.str_type?
|
90
96
|
|
@@ -152,6 +158,26 @@ module RuboCop
|
|
152
158
|
}
|
153
159
|
end
|
154
160
|
|
161
|
+
def build_route_info_from_block(block_node)
|
162
|
+
send_node = block_node.send_node
|
163
|
+
method_name = send_node.method_name
|
164
|
+
route_name = extract_route_name(send_node)
|
165
|
+
return nil unless route_name
|
166
|
+
|
167
|
+
send_range = send_node.source_range
|
168
|
+
block_range = block_node.source_range
|
169
|
+
{
|
170
|
+
node: send_node,
|
171
|
+
method: method_name,
|
172
|
+
name: route_name,
|
173
|
+
line: send_range.line,
|
174
|
+
end_line: block_range.last_line,
|
175
|
+
namespace_level: @namespace_level,
|
176
|
+
namespace_path: @namespace_path.dup,
|
177
|
+
type: categorize_route_method(method_name)
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
155
181
|
def extract_route_name(node)
|
156
182
|
method_name = node.method_name
|
157
183
|
first_arg = node.arguments.first
|
@@ -190,7 +216,6 @@ module RuboCop
|
|
190
216
|
:other
|
191
217
|
end
|
192
218
|
end
|
193
|
-
# rubocop:enable Metrics/ClassLength
|
194
219
|
end
|
195
220
|
end
|
196
221
|
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.3
|
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
|