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

Layout/IndentationWidth is broken #112

Closed
fables-tales opened this issue Apr 19, 2019 · 9 comments · Fixed by rubocop/rubocop#9619
Closed

Layout/IndentationWidth is broken #112

fables-tales opened this issue Apr 19, 2019 · 9 comments · Fixed by rubocop/rubocop#9619
Labels
rubocop bug 🚨 An apparent bug in RuboCop

Comments

@fables-tales
Copy link

class Foo
  def a
  rescue
  ensure
    a
  end
end

this fails with:

  hi.rb:3:3: Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
@searls searls added the rubocop bug 🚨 An apparent bug in RuboCop label Apr 20, 2019
@searls
Copy link
Contributor

searls commented Apr 20, 2019

This appears to be a rubocop bug, but I can only repro it for empty methods, which makes it seem lower priority. This passes:

class Foo
  def a
    nil
  rescue
  ensure
    a
  end
end

@will
Copy link
Contributor

will commented Jul 10, 2019

I don’t know if this is the same thing, but when I try and make this indent "correctly" Layout/IndentionWidth is the rule that complains, and this is an open issue about that rule, so maybe??

    feed.entry(event,
      id: "urn:uuid:#{event["id"]}",
      url: url,
      published: Time.parse(event["createdAt"]),
      updated: Time.parse(event["createdAt"])) do |entry|
        entry.title(event["tag"].titleize)
        entry.author do |author|
          author.name "Citus Cloud"
      end
# …

gets changed to

    feed.entry(event,
      id: "urn:uuid:#{event["id"]}",
      url: url,
      published: Time.parse(event["createdAt"]),
      updated: Time.parse(event["createdAt"])) do |entry|
      entry.title(event["tag"].titleize)
      entry.author do |author|
        author.name "Citus Cloud"
      end
# …

This is on v 0.1.0

@searls
Copy link
Contributor

searls commented Jul 10, 2019

Well, that sure seems bad. @will would you be willing or able to try digging into this?

@will
Copy link
Contributor

will commented Jul 10, 2019

This is as far as I think I can get:

It seems like it depends on where the last end is. You can move that one around, and the rest of the body above it will follow the indentation. Which seems a bit weird to me. (by follow I mean, I have my editor set to auto fix whatever errors, and when you move the end, it auto fixes the indentation to match where the last end is)

So if you have

a.method("a",
  id: 2,
  ok: 3) do |thing|
    thing.ok
    thing.other do |a|
      a.foo
    end
  end

and move that last end over to the left two spaces, the whole thing becomes

a.method("a",
  id: 2,
  ok: 3) do |thing|
  thing.ok
  thing.other do |a|
    a.foo
  end
end

This at least gives me a fix for this, and at most maybe means it’s not a bug at all and this is how it should be? I really don’t know.

@jmkoni
Copy link
Contributor

jmkoni commented Jan 7, 2021

I was going through old issues and checked the state of this one. I put the original code in a file called test.rb:

class Foo
  def a
  rescue
  ensure
    a
  end
end

and it now fails with this glorious infinite loop.

be standardrb --fix test.rb
bundler: failed to load command: standardrb (/Users/jennifer/.rvm/gems/ruby-2.7.2@standard/bin/standardrb)
RuboCop::Runner::InfiniteCorrectionLoop: Infinite loop detected in /Users/jennifer/dev/standard/test.rb and caused by Layout/IndentationWidth -> Layout/IndentationWidth, Layout/RescueEnsureAlignment
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:304:in `check_for_infinite_loop'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:286:in `loop'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:131:in `file_offenses'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:122:in `process_file'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:100:in `each'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:100:in `reduce'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:86:in `inspect_files'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/gems/rubocop-1.7.0/lib/rubocop/runner.rb:47:in `run'
  /Users/jennifer/dev/standard/lib/standard/runners/rubocop.rb:12:in `call'
  /Users/jennifer/dev/standard/lib/standard/cli.rb:18:in `run'
  /Users/jennifer/dev/standard/exe/standardrb:7:in `<top (required)>'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/bin/standardrb:23:in `load'
  /Users/jennifer/.rvm/gems/ruby-2.7.2@standard/bin/standardrb:23:in `<top (required)>'

@koic have you seen this particular collision before?

@dvandersluis
Copy link

@jmkoni I opened rubocop/rubocop#9619 to fix the infinite loop.

@koic
Copy link
Contributor

koic commented Mar 19, 2021

I overlooked the mention 💦 @dvandersluis Thank you for working on this!

@jmkoni
Copy link
Contributor

jmkoni commented Mar 19, 2021

@dvandersluis @koic thank you to you both :)

@jmkoni
Copy link
Contributor

jmkoni commented Apr 21, 2021

Should be part of 1.05

@jmkoni jmkoni closed this as completed Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rubocop bug 🚨 An apparent bug in RuboCop
Projects
None yet
6 participants