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

RedundantBegin cop autocorrect modifies whitespace formatting #1307

Closed
KurtPreston opened this issue Aug 28, 2014 · 1 comment · Fixed by #1308
Closed

RedundantBegin cop autocorrect modifies whitespace formatting #1307

KurtPreston opened this issue Aug 28, 2014 · 1 comment · Fixed by #1308

Comments

@KurtPreston
Copy link

I've noticed that the Style/RedundantBegin cop sometimes has two undesirable actions:

  1. It sometimes removes blank lines
  2. It sometimes causes unusual indentation, i.e. indenting the raise clause by a single space.

The following rspec test demonstrates both of these anomalies. This spec could be added to spec/rubocop/cop/style/redundant_begin_spec.rb:

  it "doesn't modify spacing when auto-correcting" do
    src = """
    def method
      begin
        BlockA do |strategy|
          foo
        end

        BlockB do |portfolio|
          foo
        end

      rescue => e
        bar
      end
    end
    """

    result_src = """
    def method
      BlockA do |strategy|
        foo
      end

      BlockB do |portfolio|
        foo
      end

    rescue => e
      bar
    end
    """
    new_source = autocorrect_source(cop, src)
    expect(new_source).to eq(result_src)
  end
yous added a commit to yous/rubocop that referenced this issue Aug 28, 2014
Auto-correction of `Style/RedundantBegin` cop have treated new line as
indentation and deleted them.

Fix rubocop#1307.
@KurtPreston
Copy link
Author

@yous Damn that was fast. Thanks!

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 a pull request may close this issue.

1 participant