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

Option to remove leading/trailing whitespace inside tags

silverwind opened this issue ยท comments

Not sure if options are on the table for this module, but I'd like to see one to remove the space here:

.replace(/{{(?![-<]|(?:\/\*))[ \t]*/g, "{{ ")
.replace(/[ \t]*(?<![->]|(?:\*\/))}}/g, " }}")

meaning it should output {{.var}} instead of {{ .var }} for people who prefer terseness.

That's for sure doable. If it's not much effort I'll implement it in the next week ๐Ÿ‘
We can probably read a flag for that from the .prettierrc ๐Ÿค”

Ah well, I was wrong. The spaces are added by the HTML Formmater, which is used for formatting the brackets. If you have some ideas how to implement this, feel free to open a PR.

Atleast with the current approach this seems not possible. Anyway, thanks for the suggestion. I'll close this issue to keep the board quite clean.

Thanks for your contribution.

@all-contributors please add @silverwind for ideas

@NiklasPor

I've put up a pull request to add @silverwind! ๐ŸŽ‰

Thanks. I may contribute later after testing the plugin further. I want to introduce it on gitea for formatting of go templates via prettier, thought I'm pretty sure I'll hit a bug or two in the plugin in process ๐Ÿ˜‰

Hey @silverwind, not sure if this is still relevant but besides many other features prettier-plugin-go-template@0.0.11-beta.13 now has an option to remove the bracket spacing:

// .prettierrc
{
  /**
   * Enables & disables spacing between go statements.
   * E.g. {{ statement }} vs {{statement}}.
   * Default: true
   */
  "goTemplateBracketSpacing": false
}

I'll reopen this until the PR is merged to master.