From 67e1f81bc5a956e87fff667a8b0e44c780ed4ec5 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 21 Mar 2021 19:35:13 +0900 Subject: [PATCH] Require RuboCop 0.90 or higher due to use `RESTRICT_ON_SEND` Follow https://github.com/rubocop-hq/rubocop/pull/8365 This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only. `RESTRICT_ON_SEND` has been introduced since RuboCop 0.90. --- CHANGELOG.md | 1 + lib/rubocop/cop/minitest/assert_empty_literal.rb | 1 + lib/rubocop/cop/minitest/assert_in_delta.rb | 2 ++ lib/rubocop/cop/minitest/assert_nil.rb | 1 + lib/rubocop/cop/minitest/assert_path_exists.rb | 1 + lib/rubocop/cop/minitest/assert_truthy.rb | 1 + lib/rubocop/cop/minitest/global_expectations.rb | 2 ++ lib/rubocop/cop/minitest/literal_as_actual_argument.rb | 1 + lib/rubocop/cop/minitest/refute_equal.rb | 1 + lib/rubocop/cop/minitest/refute_false.rb | 1 + lib/rubocop/cop/minitest/refute_in_delta.rb | 2 ++ lib/rubocop/cop/minitest/refute_nil.rb | 1 + lib/rubocop/cop/minitest/refute_path_exists.rb | 1 + lib/rubocop/cop/mixin/minitest_cop_rule.rb | 1 + rubocop-minitest.gemspec | 2 +- 15 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 737d192e..b83bc344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Changes * [#118](https://github.com/rubocop/rubocop-minitest/pull/118): **(BREAKING)** Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][]) +* [#125](https://github.com/rubocop/rubocop-minitest/pull/125): Require RuboCop 0.90 or higher. ([@koic][]) ## 0.10.3 (2021-01-12) diff --git a/lib/rubocop/cop/minitest/assert_empty_literal.rb b/lib/rubocop/cop/minitest/assert_empty_literal.rb index 1f42a386..f8915f6c 100644 --- a/lib/rubocop/cop/minitest/assert_empty_literal.rb +++ b/lib/rubocop/cop/minitest/assert_empty_literal.rb @@ -19,6 +19,7 @@ class AssertEmptyLiteral < Cop MSG = 'Prefer using `assert_empty(%s)` over ' \ '`assert_equal(%s, %s)`.' + RESTRICT_ON_SEND = %i[assert_equal].freeze def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN (send nil? :assert_equal ${hash array} $...) diff --git a/lib/rubocop/cop/minitest/assert_in_delta.rb b/lib/rubocop/cop/minitest/assert_in_delta.rb index 08924e54..235c826a 100644 --- a/lib/rubocop/cop/minitest/assert_in_delta.rb +++ b/lib/rubocop/cop/minitest/assert_in_delta.rb @@ -18,6 +18,8 @@ module Minitest class AssertInDelta < Cop include InDeltaMixin + RESTRICT_ON_SEND = %i[assert_equal].freeze + def_node_matcher :equal_floats_call, <<~PATTERN (send nil? :assert_equal $_ $_ $...) PATTERN diff --git a/lib/rubocop/cop/minitest/assert_nil.rb b/lib/rubocop/cop/minitest/assert_nil.rb index 5b2aa32e..52be7171 100644 --- a/lib/rubocop/cop/minitest/assert_nil.rb +++ b/lib/rubocop/cop/minitest/assert_nil.rb @@ -20,6 +20,7 @@ class AssertNil < Cop MSG = 'Prefer using `assert_nil(%s)` over ' \ '`assert_equal(nil, %s)`.' + RESTRICT_ON_SEND = %i[assert_equal].freeze def_node_matcher :assert_equal_with_nil, <<~PATTERN (send nil? :assert_equal nil $_ $...) diff --git a/lib/rubocop/cop/minitest/assert_path_exists.rb b/lib/rubocop/cop/minitest/assert_path_exists.rb index 9b3e3130..eab82f69 100644 --- a/lib/rubocop/cop/minitest/assert_path_exists.rb +++ b/lib/rubocop/cop/minitest/assert_path_exists.rb @@ -17,6 +17,7 @@ module Minitest # class AssertPathExists < Cop MSG = 'Prefer using `%s` over `%s`.' + RESTRICT_ON_SEND = %i[assert].freeze def_node_matcher :assert_file_exists, <<~PATTERN (send nil? :assert diff --git a/lib/rubocop/cop/minitest/assert_truthy.rb b/lib/rubocop/cop/minitest/assert_truthy.rb index eac79afe..3268f64f 100644 --- a/lib/rubocop/cop/minitest/assert_truthy.rb +++ b/lib/rubocop/cop/minitest/assert_truthy.rb @@ -20,6 +20,7 @@ class AssertTruthy < Cop MSG = 'Prefer using `assert(%s)` over ' \ '`assert_equal(true, %s)`.' + RESTRICT_ON_SEND = %i[assert_equal].freeze def_node_matcher :assert_equal_with_truthy, <<~PATTERN (send nil? :assert_equal true $_ $...) diff --git a/lib/rubocop/cop/minitest/global_expectations.rb b/lib/rubocop/cop/minitest/global_expectations.rb index f5301044..ba860170 100644 --- a/lib/rubocop/cop/minitest/global_expectations.rb +++ b/lib/rubocop/cop/minitest/global_expectations.rb @@ -30,6 +30,8 @@ class GlobalExpectations < Cop BLOCK_MATCHERS = %i[must_output must_raise must_be_silent must_throw].freeze + RESTRICT_ON_SEND = VALUE_MATCHERS + BLOCK_MATCHERS + VALUE_MATCHERS_STR = VALUE_MATCHERS.map do |m| ":#{m}" end.join(' ').freeze diff --git a/lib/rubocop/cop/minitest/literal_as_actual_argument.rb b/lib/rubocop/cop/minitest/literal_as_actual_argument.rb index 7b39178e..21069fe9 100644 --- a/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +++ b/lib/rubocop/cop/minitest/literal_as_actual_argument.rb @@ -21,6 +21,7 @@ class LiteralAsActualArgument < Cop include ArgumentRangeHelper MSG = 'Replace the literal with the first argument.' + RESTRICT_ON_SEND = %i[assert_equal].freeze def on_send(node) return unless node.method?(:assert_equal) diff --git a/lib/rubocop/cop/minitest/refute_equal.rb b/lib/rubocop/cop/minitest/refute_equal.rb index fa141d9e..32ac3619 100644 --- a/lib/rubocop/cop/minitest/refute_equal.rb +++ b/lib/rubocop/cop/minitest/refute_equal.rb @@ -19,6 +19,7 @@ class RefuteEqual < Cop MSG = 'Prefer using `refute_equal(%s)` over ' \ '`assert(%s)`.' + RESTRICT_ON_SEND = %i[assert].freeze def_node_matcher :assert_not_equal, <<~PATTERN (send nil? :assert ${(send $_ :!= $_) (send (send $_ :! ) :== $_) } $... ) diff --git a/lib/rubocop/cop/minitest/refute_false.rb b/lib/rubocop/cop/minitest/refute_false.rb index 803cce4f..9ae71f0b 100644 --- a/lib/rubocop/cop/minitest/refute_false.rb +++ b/lib/rubocop/cop/minitest/refute_false.rb @@ -25,6 +25,7 @@ class RefuteFalse < Cop '`assert_equal(false, %s)`.' MSG_FOR_ASSERT = 'Prefer using `refute(%s)` over ' \ '`assert(!%s)`.' + RESTRICT_ON_SEND = %i[assert_equal assert].freeze def_node_matcher :assert_equal_with_false, <<~PATTERN (send nil? :assert_equal false $_ $...) diff --git a/lib/rubocop/cop/minitest/refute_in_delta.rb b/lib/rubocop/cop/minitest/refute_in_delta.rb index 6a293e85..043d74c9 100644 --- a/lib/rubocop/cop/minitest/refute_in_delta.rb +++ b/lib/rubocop/cop/minitest/refute_in_delta.rb @@ -18,6 +18,8 @@ module Minitest class RefuteInDelta < Cop include InDeltaMixin + RESTRICT_ON_SEND = %i[refute_equal].freeze + def_node_matcher :equal_floats_call, <<~PATTERN (send nil? :refute_equal $_ $_ $...) PATTERN diff --git a/lib/rubocop/cop/minitest/refute_nil.rb b/lib/rubocop/cop/minitest/refute_nil.rb index 306bfdac..ae46dc2c 100644 --- a/lib/rubocop/cop/minitest/refute_nil.rb +++ b/lib/rubocop/cop/minitest/refute_nil.rb @@ -20,6 +20,7 @@ class RefuteNil < Cop MSG = 'Prefer using `refute_nil(%s)` over ' \ '`refute_equal(nil, %s)`.' + RESTRICT_ON_SEND = %i[refute_equal].freeze def_node_matcher :refute_equal_with_nil, <<~PATTERN (send nil? :refute_equal nil $_ $...) diff --git a/lib/rubocop/cop/minitest/refute_path_exists.rb b/lib/rubocop/cop/minitest/refute_path_exists.rb index feb9a473..a1c47fa2 100644 --- a/lib/rubocop/cop/minitest/refute_path_exists.rb +++ b/lib/rubocop/cop/minitest/refute_path_exists.rb @@ -17,6 +17,7 @@ module Minitest # class RefutePathExists < Cop MSG = 'Prefer using `%s` over `%s`.' + RESTRICT_ON_SEND = %i[refute].freeze def_node_matcher :refute_file_exists, <<~PATTERN (send nil? :refute diff --git a/lib/rubocop/cop/mixin/minitest_cop_rule.rb b/lib/rubocop/cop/mixin/minitest_cop_rule.rb index 5a30c05b..87750fc8 100644 --- a/lib/rubocop/cop/mixin/minitest_cop_rule.rb +++ b/lib/rubocop/cop/mixin/minitest_cop_rule.rb @@ -29,6 +29,7 @@ def define_rule(assertion_method, target_method:, preferred_method: nil, inverse MSG = 'Prefer using `#{preferred_method}(%s)` over ' \ '`#{assertion_method}(%s)`.' + RESTRICT_ON_SEND = %i[#{assertion_method}].freeze def on_send(node) return unless node.method?(:#{assertion_method}) diff --git a/rubocop-minitest.gemspec b/rubocop-minitest.gemspec index 843f2802..908ec6c6 100644 --- a/rubocop-minitest.gemspec +++ b/rubocop-minitest.gemspec @@ -34,6 +34,6 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'rubocop', '>= 0.87', '< 2.0' + spec.add_runtime_dependency 'rubocop', '>= 0.90', '< 2.0' spec.add_development_dependency 'minitest', '~> 5.11' end