zackad / prettier-plugin-twig

Code formatting plugin for Prettier to handle Twig templates
Apache License 2.0
55 stars 6 forks source link

Review options #50

Open rellafella opened 3 months ago

rellafella commented 3 months ago

Prettier natively supports overwriting the prettier config for given file types.

I would like to see the native Prettier options used where possible.

This would mean limiting the (default) "twig specific options" to

{
  "twigAlwaysBreakObjects": false,
  "twigFollowOfficialCodingStandards": true,
  "twigOutputEndblockName": false,
  "twigMultiTags": [],
}

In the removal of twigPrintWidth and twigSingleQuote Prettier's native options would need to be used.

It would also be good to see bracketSameLine, arrowParens, [bracketSpacing]( quoteProps and trailingComma supported, but perhaps that is a separate issue.

zackad commented 3 months ago

I'm fine with removal of twigPrintWidth and twigSingleQuote options. Can you do it in a separate PR? Since this is a breaking change, I want to provide better documentation and release notes.

jannisborgers commented 3 months ago

Please be aware that in my tests, if singleQuotes is set to false (which Prettier does by default), Twig expressions inside HTML attributes currently break the plugin.

Something like this is pretty common…

<a href="{{ page.url }}" class="nav-item {{ current ? "nav-item--current" }}">
  {{ page.title }}
</a>

and results in this…

<a href="{{ page.url }}" class="nav-item {{ current ? "nav-item--current" }}">
                                                                        ^

A tag must consist of attributes or expressions. Twig Tags are not allowed.
Error: ERROR: Invalid token

I was already working on a PR that allowed such a scenario, but it got complex quickly and I am too busy at the moment.

This is a very common scenario and either the above should be fixed before removing the custom options, or the option should remain until a fix is there.

zackad commented 3 months ago

Hmm..

Something seems to be broken here. I can't reproduce this issue with v0.6.0 (I haven't upgrade to new version since https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/308 han't been fixed). Need time to investigate.

zackad commented 1 month ago

I think we should keep twigSingleQuote option and mention in the docs that the value should be different from singleQuote.

this options is VALID

singleQuote: false
twigSingleQuote: true

# or
singleQuote: true
twigSingleQuote: false

this option is INVALID

singleQuote: true
twigSingleQuote: true

# or
singleQuote: false
twigSingleQuote: false

This is to make sure that we can handle twig expression inside html attribute with string delimiter.