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 +4 -4
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb +76 -0
- data/lib/rubocop/cop/minitest/refute_match.rb +1 -1
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/minitest/assert_offense.rb +27 -1
- data/lib/rubocop/minitest/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c1c1e73140c8a3b7a03627a9e7a8772a91468924a78a55ef9d7eb1de01c41b
|
4
|
+
data.tar.gz: b04c7e1341cbe6792b360ef49fc495a0534dbbc817cc1c3643465018c5ef7776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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
|
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.
|
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-
|
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.
|
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:
|