Skip to content

Fix a false positive for Layout/EmptyLineAfterGuardClause#13455

Merged
koic merged 1 commit intorubocop:masterfrom
koic:fix_a_false_positive_for_layout_empty_line_after_guard_clause
Nov 14, 2024
Merged

Fix a false positive for Layout/EmptyLineAfterGuardClause#13455
koic merged 1 commit intorubocop:masterfrom
koic:fix_a_false_positive_for_layout_empty_line_after_guard_clause

Conversation

@koic
Copy link
Member

@koic koic commented Nov 13, 2024

This PR fixes a false positive for Layout/EmptyLineAfterGuardClause when using a guard clause outside oneliner block.

It avoids the following infinit loop error:

$ cat example.rb
return if condition; foo do
  bar
end

$ bundle exec rubocop --only Layout/EmptyLineAfterGuardClause,Layout/EmptyLinesAroundBlockBody -a
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if condition; foo do
^^^^^^^^^^^^^^^^^^^
example.rb:2:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/block/example.rb and
caused by Layout/EmptyLineAfterGuardClause -> Layout/EmptyLinesAroundBlockBody
Hint: Please update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
Please check the latest version at https://rubygems.org/gems/rubocop.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

This PR fixes a false positive for `Layout/EmptyLineAfterGuardClause`
when using a guard clause outside oneliner block.

It avoids the following infinit loop error:

```console
$ cat example.rb
return if condition; foo do
  bar
end

$ bundle exec rubocop --only Layout/EmptyLineAfterGuardClause,Layout/EmptyLinesAroundBlockBody -a
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
return if condition; foo do
^^^^^^^^^^^^^^^^^^^
example.rb:2:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/block/example.rb and
caused by Layout/EmptyLineAfterGuardClause -> Layout/EmptyLinesAroundBlockBody
Hint: Please update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
Please check the latest version at https://rubygems.org/gems/rubocop.
```
@koic koic force-pushed the fix_a_false_positive_for_layout_empty_line_after_guard_clause branch from 6d6d29a to 4cfcb87 Compare November 13, 2024 16:54
@koic koic merged commit cee7163 into rubocop:master Nov 14, 2024
@koic koic deleted the fix_a_false_positive_for_layout_empty_line_after_guard_clause branch November 14, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant