From f8057747ebc155d943b7614ebaa26708d5fa631a Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Thu, 4 Aug 2022 09:26:03 -0400 Subject: [PATCH] Mark autocorrection for `Lint/EmptyConditionalBody` as unsafe. --- changelog/fix_mark_autocorrection_for.md | 1 + config/default.yml | 3 ++- lib/rubocop/cop/lint/empty_conditional_body.rb | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_mark_autocorrection_for.md diff --git a/changelog/fix_mark_autocorrection_for.md b/changelog/fix_mark_autocorrection_for.md new file mode 100644 index 00000000000..7e48f24a42c --- /dev/null +++ b/changelog/fix_mark_autocorrection_for.md @@ -0,0 +1 @@ +* [#10867](https://github.com/rubocop/rubocop/pull/10867): Mark autocorrection for `Lint/EmptyConditionalBody` as unsafe. ([@dvandersluis][]) diff --git a/config/default.yml b/config/default.yml index 2f9b1f89f96..4ca18ed5ee9 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1753,9 +1753,10 @@ Lint/EmptyClass: Lint/EmptyConditionalBody: Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.' Enabled: true + SafeAutoCorrect: false AllowComments: true VersionAdded: '0.89' - VersionChanged: '1.33' + VersionChanged: '<>' Lint/EmptyEnsure: Description: 'Checks for empty ensure block.' diff --git a/lib/rubocop/cop/lint/empty_conditional_body.rb b/lib/rubocop/cop/lint/empty_conditional_body.rb index 805d8a26880..28f13403af9 100644 --- a/lib/rubocop/cop/lint/empty_conditional_body.rb +++ b/lib/rubocop/cop/lint/empty_conditional_body.rb @@ -7,6 +7,11 @@ module Lint # # NOTE: empty `else` branches are handled by `Style/EmptyElse`. # + # @safety + # Autocorrection for this cop is not safe. The conditions for empty branches that + # the autocorrection removes may have side effects, or the logic in subsequent + # branches may change due to the removal of a previous condition. + # # @example # # bad # if condition