rubocop-minitest 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6db30fddaa89f75fb61790465161c9de6e0fd0c7d3808afa9d091e9eac97a30e
4
- data.tar.gz: fbf5dac86cbf247ded62e437f5cb79e8c1dece32b7ec78eeda0b3c8c20fdd7d7
3
+ metadata.gz: 27c1c1e73140c8a3b7a03627a9e7a8772a91468924a78a55ef9d7eb1de01c41b
4
+ data.tar.gz: b04c7e1341cbe6792b360ef49fc495a0534dbbc817cc1c3643465018c5ef7776
5
5
  SHA512:
6
- metadata.gz: b5c7535584d692c5a2e4c62ddcfdd89939594b6c51082ba2d497f81b36b8a0b7153940c2846a14dfea681f5fe51753324e90e4d7488fb477a96e99b7aa8f2a77
7
- data.tar.gz: 5e53402c171a4dabe59f71a8d102cfd5e8dd963c47d082f305803c749f258bcf1c114e552cbc8fde60a0486002348520c6dd46fa06d3476a80b5b967835e2013
6
+ metadata.gz: 60a86b10b510ca5da0d49d647ff5e20d8296e6fbb89214b3e2cb371eaf3096d4e866b3ebafeac446ae7ee6e0d2a139eadbcc77a4e23c144c10332acdef92f552
7
+ data.tar.gz: 31acd00dd4c8cbe95e50926694a1c844cb21c1ac6c9695d6a9fa120e9d936b16a7869f44552bcc413e737bf4983be67a2481935940fb5515422e5d14a2b4f0bf
data/config/default.yml CHANGED
@@ -122,6 +122,11 @@ Minitest/DuplicateTestRun:
122
122
  Enabled: pending
123
123
  VersionAdded: '0.19'
124
124
 
125
+ Minitest/EmptyLineBeforeAssertionMethods:
126
+ Description: 'Add empty line before assertion methods.'
127
+ Enabled: pending
128
+ VersionAdded: '0.23'
129
+
125
130
  Minitest/GlobalExpectations:
126
131
  Description: 'This cop checks for deprecated global expectations.'
127
132
  StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Enforces empty line before assertion methods because it separates assertion phase.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # do_something
12
+ # assert_equal(expected, actual)
13
+ #
14
+ # # good
15
+ # do_something
16
+ #
17
+ # assert_equal(expected, actual)
18
+ #
19
+ class EmptyLineBeforeAssertionMethods < Base
20
+ include MinitestExplorationHelpers
21
+ extend AutoCorrector
22
+
23
+ MSG = 'Add empty line before assertion.'
24
+
25
+ def on_send(node)
26
+ return unless assertion_method?(node)
27
+ return unless (previous_line_node = node.left_sibling)
28
+ return if accept_previous_line?(previous_line_node, node)
29
+
30
+ previous_line_node = previous_line_node.arguments.last if use_heredoc_argument?(previous_line_node)
31
+ return unless no_empty_line?(previous_line_node, node)
32
+
33
+ register_offense(node, previous_line_node)
34
+ end
35
+
36
+ private
37
+
38
+ def accept_previous_line?(previous_line_node, node)
39
+ return true if previous_line_node.args_type? || node.parent.basic_conditional?
40
+
41
+ previous_line_node.send_type? && assertion_method?(previous_line_node)
42
+ end
43
+
44
+ def use_heredoc_argument?(node)
45
+ node.respond_to?(:arguments) && heredoc?(node.arguments.last)
46
+ end
47
+
48
+ def heredoc?(last_argument)
49
+ last_argument.respond_to?(:heredoc?) && last_argument.heredoc?
50
+ end
51
+
52
+ def no_empty_line?(previous_line_node, node)
53
+ previous_line = if heredoc?(previous_line_node)
54
+ previous_line_node.loc.heredoc_end.line
55
+ else
56
+ previous_line_node.loc.last_line
57
+ end
58
+
59
+ previous_line + 1 == node.loc.line
60
+ end
61
+
62
+ def register_offense(node, previous_line_node)
63
+ add_offense(node) do |corrector|
64
+ range = if heredoc?(previous_line_node)
65
+ previous_line_node.loc.heredoc_end
66
+ else
67
+ previous_line_node
68
+ end
69
+
70
+ corrector.insert_after(range, "\n")
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  class RefuteMatch < Base
19
19
  extend MinitestCopRule
20
20
 
21
- define_rule :refute, target_method: :match
21
+ define_rule :refute, target_method: :match, inverse: 'regexp_type?'
22
22
  end
23
23
  end
24
24
  end
@@ -26,6 +26,7 @@ require_relative 'minitest/assert_respond_to'
26
26
  require_relative 'minitest/assert_silent'
27
27
  require_relative 'minitest/assert_truthy'
28
28
  require_relative 'minitest/duplicate_test_run'
29
+ require_relative 'minitest/empty_line_before_assertion_methods'
29
30
  require_relative 'minitest/global_expectations'
30
31
  require_relative 'minitest/literal_as_actual_argument'
31
32
  require_relative 'minitest/multiple_assertions'
@@ -172,7 +172,33 @@ module RuboCop
172
172
  file = file.path
173
173
  end
174
174
 
175
- RuboCop::ProcessedSource.new(source, ruby_version, file)
175
+ processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)
176
+
177
+ # Follow up https://github.com/rubocop/rubocop/pull/10987.
178
+ # When support for RuboCop 1.37.1 ends, this condition can be removed.
179
+ if processed_source.respond_to?(:config) && processed_source.respond_to?(:registry)
180
+ processed_source.config = configuration
181
+ processed_source.registry = registry
182
+ end
183
+
184
+ processed_source
185
+ end
186
+
187
+ def configuration
188
+ @configuration ||= if defined?(config)
189
+ config
190
+ else
191
+ RuboCop::Config.new({}, "#{Dir.pwd}/.rubocop.yml")
192
+ end
193
+ end
194
+
195
+ def registry
196
+ @registry ||= begin
197
+ cops = configuration.keys.map { |cop| RuboCop::Cop::Registry.global.find_by_cop_name(cop) }
198
+ cops << cop_class if defined?(cop_class) && !cops.include?(cop_class)
199
+ cops.compact!
200
+ RuboCop::Cop::Registry.new(cops)
201
+ end
176
202
  end
177
203
 
178
204
  def ruby_version
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Minitest
5
5
  # This module holds the RuboCop Minitest version information.
6
6
  module Version
7
- STRING = '0.22.1'
7
+ STRING = '0.23.0'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-09-18 00:00:00.000000000 Z
13
+ date: 2022-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -79,6 +79,7 @@ files:
79
79
  - lib/rubocop/cop/minitest/assert_with_expected_argument.rb
80
80
  - lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
81
81
  - lib/rubocop/cop/minitest/duplicate_test_run.rb
82
+ - lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb
82
83
  - lib/rubocop/cop/minitest/global_expectations.rb
83
84
  - lib/rubocop/cop/minitest/literal_as_actual_argument.rb
84
85
  - lib/rubocop/cop/minitest/multiple_assertions.rb
@@ -118,7 +119,7 @@ metadata:
118
119
  homepage_uri: https://docs.rubocop.org/rubocop-minitest/
119
120
  changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
120
121
  source_code_uri: https://github.com/rubocop/rubocop-minitest
121
- documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.22
122
+ documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.23
122
123
  bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
123
124
  rubygems_mfa_required: 'true'
124
125
  post_install_message: