twigcs icon indicating copy to clipboard operation
twigcs copied to clipboard

Allow new lines after opening blocks

Open Chi-teck opened this issue 5 years ago • 6 comments

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.

Chi-teck avatar Mar 04 '19 16:03 Chi-teck

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.

OwlyCode avatar Mar 04 '19 16:03 OwlyCode

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.

Chi-teck avatar Mar 04 '19 16:03 Chi-teck

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.

OwlyCode avatar Mar 04 '19 16:03 OwlyCode

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.

Chi-teck avatar Mar 04 '19 16:03 Chi-teck

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.

OwlyCode avatar Mar 04 '19 16:03 OwlyCode

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

Chi-teck avatar Mar 04 '19 16:03 Chi-teck