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

rubocop --auto-correct can corrupt MiniTests specs #5547

Closed
MrLeebo opened this issue Feb 5, 2018 · 2 comments
Closed

rubocop --auto-correct can corrupt MiniTests specs #5547

MrLeebo opened this issue Feb 5, 2018 · 2 comments
Labels

Comments

@MrLeebo
Copy link

MrLeebo commented Feb 5, 2018

I just started using Rubocop today (v0.52.1) but there seems to be a bug in some rule where it is inserting line breaks/closing braces inappropriately, corrupting the test file.

Out of all my tests, it only seems to have corrupted 8 files, seems related to a multiline let call inside of a describe block.


Expected behavior

Tests that were valid and passing before rubocop --auto-correct should be valid and passing after.

Actual behavior

screen shot 2018-02-05 at 11 24 56 am

Steps to reproduce the problem

I deleted lines from the test and re-ran rubocop until I narrowed down what appears to be the culprit.

require 'test_helper'

class RubocopTest < ActiveJob::TestCase
  describe "with data" do
    let(:data) {[
      {
        'id' => 345
      }
    ]}
  end
end

becomes

require 'test_helper'

class RubocopTest 
}    stCase
  describe 'with data' do
    let(:data) {
      [
      {
        'id' => 345
      }
    ]}
  end
end

If it matters, this is my .rubocop.yml:

Metrics/LineLength:
  Max: 120

Layout/MultilineMethodCallIndentation:
  EnforcedStyle: indented

Layout/AlignParameters:
  EnforcedStyle: with_fixed_indentation

Layout/IndentHeredoc:
  EnforcedStyle: active_support

RuboCop version

0.52.1 (using Parser 2.4.0.2, running on ruby 2.2.0 x86_64-darwin15)
@MrLeebo
Copy link
Author

MrLeebo commented Feb 5, 2018

As a workaround, the let can be rewritten as

let(:data) do
  [
    { 'id' => 345 }
  ]
end

or collapsed into a one-liner and it does not have a problem.

@pocke pocke added the bug label Feb 13, 2018
@rrosenblum
Copy link
Contributor

I have narrowed this down to an issue with Layout/BlockEndNewline. I'll try to find a fix for this.

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

3 participants