Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Twig support #5944

Open
Kocal opened this Issue Mar 6, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Kocal
Copy link
Contributor

Kocal commented Mar 6, 2019

(Related to #4056 I suppose.)

On some large codebase, when many (old and new) developpers write/modify code, it's really borring and to review linting issues on Twig templates. 馃槥
I know there is also linting tools like asm89/twig-lint and the command php bin/console lint:twig inside a Symfony project, but they only check if the syntax is valid. 馃槙

It would be nice if Prettier can handle Twig files (.twig), but also HTML Twig files (.html.twig), in order to have clean Twig files everywhere. 馃帀

The following elements that should be prettified:

Given the following snippet (taken from admin/blog/edit.html.twig from Symfony Demo, but uglified on purpose):

{#
    By default, forms enable client-side validation. This means that you can't
    test the server-side validation errors from the browser. To temporarily
    disable this validation, add the 'novalidate' attribute:

    {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}
#}

{%  if show_confirmation| default(false) %}
    {% set attr = {'data-confirmation'  : 'true'} %}
    {{  include('blog/_delete_post_confirmation.html.twig')   }}
{% endif %}

{{ form_start(form, {  'attr': attr|default({})}) }}
    {{ form_widget(form) }}

    <button 
        type="submit"
        class="{{ button_css|default("btn btn-primary") }}"
    >
        <i class="fa fa-save" aria-hidden="true"></i> {{ button_label|default('label.create_post'|trans) }}
    </button>

    {% 
        if include_back_to_home_link|default(false) 
    %}
        <a href="{{ path('admin_post_index') }}" class="btn btn-link">
            <i class="fa fa-list-alt" aria-hidden="true"></i> {{ 'action.back_to_list'|trans
 }}
        </a>
    {% endif %}
{{ form_end(form) }}

The prettified should be something like this (this is my code style, but if Prettier on Twig files will be a thing, maybe we should ask to twigphp/Twig or the Twig community what they prefer):

{#
    By default, forms enable client-side validation. This means that you can't
    test the server-side validation errors from the browser. To temporarily
    disable this validation, add the 'novalidate' attribute:

    {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}
#}

{% if show_confirmation|default(false) %}
    {% set attr = { 'data-confirmation': 'true' } %}
    {{ include('blog/_delete_post_confirmation.html.twig') }}
{% endif %}

{{ form_start(form, { attr: attr|default({}) }) }}
    {{ form_widget(form) }}

    <button type="submit" class="{{ button_css|default("btn btn-primary") }}">
        <i class="fa fa-save" aria-hidden="true"></i> {{ button_label|default('label.create_post'|trans) }}
    </button>

    {% if include_back_to_home_link|default(false) %}
        <a href="{{ path('admin_post_index') }}" class="btn btn-link">
            <i class="fa fa-list-alt" aria-hidden="true"></i> {{ 'action.back_to_list'|trans }}
        </a>
    {% endif %}
{{ form_end(form) }}

Thanks for your consideration, I'm sure that will be helpful to many people 馃檪

@evilebottnawi

This comment has been minimized.

Copy link
Member

evilebottnawi commented Mar 6, 2019

I think it is out of scope of prettier (core). We support plugin system https://prettier.io/docs/en/plugins.html and real plugins with code how plugins should be implemented. I think the right decision would be to implement the plugin.

@Kocal

This comment has been minimized.

Copy link
Contributor Author

Kocal commented Mar 6, 2019

Ah yeah, I totally forgot about plugins.

Well, maybe it's the good time for me to write my first own plugin 馃憖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.