friendsoftwig / twigcs

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

Allow new lines after opening blocks #58

Open Chi-teck opened 5 years ago

Chi-teck commented 5 years ago

Drupal core use multiline block statements to set Twig variables like follows. https://github.com/drupal/drupal/blob/8.6.10/core/themes/classy/templates/block/block.html.twig#L28

Twig coding standard does not forbid this syntax. So I think Twigcs should no complain about that. Currently it brings ERROR There should be 1 space(s) after opening a block. violation.

Thanks.

OwlyCode commented 5 years ago

Hello,

As of https://twig.symfony.com/doc/2.x/coding_standards.html it is stated :

Put one (and only one) space after the start of a delimiter ({{, {%, and {#) and before the end of a delimiter (}}, %}, and #}):

My understanding of this is that you should format like this :

{% set classes = [
    'block',
    'block-' ~ configuration.provider|clean_class,
    'block-' ~ plugin_id|clean_class,
] %}

But you can still use custom rules with Twigcs.

Chi-teck commented 5 years ago

My understanding of this is that you should format like this

That's how we work around right now. But this kind of formatting does not look well.

OwlyCode commented 5 years ago

I personally got quite used to it, it saves 2 lines in vertical space. But that's pure opinion without any facts.

Twigcs is not about forcing you to do this. The tool is meant to allow you to enforce the rules you want in your project. In your case you should go with a custom Ruleset so you can set up the coding style that suits you.

Chi-teck commented 5 years ago

Yes, but the rule (DelimiterSpacing) has no configuration options to change that behavior. So besides the Ruleset we will have to develop a new Rule for that.

OwlyCode commented 5 years ago

We can add this. I have very little available time at the moment for open source projects. If you want to help you can add this or I will do it but that will take some time.

Chi-teck commented 5 years ago

I am not quite familiar with Twig lexer. So I think it ls better to leave this for you. Thanks.