friendsoftwig / twigcs

The missing checkstyle for twig!
MIT License
342 stars 34 forks source link

Unexpected macro syntax violation #170

Open cedric-anne opened 3 years ago

cedric-anne commented 3 years ago

In Twig documentation, there are space surrounding the = operator in macro declarations.

Problem is that this syntax is reported as errored by the rule responsible to check named arguments declaration.

Macro declaration:

{% macro test(title, test = true) %}
    ...
{% endmacro %}

Error reported: l.1 c.25 : ERROR There should be 0 space before the "=" in the named arguments list.

OwlyCode commented 3 years ago

Hi,

Good catch! This would need to be fixed and then added to our test suite.

alexander-schranz commented 1 year ago

I have a similar case where html code seems to be detected as twig the data-controller="expander":

<!-- overlay -->
<div id="{{ id }}" class="relative z-10 hidden" role="dialog" aria-modal="true">
    <div class="fixed inset-0 bg-black bg-opacity-50 transition-opacity cursor-default"
         data-controller="expander"
         data-action="click->expander#close"
         aria-controls="{{ id }}"
         aria-expanded="false"></div>

    <div class="fixed z-10 w-screen sm:w-[85vw] max-w-screen-md bottom-0 sm:bottom-auto sm:top-1/2 left-1/2 -translate-x-1/2 sm:-translate-y-1/2 bg-white rounded-t-lg sm:rounded-lg shadow-lg">
        <div class="absolute top-0 right-4 pt-4 pl-2 pb-2 bg-white rounded-bl-xl">
            <button type="button" class="bg-white rounded-md text-primary-600 hover:text-primary-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
                    data-controller="expander"
                    data-action="expander#close"
                    aria-controls="{{ id }}"
                    aria-expanded="false">
                <span class="sr-only">{{ 'app.close'|trans }}</span>
                {{ include('website/atoms/icons/outline/x.html.twig', {class: 'h-6 w-6'}) }}
            </button>
        </div>

        <div class="max-h-[90vh] sm:max-h-[85vh] overflow-y-auto p-5 pt-8 sm:p-10 overscroll-y-contain">
            {% if title|default %}
                <h3 class="text-2xl leading-8 font-bold text-slate-600 mb-10">{{ title }}</h3>
            {% endif %}

            <div>
                {% block content %}{% endblock %}
            </div>
        </div>
    </div>
</div>
        {
            "file": "templates\/molecules\/overlay.html.twig",
            "violations": [
                {
                    "line": 12,
                    "column": 120,
                    "severity": 3,
                    "type": "error",
                    "message": "There should be 0 space before the \"=\" in the named arguments list."
                },
                {
                    "line": 12,
                    "column": 122,
                    "severity": 3,
                    "type": "error",
                    "message": "There should be 0 space after the \"=\" in the named arguments list."
                }
            ]
        },