Skip to content

Fix an error for Layout/EmptyLinesAroundExceptionHandlingKeywords#13172

Merged
koic merged 1 commit intorubocop:masterfrom
koic:fix_error_for_layout_empty_lines_around_exception_handling_keywords
Aug 30, 2024
Merged

Fix an error for Layout/EmptyLinesAroundExceptionHandlingKeywords#13172
koic merged 1 commit intorubocop:masterfrom
koic:fix_error_for_layout_empty_lines_around_exception_handling_keywords

Conversation

@koic
Copy link
Member

@koic koic commented Aug 30, 2024

This PR fixes the following error for Layout/EmptyLinesAroundExceptionHandlingKeywords when ensure and end are on the same line:

$ cat /tmp/example.rb
def do_something
ensure end

$ ruby -c /tmp/example.rb
Syntax OK

$ bundle exec rubocop /tmp/example.rb -a -d --only Layout/EmptyLinesAroundExceptionHandlingKeywords
(snip)

For /tmp: An error occurred while Layout/EmptyLinesAroundExceptionHandlingKeywords cop was inspecting /tmp/example.rb:1:0.
The range 28...29 is outside the bounds of the source
/Users/koic/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/parser-3.3.4.2/lib/parser/source/tree_rewriter.rb:406:
in 'Parser::Source::TreeRewriter#check_range_validity'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/corrector.rb:120:in 'RuboCop::Cop::Corrector#check_range_validity'

A similar issue can occur with else.


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 the following error for `Layout/EmptyLinesAroundExceptionHandlingKeywords`
when `ensure` and `end` are on the same line:

```console
$ cat /tmp/example.rb
def do_something
ensure end

$ ruby -c /tmp/example.rb
Syntax OK

$ bundle exec rubocop /tmp/example.rb -a -d --only Layout/EmptyLinesAroundExceptionHandlingKeywords
(snip)

For /tmp: An error occurred while Layout/EmptyLinesAroundExceptionHandlingKeywords cop was inspecting /tmp/example.rb:1:0.
The range 28...29 is outside the bounds of the source
/Users/koic/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/parser-3.3.4.2/lib/parser/source/tree_rewriter.rb:406:
in 'Parser::Source::TreeRewriter#check_range_validity'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/corrector.rb:120:in 'RuboCop::Cop::Corrector#check_range_validity'
```

A similar issue can occur with `else`.
@koic koic merged commit be6e656 into rubocop:master Aug 30, 2024
@koic koic deleted the fix_error_for_layout_empty_lines_around_exception_handling_keywords branch August 30, 2024 16:03
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