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

Pry::Indent & consecutive line breaks #2094

Open
bcgraham opened this issue Dec 5, 2019 · 2 comments · May be fixed by #2132
Open

Pry::Indent & consecutive line breaks #2094

bcgraham opened this issue Dec 5, 2019 · 2 comments · May be fixed by #2132

Comments

@bcgraham
Copy link
Contributor

bcgraham commented Dec 5, 2019

Pry::Indent without consecutive linebreaks:

code = <<~CODE.chomp
  class Foo
    def bar
      :bar
    end
    def baz
      :baz
    end
  end
CODE
# => "class Foo\n  def bar\n    :bar\n  end\n  def baz\n    :baz\n  end\nend"
puts Pry::Indent.new.indent(code)
# => class Foo
# =>   def bar
# =>     :bar
# =>   end
# =>   def baz
# =>     :baz
# =>   end
# => end

However, if we put a linebreak between the bar's end and baz's def:

code = <<~CODE.chomp
  class Foo
    def bar
      :bar
    end

    def baz
      :baz
    end
  end
CODE
=> "class Foo\n  def bar\n    :bar\n  end\n\n  def baz\n    :baz\n  end\nend"
puts Pry::Indent.new.indent(code)
# => class Foo
# =>   def bar
# =>     :bar
# =>   end
# =>     def baz   # <-- extra indentation; boo, hiss
# =>     :baz
# =>   end
# => end

Ideally, that wouldn't be the case, but I could see an argument that Pry::Indent was never intended to support that use case, because of how lines of input are handled.

Adding a test case & fixing this would be pretty small - would a PR with such a test case & fix be acceptable, or is this not intended to be supported as a use case?

@barrettkingram
Copy link
Contributor

@bcgraham Out of curiosity, how would you reproduce this scenario under normal usage of Pry? Or are you calling Pry::Indent directly in your code for some reason?

Also master is green again if you want to re-open that PR.

@bcgraham
Copy link
Contributor Author

@barrettkingram Yes, I’m calling directly in my own code. It is definitely not under normal usage of Pry.

@bcgraham bcgraham linked a pull request May 2, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants