rubocop-nueca 2.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb34764da703f11ac54951f9b92fddc4c12b02484a16db639037492673777fa9
4
- data.tar.gz: f5b592ac30bbb9dd3dc453755a3381e24afe704766cd5025a318f92b53eca7d9
3
+ metadata.gz: 81918c1ee3c1d72d3bfdf6914398dab599378c4a37ae66419afb23792c35386e
4
+ data.tar.gz: a4348608537bc0876333bb78e4757770f91859623e83c3353b013e4d7233f1a2
5
5
  SHA512:
6
- metadata.gz: 16f6447cb675eb5d93683147d8bc253b9aad89b0f7eacd6a1c006b07713743ecb20c5ba84cff87361a3184a69000dc08f85bc6121723b11579409f73d98ebcba
7
- data.tar.gz: 6efdbd1a9a74ada84396470d81789e4cbc8552bb4b6e92d1e6bee5ae5cd534c12bffdb6152ed25bc8448ce31a999de6d1f447e2a450cc6eece9e5655b6213fd9
6
+ metadata.gz: 3e41c08ebed4ab33a3b41227cc97d1506d3c289aedf7468f8d8925d8b0ef792f8780d5a510aade458dfd08624bdb36aee4975d63c9689c68f8f9283a0dc7e679
7
+ data.tar.gz: a0c05dfcf12646d2c881bfa80f87d70bddfed41916b317f2544823b47b93a71233be42331b7926c9a41be39211dfed96cfaa9f07d7b723df18faee1cd41a87a9
data/config/default.yml CHANGED
@@ -96,6 +96,10 @@ Rails/UnknownEnv:
96
96
  - test
97
97
  - staging
98
98
 
99
+ RSpec/ScatteredSetup:
100
+ Exclude:
101
+ - spec/requests/api/**/*_spec.rb
102
+
99
103
  RSpec/MultipleExpectations:
100
104
  Enabled: false
101
105
 
@@ -166,9 +170,6 @@ Style/ClassMethodsDefinitions:
166
170
  Style/ImplicitRuntimeError:
167
171
  Enabled: true
168
172
 
169
- Style/InvertibleUnlessCondition:
170
- Enabled: true
171
-
172
173
  Style/IpAddresses:
173
174
  Enabled: true
174
175
 
@@ -13,7 +13,7 @@ module RuboCop
13
13
  PATTERN
14
14
 
15
15
  def on_send(node)
16
- return if node.source_range.source_buffer.name.exclude?('_spec.rb')
16
+ return unless node.source_range.source_buffer.name.include?('_spec.rb')
17
17
  return unless datetime_usage(node)
18
18
 
19
19
  add_offense(node)
@@ -11,7 +11,7 @@ module RuboCop
11
11
  PATTERN
12
12
 
13
13
  def on_send(node)
14
- return if node.source_range.source_buffer.name.exclude?('_spec.rb')
14
+ return unless node.source_range.source_buffer.name.include?('_spec.rb')
15
15
  return unless browser_usage(node)
16
16
 
17
17
  add_offense(node)
@@ -29,7 +29,7 @@ module RuboCop
29
29
 
30
30
  def on_send(node)
31
31
  buffer = node.source_range.source_buffer
32
- return if buffer.name.exclude?('_spec.rb')
32
+ return unless buffer.name.include?('_spec.rb')
33
33
  return unless require_mongoid_helper(node)
34
34
 
35
35
  root_node = processed_source.ast
@@ -60,7 +60,7 @@ module RuboCop
60
60
  prev_end_line = prev_assoc.loc.last_line
61
61
  curr_start_line = curr_assoc.loc.line
62
62
 
63
- next if curr_start_line - prev_end_line <= 1
63
+ next unless curr_start_line - prev_end_line > 1
64
64
 
65
65
  add_offense(curr_assoc, message: MSG)
66
66
  end
@@ -67,7 +67,7 @@ module RuboCop
67
67
  def check_same_type_grouping(same_type_associations, all_associations)
68
68
  groups = find_contiguous_groups(same_type_associations, all_associations)
69
69
 
70
- return if groups.length <= 1
70
+ return unless groups.length > 1
71
71
 
72
72
  groups[1..].each do |group|
73
73
  add_offense(group.first, message: MSG)
@@ -99,7 +99,7 @@ module RuboCop
99
99
  end
100
100
 
101
101
  def finalize_group(groups, current_group)
102
- return if current_group.none?
102
+ return unless current_group.any?
103
103
 
104
104
  groups << current_group.dup
105
105
  current_group.clear
@@ -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
@@ -44,7 +44,7 @@ module RuboCop
44
44
  send_node = node.send_node
45
45
  return unless send_node.send_type? && route_method?(send_node)
46
46
 
47
- add_route_block_if_valid(node) if [:member, :collection].exclude?(send_node.method_name)
47
+ add_route_block_if_valid(node) unless [:member, :collection].include?(send_node.method_name)
48
48
  process_nested_context(node)
49
49
  end
50
50
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Nueca
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  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 Rails cops
10
- Dir[File.join(__dir__, 'rubocop', 'cop', 'rails', '*.rb')].each do |file|
11
- require file
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.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