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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a49b9e5e060e7ec154ef9feaf553325fb156d58c59aba67ea3cc2ac1e1e13b67
4
- data.tar.gz: 3e110fe0c9a710158865e3f67a443dacde11a7aba68f92df3ff305016cc2fdbc
3
+ metadata.gz: 86a3f50ec1bdcbb388b5843fc52caa7424579538bf73f995f3121a8e39e23544
4
+ data.tar.gz: e94a2e703f0ac39efa1ac5b9886fa711f7c2b5c482a6f27d9a4301af4bdae4eb
5
5
  SHA512:
6
- metadata.gz: 376a36b1a4e897c49af1fc553504471e2c9014e8bfb1b147dc9f0d1af5f5202acb3e91feaf382310f17468e7515b1c59d2cb8d0198285418d5733cf2a643742d
7
- data.tar.gz: 910aef0f0fd56d15ef56c1fe7b2e3bb2ebc18d65dfb35aa7c88ab698e6e6ed8fe8bd21635ff3ca94f85c10f9c730d81b5fc3b247a4412dfb180f9f869093d693
6
+ metadata.gz: 330371fdc147e6d9469a230d0a47545cc8855117c2cb9c6a5ab828946eb353357579b238db05658357f3301927dc5b9da868711691a84da4975741cf369c2db6
7
+ data.tar.gz: b9941dd2e7f84e12f5ceab85b2508e185ab80f04c06d387786f51949770f8faace0c023101f99322be2fb69cc69d020ce19cb814b60be47925242b23a1660938
@@ -1,12 +1,16 @@
1
1
  name: Publish Gem
2
2
 
3
3
  on:
4
- push:
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
- add_route_if_valid(send_node)
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 send_node.method_name
72
+ case method_name
65
73
  when :namespace
66
- namespace_name = extract_namespace_name(send_node)
67
- new_namespace_path << namespace_name if namespace_name
74
+ add_namespace_to_path(new_namespace_path, send_node)
68
75
  when :scope
69
- scope_name = extract_scope_name(send_node)
70
- new_namespace_path << scope_name if scope_name
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Nueca
5
- VERSION = '1.2.2'
5
+ VERSION = '1.2.5'
6
6
  end
7
7
  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.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