rubocop-nueca 2.0.1 → 2.1.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 +4 -4
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/rswag/scattered_setup.rb +35 -0
- data/lib/rubocop/nueca/version.rb +1 -1
- data/lib/rubocop-nueca.rb +5 -3
- 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: 81918c1ee3c1d72d3bfdf6914398dab599378c4a37ae66419afb23792c35386e
|
4
|
+
data.tar.gz: a4348608537bc0876333bb78e4757770f91859623e83c3353b013e4d7233f1a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e41c08ebed4ab33a3b41227cc97d1506d3c289aedf7468f8d8925d8b0ef792f8780d5a510aade458dfd08624bdb36aee4975d63c9689c68f8f9283a0dc7e679
|
7
|
+
data.tar.gz: a0c05dfcf12646d2c881bfa80f87d70bddfed41916b317f2544823b47b93a71233be42331b7926c9a41be39211dfed96cfaa9f07d7b723df18faee1cd41a87a9
|
data/config/default.yml
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSwag
|
6
|
+
class ScatteredSetup < RuboCop::Cop::Base
|
7
|
+
MSG = 'Do not define multiple hooks of the same type in the same response group.'
|
8
|
+
|
9
|
+
def on_block(node)
|
10
|
+
return unless rswag_test?(node)
|
11
|
+
|
12
|
+
hooks = analyzable_hooks(node)
|
13
|
+
hooks.group_by { |hook| hook.send_node.method_name }.each_value do |group|
|
14
|
+
next if group.size <= 1
|
15
|
+
|
16
|
+
group[1..].each { |hook| add_offense(hook) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def rswag_test?(_node)
|
23
|
+
processed_source.file_path&.include?('spec/requests/api')
|
24
|
+
end
|
25
|
+
|
26
|
+
def analyzable_hooks(node)
|
27
|
+
hook_methods = [:before, :after, :around]
|
28
|
+
node.body&.each_child_node(:block)&.select do |blk|
|
29
|
+
hook_methods.include?(blk.send_node&.method_name)
|
30
|
+
end || []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rubocop-nueca.rb
CHANGED
@@ -6,7 +6,9 @@ require 'rubocop'
|
|
6
6
|
# Load the plugin
|
7
7
|
require_relative 'rubocop/nueca/plugin'
|
8
8
|
|
9
|
-
# Load all custom
|
10
|
-
|
11
|
-
|
9
|
+
# Load all custom cops
|
10
|
+
['rails', 'rswag'].each do |subdir|
|
11
|
+
Dir[File.join(__dir__, 'rubocop', 'cop', subdir, '*.rb')].each do |file|
|
12
|
+
require file
|
13
|
+
end
|
12
14
|
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: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/rubocop/cop/rails/route_separation.rb
|
154
154
|
- lib/rubocop/cop/rails/route_sorting.rb
|
155
155
|
- lib/rubocop/cop/rails/time_zone_today.rb
|
156
|
+
- lib/rubocop/cop/rswag/scattered_setup.rb
|
156
157
|
- lib/rubocop/cop/shared/collection_context.rb
|
157
158
|
- lib/rubocop/cop/shared/route_collector.rb
|
158
159
|
- lib/rubocop/cop/shared/route_helper.rb
|