From 46f03a43b77e1a07502a4af5238b81799fb0ba20 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 21 Jan 2023 15:51:22 +0900 Subject: [PATCH] Mark `Minitest/RefuteFalse` as unsafe autocorrection Follow up https://github.com/rubocop/rubocop-minitest/issues/209#issuecomment-1385071429 This PR marks `Minitest/RefuteFalse` as unsafe autocorrection. --- ...ark_minitest_refute_false_as_unsafe_autocorrection.md | 1 + config/default.yml | 2 ++ lib/rubocop/cop/minitest/refute_false.rb | 9 +++++++++ 3 files changed, 12 insertions(+) create mode 100644 changelog/change_mark_minitest_refute_false_as_unsafe_autocorrection.md diff --git a/changelog/change_mark_minitest_refute_false_as_unsafe_autocorrection.md b/changelog/change_mark_minitest_refute_false_as_unsafe_autocorrection.md new file mode 100644 index 00000000..82e43f9f --- /dev/null +++ b/changelog/change_mark_minitest_refute_false_as_unsafe_autocorrection.md @@ -0,0 +1 @@ +* [#233](https://github.com/rubocop/rubocop-minitest/issues/233): Mark `Minitest/RefuteFalse` as unsafe autocorrection. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index f49a550f..9b2c65f8 100644 --- a/config/default.yml +++ b/config/default.yml @@ -191,7 +191,9 @@ Minitest/RefuteFalse: Description: 'Check if your test uses `refute(actual)` instead of `assert_equal(false, actual)`.' StyleGuide: 'https://minitest.rubystyle.guide#refute-false' Enabled: true + SafeAutoCorrect: false VersionAdded: '0.3' + VersionChanged: '<>' Minitest/RefuteInDelta: Description: 'This cop enforces the test to use `refute_in_delta` instead of using `refute_equal` to compare floats.' diff --git a/lib/rubocop/cop/minitest/refute_false.rb b/lib/rubocop/cop/minitest/refute_false.rb index 60bb19ae..dacdfed4 100644 --- a/lib/rubocop/cop/minitest/refute_false.rb +++ b/lib/rubocop/cop/minitest/refute_false.rb @@ -5,6 +5,15 @@ module Cop module Minitest # Enforces the use of `refute(object)` over `assert_equal(false, object)`. # + # @safety + # This cop's autocorrection is unsafe because it cannot detect failure when second argument is `nil`. + # + # [source,ruby] + # ---- + # assert_equal(false, nil) # failure + # refute(nil) # success + # ---- + # # @example # # bad # assert_equal(false, actual)