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

Different formatting result after formatting once

jasikpark opened this issue · comments

When given:

{{ if }}
  <span>1</span>
{{ else if }}
  <span>2</span>
{{ else if }}
  <s
  <span>3</span>
{{ end }}

"prettier-plugin-go-template": "^0.0.12-beta.2",

outputs

❯ yarn format tmp/input.html
yarn run v1.22.18
$ prettier --parser go-template tmp/input.html
tmp/input.htmlFormatting failed. SyntaxError: Unexpected closing tag "span". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (3:10)
  1 |
  2 |   <s
> 3 |   <span>3</span>
    |          ^^^^^^^
  4 |
    at y (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/parser-html.js:40:2906)
    at Vl (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/parser-html.js:111:2567)
    at Xl (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/parser-html.js:111:4116)
    at Object.parse (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/parser-html.js:111:4885)
    at Object.parse$d [as parse] (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:12975:19)
    at textToDoc (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:14088:27)
    at /Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:14074:95
    at embed (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier-plugin-go-template/lib/index.js:81:18)
    at Object.embed (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier-plugin-go-template/lib/index.js:61:24)
    at Object.printSubtree (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:14074:28) {
  loc: { start: { line: 3, column: 10 }, end: { line: 3, column: 17 } },
  codeFrame: '\x1B[0m \x1B[90m 1 |\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 2 |\x1B[39m   \x1B[33m<\x1B[39m\x1B[33ms\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 3 |\x1B[39m   \x1B[33m<\x1B[39m\x1B[33mspan\x1B[39m\x1B[33m>\x1B[39m\x1B[35m3\x1B[39m\x1B[33m<\x1B[39m\x1B[33m/\x1B[39m\x1B[33mspan\x1B[39m\x1B[33m>\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m   |\x1B[39m          \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 4 |\x1B[39m\x1B[0m'
}
{{ if }}
  <span>1</span>
{{ else if }}
  <span>2</span>
{{ if }}
  <span>1</span>
{{ else if }}
  <span>2</span>
{{ else if }}
  <s
  <span>3</span>
{{ end }}
✨  Done in 0.53s.

And when formatting the resulting output it prints:

input:

{{ if }}
  <span>1</span>
{{ else if }}
  <span>2</span>
{{ if }}
  <span>1</span>
{{ else if }}
  <span>2</span>
{{ else if }}
  <s
  <span>3</span>
{{ end }}
❯ yarn format tmp/formatted.html                           
yarn run v1.22.18
$ prettier --parser go-template tmp/formatted.html
tmp/formatted.html[error] tmp/formatted.html: Error: Missing end block.
[error]     at Object.exports.parseGoTemplate [as parse] (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier-plugin-go-template/lib/parse.js:145:15)
[error]     at Object.parse$d [as parse] (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:12975:19)
[error]     at coreFormat (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:14525:16)
[error]     at formatWithCursor$1 (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:14765:14)
[error]     at Object.formatWithCursor (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/index.js:60959:12)
[error]     at format$1 (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/bin-prettier.js:18001:21)
[error]     at Object.formatFiles$1 [as formatFiles] (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/bin-prettier.js:18115:16)
[error]     at async main (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/bin-prettier.js:20216:5)
[error]     at async Object.run (/Users/calebjasik-defined/Github/fuzz-prettier-plugin-go-template/node_modules/prettier/bin-prettier.js:20159:5)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It seems like it shouldn't be formatting the code if it fails/errors, right?

Please confirm the fix in prettier-plugin-go-template@0.0.12-beta.3

Looks like that sorted it, thanks! 😁