Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error for Layout/EmptyLinesAroundExceptionHandlingKeywords #10193

Conversation

koic
Copy link
Member

@koic koic commented Oct 17, 2021

This PR fixes the following error for Layout/EmptyLinesAroundExceptionHandlingKeywords when begin and rescue are on the same line.

% echo 'begin; foo; rescue => e; end' | bundle exec rubocop --stdin
  example.rb -d
For /Users/koic/src/github.com/rubocop/rubocop: configuration from
  /Users/koic/src/github.com/rubocop/rubocop/.rubocop.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.11.5/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.11.5/config/default.yml
Default configuration from
  /Users/koic/src/github.com/rubocop/rubocop/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.5.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.5.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
Inheriting configuration from
  /Users/koic/src/github.com/rubocop/rubocop/.rubocop_todo.yml
Inspecting 1 file
Scanning /Users/koic/src/github.com/rubocop/rubocop/example.rb
An error occurred while Layout/EmptyLinesAroundExceptionHandlingKeywords
  cop was inspecting
  /Users/koic/src/github.com/rubocop/rubocop/example.rb:1:0.
The range 29...30 is outside the bounds of the source
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:406:in
  `check_range_validity'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/corrector.rb:100:in
  `check_range_validity'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:398:in
  `combine'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:194:in
  `replace'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:218:in
  `remove'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/correctors/empty_line_corrector.rb:13:in
  `correct'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:104:in
  `block in check_line'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/base.rb:342:in
  `correct'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/base.rb:127:in `add_offense'

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 `begin` and `rescue` are on the same line.

```console
% echo 'begin; foo; rescue => e; end' | bundle exec rubocop --stdin
  example.rb -d
For /Users/koic/src/github.com/rubocop/rubocop: configuration from
  /Users/koic/src/github.com/rubocop/rubocop/.rubocop.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.11.5/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-performance-1.11.5/config/default.yml
Default configuration from
  /Users/koic/src/github.com/rubocop/rubocop/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.5.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.5.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from
  /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rubocop-rake-0.6.0/config/default.yml
Inheriting configuration from
  /Users/koic/src/github.com/rubocop/rubocop/.rubocop_todo.yml
Inspecting 1 file
Scanning /Users/koic/src/github.com/rubocop/rubocop/example.rb
An error occurred while Layout/EmptyLinesAroundExceptionHandlingKeywords
  cop was inspecting
  /Users/koic/src/github.com/rubocop/rubocop/example.rb:1:0.
The range 29...30 is outside the bounds of the source
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:406:in
  `check_range_validity'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/corrector.rb:100:in
  `check_range_validity'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:398:in
  `combine'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:194:in
  `replace'
/Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/parser-3.0.2.0/lib/parser/source/tree_rewriter.rb:218:in
  `remove'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/correctors/empty_line_corrector.rb:13:in
  `correct'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/mixin/empty_lines_around_body.rb:104:in
  `block in check_line'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/base.rb:342:in
  `correct'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/base.rb:127:in `add_offense'
```
@koic koic force-pushed the fix_an_error_for_empty_lines_around_exception_handling_keywords branch from 4ef4076 to 95262d0 Compare October 17, 2021 09:19
@koic koic merged commit 1894717 into rubocop:master Oct 17, 2021
@koic koic deleted the fix_an_error_for_empty_lines_around_exception_handling_keywords branch October 17, 2021 19:12
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.

None yet

1 participant