Rubocop: No right autocorrects

Created on 27 Dec 2017  Â·  6Comments  Â·  Source: rubocop-hq/rubocop

Hi,

I'm having some strange corrections:

Before:

# frozen_string_literal: true

require 'common_helper'
require 'support/capybara_box'
require 'support/database_cleaner'
require 'support/factory_bot'

RSpec.describe Dashboard do
  before do
    page.set_rack_session(
      current_grades_ids: [
        1
      ],

      current_student_id: student.id
    )
  end
end

After:

# frozen_string_literal: true

require 'common_helper'
require 'support/capybara_box'
support/database_cleaner'
require 'support/factory_bot'

RSpec.describe Dashboard do
  before do
    page.set_rack_session(
      current_grades_ids: [
        1
      ],

      current_student_id: student.id
    )
  end
end

or

before:

# frozen_string_literal: true

require 'common_helper'
require 'support/capybara_box'
require 'support/database_cleaner'
require 'support/factory_bot'
require 'support/shared/enroll_situation'

RSpec.describe Dashboard, '#user:choose_schedule', :js do
  before do
    page.set_rack_session(
      current_grades_ids: [
        'xxx',
        'xxx',
        'xxx',
        'xxx'
      ],

      current_student_id: student.id,
      current_user_id:    student.user_id
    )
  end

  it 'works' do
  end
end

After:

# frozen_string_literal: true

require 'common_helper'
require 'support/capybara_box'
require 'support/database_cleaner'
require 'support/factory_bot'
equire 'support/shared/enroll_situation'
  .describe Dashboard, '#user:choose_schedule', :js do
  before do
    page.set_rack_session(
      current_grades_ids: %w[
        xxx
        xxx
        xxx
        xxx
      ],

      current_student_id: student.id,
      current_user_id:    student.user_id
    )
  end

  it 'works' do
  end
end
0.52.1 (using Parser 2.4.0.2, running on ruby 2.5.0 x86_64-darwin17)

Thanks for this project. (:

bug

All 6 comments

I cannot reproduce this autocorrection on my machine. What is the output of just running rubocop on the files? Which offenses are detected – by which cops?

I'm seeing something similar (0.52.1). I appears to be making the edit on the wrong line.

class LangList
  def create_new_langfile
    i = 0
    File.open(@path + "en.yml", "w+") do |f|
      @new_en_arr.each { |element|
        i += 1
        f.puts(element) }
    end
  end
end

running
rubocop --auto-correct --only Layout lib/tasks/translate2.rake
gives the following errors

Offenses:

lib/tasks/translate2.rake:5:1: E: Lint/Syntax: unexpected token tRCURLY
(Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops)
}      h + "en.yml", "w+") do |f|
^
lib/tasks/translate2.rake:5:20: E: Lint/Syntax: unexpected token tCOMMA
(Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops)
}      h + "en.yml", "w+") do |f|
                   ^
lib/tasks/translate2.rake:7:25: C: [Corrected] Layout/BlockEndNewline: Expression at 7, 25 should be on its own line.
        f.puts(element) }
                        ^
lib/tasks/translate2.rake:11:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^

and this output

class LangList
  def create_new_langfile
    i = 0
    File.open(@p
}      h + "en.yml", "w+") do |f|
      @new_en_arr.each { |element|
        i += 1
        f.puts(element) }
    end
  end
end

@eamonn-webster That I can reproduce. Using git-bisect I’ve identified a540482cc9581fb03457b2631241ca9b72419150 as the first bad commit. cc @bgeuken re. #4869.

A failing test case for spec/rubocop/cop/layout/block_end_newline_spec.rb:

  it 'autocorrects a {} block where there is code on the line above and below' do
    src = <<-RUBY.strip_indent
      1
      2
      test {
        foo  }
      3
      4
    RUBY

    new_source = autocorrect_source(src)

    expect(new_source).to eq(['1',
                              '2',
                              'test {',
                              '  foo',
                              '}',
                              '3',
                              '4',
                              ''].join("\n"))
  end

There seems to be some confusion between node.source and node.loc.end.source_buffer.source…

Sorry about late @bquorning , but maybe I was, for some reason, on version 0.52.0. Now, for sure, on 0.52.1 it does not happened again.

I believe this issue has been fixed by #5590.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikegee picture mikegee  Â·  3Comments

david942j picture david942j  Â·  3Comments

cabello picture cabello  Â·  3Comments

AndreiMotinga picture AndreiMotinga  Â·  3Comments

bquorning picture bquorning  Â·  3Comments