twigcs icon indicating copy to clipboard operation
twigcs copied to clipboard

Problem when multiple lines

Open bastien70 opened this issue 3 years ago • 7 comments

Hello, I've the following code :

{% set head_of_service_and_can_credit = is_granted(constant('App\\Application\\Entity\\User::ROLE_CHEF_SERVICE'))
        and not is_granted(constant('App\\Application\\Entity\\User::ROLE_RH'))
        and headOfServiceTypesAuthorizationCount > 0
        and user.service.headOfService.validator.id == app.user.id
    %}

And the following errors :

l.11 c.117 : ERROR There should be 1 space between the "and" operator and its left operand.
l.12 c.79 : ERROR There should be 1 space between the "and" operator and its left operand.
l.13 c.52 : ERROR There should be 1 space between the "and" operator and its left operand.

These errors will only be resolved if I put everything on one line but I don't want it because the line will be too long. How can I fix this kind of problem?

Same here :

{% extends is_granted(constant('App\\Application\\Entity\\User::ROLE_SUPER_ADMIN'))
    ? "admin/base.html.twig"
    : "base.html.twig"
%}
l.1 c.83 : ERROR There should be 1 space before the "?".
l.2 c.29 : ERROR There should be 1 space before the ":".

Same, if I put it on one line it will work, but afterwards the line becomes too long

bastien70 avatar Dec 27 '21 11:12 bastien70

Hi, I think I have the same problem.

Is there a way to tell twigcs to ignore this line?

{% if
    globalAuth.care_user_log_truncate == 1 or globalAuth.care_comment_truncate == 1 or
    globalAuth.care_content_truncate == 1 or globalAuth.care_all_images_truncate == 1 or
    globalAuth.care_session_truncate == 1 or globalAuth.care_content_keyword == 1 or
    globalAuth.care_passive_users_truncate == 1
%}

sc

ghost avatar Jan 14 '22 17:01 ghost

@bastien70 @libreajans

Try replacing enforceSize(...) with enforceSpaceOrLineBreak(...) where appropriate in RulesetBuilder.php. For the ternaries, that would be lines 225 and 227.

MichaelAllenWarner avatar Feb 08 '22 19:02 MichaelAllenWarner

I'm sorry I didn't answer sooner to this issue. Are you still facing the problem or did you manage to configure your own ruleset?

OwlyCode avatar Apr 28 '22 20:04 OwlyCode

I too encountered this issue. Ended up creating variables just to make the code readable...

gnutix avatar May 29 '22 15:05 gnutix

Same issue, but I duplicated it with more context, sorry. (Ref: https://github.com/friendsoftwig/twigcs/issues/254)

RSickenberg avatar Aug 02 '22 08:08 RSickenberg

Still encountering this issue on v6 :(

danog avatar Nov 15 '22 09:11 danog

Yeah still encountering the issue too :(

bastien70 avatar Oct 30 '23 15:10 bastien70