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

EmptyLinesAroundExceptionHandlingKeywords fails on one-liner rescue #10379

Closed
MaxLap opened this issue Jan 27, 2022 · 0 comments · Fixed by #10381
Closed

EmptyLinesAroundExceptionHandlingKeywords fails on one-liner rescue #10379

MaxLap opened this issue Jan 27, 2022 · 0 comments · Fixed by #10381
Labels

Comments

@MaxLap
Copy link
Contributor

MaxLap commented Jan 27, 2022

Expected behavior

I know it's poor code, that's why I'm trying to setup RuboCop for it, but each of the following 3 snippets make rubocop unable to process the file they are in.

begin
  foo
rescue; end
begin
  foo
rescue; bar; end
begin
  foo
rescue StandardError; bar; end

Actual behavior

Scanning /home/max/projects/haml-lint/_localstuff/ruby_to_fix1.rb
An error occurred while Layout/EmptyLinesAroundExceptionHandlingKeywords cop was inspecting /home/max/projects/haml-lint/_localstuff/ruby_to_fix1.rb:1:0.
The range 24...25 is outside the bounds of the source
/home/max/.rvm/gems/ruby-2.6.3/gems/parser-3.1.0.0/lib/parser/source/tree_rewriter.rb:406:in `check_range_validity'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/corrector.rb:100:in `check_range_validity'
/home/max/.rvm/gems/ruby-2.6.3/gems/parser-3.1.0.0/lib/parser/source/tree_rewriter.rb:398:in `combine'
/home/max/.rvm/gems/ruby-2.6.3/gems/parser-3.1.0.0/lib/parser/source/tree_rewriter.rb:194:in `replace'
/home/max/.rvm/gems/ruby-2.6.3/gems/parser-3.1.0.0/lib/parser/source/tree_rewriter.rb:218:in `remove'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/correctors/empty_line_corrector.rb:13:in `correct'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/mixin/empty_lines_around_body.rb:104:in `block in check_line'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/base.rb:342:in `correct'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/mixin/empty_lines_around_body.rb:103:in `check_line'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb:88:in `block in check_body'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb:82:in `each'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb:82:in `check_body'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb:74:in `on_kwbegin'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:98:in `each'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:69:in `on_kwbegin'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-ast-1.15.1/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cop/team.rb:83:in `investigate'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:309:in `inspect_file'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:253:in `block in do_inspection_loop'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:280:in `loop'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:129:in `file_offenses'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:120:in `process_file'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `each'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `reduce'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:86:in `inspect_files'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/runner.rb:47:in `run'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/command.rb:11:in `run'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli.rb:71:in `run_command'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli.rb:78:in `execute_runners'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/lib/rubocop/cli.rb:47:in `run'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/exe/rubocop:12:in `block in <top (required)>'
/home/max/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/home/max/.rvm/gems/ruby-2.6.3/gems/rubocop-1.25.0/exe/rubocop:12:in `<top (required)>'
/home/max/.rvm/gems/ruby-2.6.3/bin/rubocop:23:in `load'
/home/max/.rvm/gems/ruby-2.6.3/bin/rubocop:23:in `<main>'
/home/max/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
/home/max/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'

Steps to reproduce the problem

I tested the snippet an older version too, and the problem also happens. Reproducing should only be to run the snippet on a clean file.

The problem seems clearly related to the use of a one-liner except clause.

Here is the config used:

AllCops:
  DisplayCopNames: true
  TargetRubyVersion: 2.7
  NewCops: disable

RuboCop version

1.25.0 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 2.6.3 x86_64-linux)
@MaxLap MaxLap changed the title EmptyLinesAroundExceptionHandlingKeywords EmptyLinesAroundExceptionHandlingKeywords fails on one-liner rescue Jan 27, 2022
@koic koic added the bug label Jan 27, 2022
koic added a commit to koic/rubocop that referenced this issue Jan 27, 2022
…nHandlingKeywords`

Fix rubocop#10379.

This PR fixes an error for `Layout/EmptyLinesAroundExceptionHandlingKeywords`
when `rescue` and `end` are on the same line.
bbatsov pushed a commit that referenced this issue Jan 28, 2022
…ngKeywords`

Fix #10379.

This PR fixes an error for `Layout/EmptyLinesAroundExceptionHandlingKeywords`
when `rescue` and `end` are on the same line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants