trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
157 stars 35 forks source link

Throws error on vue shorthand attributes #56

Open urbantrout opened 4 years ago

urbantrout commented 4 years ago
<button @click="doSomeVueStuff">OK</button>

The above code throws an error. A workaround is to use v-on:click instead of @click

https://vuejs.org/v2/guide/syntax.html#v-on-Shorthand

hansgrinwis commented 4 years ago

Additionally, v-on:click throws an error when an event modifier is present. As in:

<a href="" v-on:click.prevent="doSomeVueStuff">OK</a>

https://vuejs.org/v2/guide/events.html#Event-Modifiers

terryupton commented 4 years ago

Seeing the same isses with Alpine JS too.

["ERROR" - 6:19:41 PM] Error formatting document.
Error: ERROR: Expected an Identifier
  192 |                 <div x-data="getCheckedCount()"
  193 |         x-init="getChecked()"
> 194 |         x-on:item-selected.window="getChecked()"
      |                           ^
  195 |         class="pl-6 pt-6 font-medium"
  196 |         id="courseTotals"
  197 | >
dnnsjsk commented 3 years ago

Are there any ways around this?

drdogbot7 commented 3 years ago

same issue using AlpineJS… which makes sense, because it has a very similar syntax.

dnnsjsk commented 3 years ago

I wish there was a way to just ignore the attributes, {# prettier-ignore #} is not working here, unfortunately.

Anyone here able to write up a plugin? This codebase is a bit beyond me..

hansgrinwis commented 3 years ago

As twig is supercharged HTML, <!-- prettier-ignore --> should work.

(Please note that if you do not strip HTML comments in your build process, it will end up in the code sent to the browser. Of course, when prettifying HTML and stripping HTML comments in your build process, do the stripping after Prettier performs its magic. 🙄)

solidevolution commented 3 years ago

As twig is supercharged HTML, <!-- prettier-ignore --> should work.

(Please note that if you do not strip HTML comments in your build process, it will end up in the code sent to the browser. Of course, when prettifying HTML and stripping HTML comments in your build process, do the stripping after Prettier performs its magic. 🙄)

Doesn't work, tested with twig and alpinejs