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

Style/Next truncates previous line when indenting is off #4392

Closed
andrewngo opened this issue May 19, 2017 · 0 comments · Fixed by #4417
Closed

Style/Next truncates previous line when indenting is off #4392

andrewngo opened this issue May 19, 2017 · 0 comments · Fixed by #4417
Labels

Comments

@andrewngo
Copy link

Running auto-correct on our files. Narrowed down this issue to the Style/Next cop. If the if/end block is not properly indented, when it changes to next, the line above the previous 'end' is truncated by however much the indenting was off.


Expected behavior

Expect an auto-correction and indenting is correct

def test_title(opts = nil)
  [1, 2, 3, 4].each do |num|
    next unless !opts.nil?
    puts num
    if num != 2
      puts 'hello'
      puts 'world'
    end
  end
end

Actual behavior

Since the indenting of end was not aligned correctly with its if, when it changes to next, it truncates the last letter of the previous line. In this case, causing a syntax error

def test_title(opts = nil)
  [1, 2, 3, 4].each do |num|
    next unless !opts.nil?
    puts num
    if num != 2
      puts 'hello'
      puts 'world'
    en
  end
end

Steps to reproduce the problem

def test_title(opts = nil)
  [1, 2, 3, 4].each do |num|
    if !opts.nil?
      puts num
      if num != 2
        puts 'hello'
        puts 'world'
      end
   end
  end
end

$rubocop --only Next -a test_file.rb

RuboCop version

$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.2.4 x64-mingw32)
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