NiklasPor / prettier-plugin-go-template

Fixes prettier formatting for go templates 🐹

Home Page:prettier-plugin-go-template-niklaspor.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lines containing variable definitions cause double-empty lines

cnunciato opened this issue · 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:

demo.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!

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

#56 (comment)

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 🚀