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

Auto correction removes unrelated code block on "Redundant else-clause" error #5515

Closed
gimite opened this issue Jan 27, 2018 · 0 comments
Closed
Labels

Comments

@gimite
Copy link

gimite commented Jan 27, 2018

Expected behavior

It only removes the redundant else-clause.

Actual behavior

It removes unrelated code block, resulting in code with syntax error. See below.

Steps to reproduce the problem

$ cat <<EOF > foo.rb
class Foo
  def value
    if @params
      case @params[:x]
      when 'a'
        'b'
      else
        nil
      end
    else
      'c'
    end
  end
end
EOF

$ rubocop foo.rb --auto-correct foo.rb
Inspecting 1 file
E

Offenses:

foo.rb:7:7: C: [Corrected] Style/EmptyElse: Redundant else-clause.
      else
      ^^^^
foo.rb:10:1: E: Lint/Syntax: unexpected token $end
(Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)

1 file inspected, 2 offenses detected, 1 offense corrected

$ cat foo.rb
class Foo
  def value
    if @params
      case @params[:x]
      when 'a'
        'b'
      end
  end
end

$ ruby foo.rb
foo.rb:9: syntax error, unexpected end-of-input, expecting keyword_end

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.4.1 i686-linux)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants