rubocop-minitest 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -9
- data/CHANGELOG.md +6 -0
- data/bin/console +4 -10
- data/config/default.yml +2 -2
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops_minitest.adoc +8 -4
- data/lib/rubocop/cop/minitest/assert_nil.rb +19 -15
- data/lib/rubocop/cop/minitest/refute_nil.rb +19 -17
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/cop/mixin/nil_assertion_handleable.rb +55 -0
- data/lib/rubocop/minitest/version.rb +1 -1
- data/relnotes/v0.15.0.md +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7a9c739cc54955a9c7647d8d5442c18f7888acb54212da90598fbec357717b
|
4
|
+
data.tar.gz: 784f7adfaeb34d54fedeaedcadd528cdffb6c888569a1314082b2c93217b5f3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7bf8ad7fa1be35b461ab54c2097ccd4c6fd320f1b15341c253f527099afeebee139feb33007f6b471309aaad6bb0f6f4534a52e32b2e3bc0f45344a4e5588ef
|
7
|
+
data.tar.gz: a73427443b2f4cb050f5e7893809f8026dbb41c4dc77461e6aa07fc13228e60f36a6bec7e893745eb14d911f143556003166028eb5abfcfea8f49b676ae50dbb
|
data/.rubocop.yml
CHANGED
@@ -25,16 +25,9 @@ Naming/PredicateName:
|
|
25
25
|
|
26
26
|
Naming/InclusiveLanguage:
|
27
27
|
FlaggedTerms:
|
28
|
-
|
28
|
+
offence:
|
29
29
|
Suggestions:
|
30
|
-
-
|
31
|
-
blacklist:
|
32
|
-
Suggestions:
|
33
|
-
- denylist
|
34
|
-
master:
|
35
|
-
AllowedRegex:
|
36
|
-
- 'blob/master/'
|
37
|
-
- 'master \(unreleased\)'
|
30
|
+
- offense
|
38
31
|
|
39
32
|
Style/FormatStringToken:
|
40
33
|
# Because we parse a lot of source codes from strings. Percent arrays
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.15.0 (2021-08-09)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#140](https://github.com/rubocop/rubocop-minitest/issues/140): Make `Minitest/AssertNil` and `Minitest/RefuteNil` aware of `assert(obj.nil?)` and `refute(obj.nil?)`. ([@koic][])
|
10
|
+
|
5
11
|
## 0.14.0 (2021-07-03)
|
6
12
|
|
7
13
|
### New features
|
data/bin/console
CHANGED
@@ -2,16 +2,10 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'bundler/setup'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require 'rubocop
|
8
|
-
|
9
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
-
# with your gem easier. You can also use a different console, if you like.
|
5
|
+
require 'irb'
|
6
|
+
require 'rubocop'
|
7
|
+
require 'rubocop-minitest'
|
11
8
|
|
12
|
-
|
13
|
-
# require "pry"
|
14
|
-
# Pry.start
|
9
|
+
ARGV.clear
|
15
10
|
|
16
|
-
require 'irb'
|
17
11
|
IRB.start(__FILE__)
|
data/config/default.yml
CHANGED
@@ -59,7 +59,7 @@ Minitest/AssertKindOf:
|
|
59
59
|
VersionAdded: '0.10'
|
60
60
|
|
61
61
|
Minitest/AssertNil:
|
62
|
-
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)`.'
|
62
|
+
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)` or `assert(something.nil?)`.'
|
63
63
|
StyleGuide: 'https://minitest.rubystyle.guide#assert-nil'
|
64
64
|
Enabled: true
|
65
65
|
VersionAdded: '0.1'
|
@@ -172,7 +172,7 @@ Minitest/RefuteKindOf:
|
|
172
172
|
VersionAdded: '0.10'
|
173
173
|
|
174
174
|
Minitest/RefuteNil:
|
175
|
-
Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)`.'
|
175
|
+
Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)` or `refute(something.nil?)`.'
|
176
176
|
StyleGuide: 'https://minitest.rubystyle.guide#refute-nil'
|
177
177
|
Enabled: true
|
178
178
|
VersionAdded: '0.2'
|
data/docs/antora.yml
CHANGED
@@ -261,8 +261,8 @@ assert_match(matcher, string, 'message')
|
|
261
261
|
| -
|
262
262
|
|===
|
263
263
|
|
264
|
-
This cop enforces the test to use `assert_nil`
|
265
|
-
|
264
|
+
This cop enforces the test to use `assert_nil` instead of using
|
265
|
+
`assert_equal(nil, something)` or `assert(something.nil?)`.
|
266
266
|
|
267
267
|
=== Examples
|
268
268
|
|
@@ -271,6 +271,8 @@ instead of using `assert_equal(nil, something)`.
|
|
271
271
|
# bad
|
272
272
|
assert_equal(nil, actual)
|
273
273
|
assert_equal(nil, actual, 'message')
|
274
|
+
assert(object.nil?)
|
275
|
+
assert(object.nil?, 'message')
|
274
276
|
|
275
277
|
# good
|
276
278
|
assert_nil(actual)
|
@@ -927,8 +929,8 @@ refute_match(matcher, string, 'message')
|
|
927
929
|
| -
|
928
930
|
|===
|
929
931
|
|
930
|
-
This cop enforces the test to use `refute_nil`
|
931
|
-
|
932
|
+
This cop enforces the test to use `refute_nil` instead of using
|
933
|
+
`refute_equal(nil, something)` or `refute(something.nil?)`.
|
932
934
|
|
933
935
|
=== Examples
|
934
936
|
|
@@ -937,6 +939,8 @@ instead of using `refute_equal(nil, something)`.
|
|
937
939
|
# bad
|
938
940
|
refute_equal(nil, actual)
|
939
941
|
refute_equal(nil, actual, 'message')
|
942
|
+
refute(actual.nil?)
|
943
|
+
refute(actual.nil?, 'message')
|
940
944
|
|
941
945
|
# good
|
942
946
|
refute_nil(actual)
|
@@ -3,13 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
# This cop enforces the test to use `assert_nil`
|
7
|
-
#
|
6
|
+
# This cop enforces the test to use `assert_nil` instead of using
|
7
|
+
# `assert_equal(nil, something)` or `assert(something.nil?)`.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# assert_equal(nil, actual)
|
12
12
|
# assert_equal(nil, actual, 'message')
|
13
|
+
# assert(object.nil?)
|
14
|
+
# assert(object.nil?, 'message')
|
13
15
|
#
|
14
16
|
# # good
|
15
17
|
# assert_nil(actual)
|
@@ -17,27 +19,29 @@ module RuboCop
|
|
17
19
|
#
|
18
20
|
class AssertNil < Base
|
19
21
|
include ArgumentRangeHelper
|
22
|
+
include NilAssertionHandleable
|
20
23
|
extend AutoCorrector
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
25
|
+
ASSERTION_TYPE = 'assert'
|
26
|
+
RESTRICT_ON_SEND = %i[assert_equal assert].freeze
|
25
27
|
|
26
|
-
def_node_matcher :
|
27
|
-
|
28
|
+
def_node_matcher :nil_assertion, <<~PATTERN
|
29
|
+
{
|
30
|
+
(send nil? :assert_equal nil $_ $...)
|
31
|
+
(send nil? :assert (send $_ :nil?) $...)
|
32
|
+
}
|
28
33
|
PATTERN
|
29
34
|
|
30
35
|
def on_send(node)
|
31
|
-
|
32
|
-
|
36
|
+
nil_assertion(node) do |actual, message|
|
37
|
+
register_offense(node, actual, message)
|
38
|
+
end
|
39
|
+
end
|
33
40
|
|
34
|
-
|
41
|
+
private
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
corrector.replace(first_and_second_arguments_range(node), actual.source)
|
39
|
-
end
|
40
|
-
end
|
43
|
+
def assertion_type
|
44
|
+
ASSERTION_TYPE
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -3,13 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Minitest
|
6
|
-
# This cop enforces the test to use `refute_nil`
|
7
|
-
#
|
6
|
+
# This cop enforces the test to use `refute_nil` instead of using
|
7
|
+
# `refute_equal(nil, something)` or `refute(something.nil?)`.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# refute_equal(nil, actual)
|
12
12
|
# refute_equal(nil, actual, 'message')
|
13
|
+
# refute(actual.nil?)
|
14
|
+
# refute(actual.nil?, 'message')
|
13
15
|
#
|
14
16
|
# # good
|
15
17
|
# refute_nil(actual)
|
@@ -17,29 +19,29 @@ module RuboCop
|
|
17
19
|
#
|
18
20
|
class RefuteNil < Base
|
19
21
|
include ArgumentRangeHelper
|
22
|
+
include NilAssertionHandleable
|
20
23
|
extend AutoCorrector
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
RESTRICT_ON_SEND = %i[refute_equal].freeze
|
25
|
+
ASSERTION_TYPE = 'refute'
|
26
|
+
RESTRICT_ON_SEND = %i[refute_equal refute].freeze
|
25
27
|
|
26
|
-
def_node_matcher :
|
27
|
-
|
28
|
+
def_node_matcher :nil_refutation, <<~PATTERN
|
29
|
+
{
|
30
|
+
(send nil? :refute_equal nil $_ $...)
|
31
|
+
(send nil? :refute (send $_ :nil?) $...)
|
32
|
+
}
|
28
33
|
PATTERN
|
29
34
|
|
30
35
|
def on_send(node)
|
31
|
-
|
32
|
-
|
36
|
+
nil_refutation(node) do |actual, message|
|
37
|
+
register_offense(node, actual, message)
|
38
|
+
end
|
39
|
+
end
|
33
40
|
|
34
|
-
|
41
|
+
private
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
corrector.replace(
|
39
|
-
first_and_second_arguments_range(node), actual.source
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
+
def assertion_type
|
44
|
+
ASSERTION_TYPE
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -4,6 +4,7 @@ require_relative 'mixin/argument_range_helper'
|
|
4
4
|
require_relative 'mixin/in_delta_mixin'
|
5
5
|
require_relative 'mixin/minitest_cop_rule'
|
6
6
|
require_relative 'mixin/minitest_exploration_helpers'
|
7
|
+
require_relative 'mixin/nil_assertion_handleable'
|
7
8
|
require_relative 'minitest/assert_empty'
|
8
9
|
require_relative 'minitest/assert_empty_literal'
|
9
10
|
require_relative 'minitest/assert_equal'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# Common functionality for `AssertNil` and `RefuteNil` cops.
|
7
|
+
module NilAssertionHandleable
|
8
|
+
MSG = 'Prefer using `%<assertion_type>s_nil(%<preferred_args>s)` over `%<method>s(%<current_args>s)`.'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def register_offense(node, actual, message)
|
13
|
+
message = build_message(node, actual, message)
|
14
|
+
|
15
|
+
add_offense(node, message: message) do |corrector|
|
16
|
+
autocorrect(corrector, node, actual)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_message(node, actual, message)
|
21
|
+
message = message.first
|
22
|
+
message_source = message&.source
|
23
|
+
|
24
|
+
preferred_args = [actual.source, message_source].compact
|
25
|
+
current_args = if comparison_assertion_method?(node)
|
26
|
+
['nil', preferred_args].join(', ')
|
27
|
+
else
|
28
|
+
["#{actual.source}.nil?", message_source].compact.join(', ')
|
29
|
+
end
|
30
|
+
|
31
|
+
format(
|
32
|
+
MSG,
|
33
|
+
assertion_type: assertion_type,
|
34
|
+
preferred_args: preferred_args.join(', '),
|
35
|
+
method: node.method_name, current_args: current_args
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def autocorrect(corrector, node, actual)
|
40
|
+
corrector.replace(node.loc.selector, :"#{assertion_type}_nil")
|
41
|
+
if comparison_assertion_method?(node)
|
42
|
+
corrector.replace(first_and_second_arguments_range(node), actual.source)
|
43
|
+
else
|
44
|
+
corrector.remove(node.first_argument.loc.dot)
|
45
|
+
corrector.remove(node.first_argument.loc.selector)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def comparison_assertion_method?(node)
|
50
|
+
node.method?(:"#{assertion_type}_equal")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/relnotes/v0.15.0.md
ADDED
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.15.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: 2021-
|
13
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/rubocop/cop/mixin/in_delta_mixin.rb
|
126
126
|
- lib/rubocop/cop/mixin/minitest_cop_rule.rb
|
127
127
|
- lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
|
128
|
+
- lib/rubocop/cop/mixin/nil_assertion_handleable.rb
|
128
129
|
- lib/rubocop/minitest.rb
|
129
130
|
- lib/rubocop/minitest/inject.rb
|
130
131
|
- lib/rubocop/minitest/version.rb
|
@@ -141,6 +142,7 @@ files:
|
|
141
142
|
- relnotes/v0.12.1.md
|
142
143
|
- relnotes/v0.13.0.md
|
143
144
|
- relnotes/v0.14.0.md
|
145
|
+
- relnotes/v0.15.0.md
|
144
146
|
- relnotes/v0.2.0.md
|
145
147
|
- relnotes/v0.2.1.md
|
146
148
|
- relnotes/v0.3.0.md
|
@@ -165,7 +167,7 @@ metadata:
|
|
165
167
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
166
168
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
167
169
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
168
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
170
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.15
|
169
171
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
170
172
|
post_install_message:
|
171
173
|
rdoc_options: []
|