prettier-plugin-go-template icon indicating copy to clipboard operation
prettier-plugin-go-template copied to clipboard

Lines containing variable definitions cause double-empty lines

Open cnunciato opened this issue 2 years ago • 2 comments

First off, thanks for this excellent plugin!

One thing I've noticed is that when a line containing a variable definition has no trailing space, and that same line is followed by a single empty line, the plugin appends a second empty line. Here's a video using the playground that shows this behavior:

https://user-images.githubusercontent.com/274700/183225768-c066bb8c-5e9e-4b16-8bfe-331d228bb0c0.mov

When there is a trailing space, however, the plugin keeps just one empty line.

I don't see a test that covers this case, but I do see one that covers removing multiple empty lines, so I'm assuming, since two consecutive lines isn't a Go template convention, that this is a legitimate bug. Happy to take a shot at fixing it myself, but figured I'd post here first in case it's either an easy fix or something you could provide me with a little guidance on before I go spelunking.

Thanks again and appreciate your help!

cnunciato avatar Aug 06 '22 00:08 cnunciato

Just noticed this comment also, which seems like it may be related:

https://github.com/NiklasPor/prettier-plugin-go-template/issues/56#issuecomment-873311542

cnunciato avatar Aug 06 '22 00:08 cnunciato

Hey, thanks for reporting!

Sadly bugs like these aren't quite easy to fix, as this whole plugin is based around heuristics (regex 😂) which extract all go-interpolation and invokes the regular HTML formatter — I didn't want to invest the time to write a new one here for obvious reasons.

If you're able to fix this I'll surely accept a PR 🚀

NiklasPor avatar Aug 06 '22 05:08 NiklasPor