eraserhd / parinfer-rust

A Rust port of parinfer.
ISC License
546 stars 42 forks source link

Unmatched double quote in comment breaks parinfer #128

Closed daveyarwood closed 1 year ago

daveyarwood commented 2 years ago

I stumbled upon this by chance and it actually made me think that there was some Neovim breaking change that broke parinfer. It turns out to be what appears to be a corner case bug in parinfer.

I was able to come up with this simple repro.

Steps to reproduce

Create a new Clojure file containing this:

["here is a"
 ["nested"
  ["list of things"]]]

(def testing
  ;; comment
  42)

Try doing ordinary parinfer things. For example, delete the [ before "list of things" and it correctly turns into this:

["here is a"
 ["nested"
  "list of things"]]

Now, add a " character into the comment, like this:

  ;; "comment

Try doing ordinary parinfer things.

Expected behavior

Same as described above. Deleting the [ before "list of things" should produce:

["here is a"
 ["nested"
  "list of things"]]

Actual behavior

The unmatched double quote seems to completely break parinfer.

Deleting the [ before "list of things" incorrectly produces:

["here is a"
 ["nested"
  "list of things"]]]

(note the extra unmatched ] that should have been removed automatically)

daveyarwood commented 2 years ago

Possibly the same issue as #82

eraserhd commented 1 year ago

This is intentional, though somewhat awkward behavior. See #106 and here.

daveyarwood commented 1 year ago

My understanding of that article is that the issue is expected, and also prevented in parinfer.js. So maybe the issue is that that same prevention needs to also be implemented in parinfer-rust? Or am I misunderstanding the issue?

eraserhd commented 1 year ago

Parinfer doesn't (and can't!) prevent putting a quote in a comment. In fact, if you put two quotes in a comment, parinfer works again. The "prevention" is that parinfer will not reformat code until the dangerous quote is resolved.

Parinfer-rust actually gives a good error. It's likely not being displayed by the editor integration:

ᐅ printf ';"\n' |parinfer-rust
parinfer-rust: Quotes must balanced inside comment blocks.