8000 `while cond do` indentation detection is off · Issue #158 · ruby/irb · GitHub
[go: up one dir, main page]

Skip to content
while cond do indentation detection is off #158
@schneems

Description

@schneems

Description

IRB attempts to detect the correct indentation level based on keywords (while, until, for, do, etc.) and some keywords can occur on the same line. For instance (while cond do) needs to only be indented once instead of twice. This is handled here https://github.com/ruby/ruby/blob/06b44f819eb7b5ede1ff69cecb25682b56a1d60c/lib/irb/ruby-lex.rb#L362-L365

However, there are cases that accidentally trigger this code and do not provide correct indentation. Consider this method:

def yield_if(block)
  yield if block.call
end

It can be called like this:

yield_if ->{true} do
  puts "bad indent"
end

But if you try to type that in it will be forced to:

yield_if ->{true} do
puts "bad indent"
end

Result of irb_info

Here is a video of the indentation behavior:

ScreenFlow.mp4

Please past the result of irb_info command in IRB.

ex.)

$ irb
irb(main):001:0> irb_info
=>
Ruby version: 3.0.0
IRB version: irb 1.3.0 (2020-12-25)
InputMethod: ReidlineInputMethod with Reline 0.2.0

Terminal Emulator

iterm 2

Setting Files

$ cat ~/.irbrc
cat: /Users/rschneeman/.irbrc: No such file or directory
$ cat ~/.inputrc
cat: /Users/rschneeman/.inputrc: No such file or directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0