[dependency evaluation] Adopt vincentlanglet/twig-cs-fixer for Twig coding standards

Created on 9 June 2022, over 2 years ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

We are using PHP_CodeSniffer for PHP coding standards, ESLint for JavaScript and Stylelint for CSS, but we have nothing for Twig templates.

Steps to reproduce

Proposed resolution

Adopt https://github.com/VincentLanglet/Twig-CS-Fixer for ensuring Twig templates match coding standards.

Dependency evaluation

Maintainership: Primary author is Vincent Langlet, also very active in other projects around Symfony (Symfony itself, Sonata, Doctrine). The author is responsive to issues and pull requests. Only 3 issues are open (2024-07-12), all of them were opened within the last three months.

Security policy: See https://github.com/VincentLanglet/Twig-CS-Fixer/security/policy The latest major version is maintained and receives security updates, which should be fine for a dev dependency.

Release cycle: Frequent releases, 19 so far this year. Version 2.0.0 (current major version) has been released at the end of 2023. The maintainer confirmed that he tries to adhere to semver.

Other dependencies: None that aren't already required by Drupal itself or other dependencies.

Remaining tasks

  • Add TwigCS to composer.json and commit-code-check.sh
  • Configure it to pass without any violations for now
  • Raise child issues to fix individual violations

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

RTBC

Version

11.0 ๐Ÿ”ฅ

Component
Themeย  โ†’

Last updated about 19 hours ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

  • Needs frontend framework manager review

    Used to alert the fron-tend framework manager core committer(s) that a front-end focused issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Missing content requested by

๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi
3 months ago
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @longwave
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm
  • Drupal core is moving towards using a โ€œmainโ€ branch. As an interim step, a new 11.x branch has been opened โ†’ , as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule โ†’ and the Allowed changes during the Drupal core release cycle โ†’ .

  • Drupal 9.5.0-beta2 โ†’ and Drupal 10.0.0-beta2 โ†’ were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule โ†’ and the Allowed changes during the Drupal core release cycle โ†’ .

  • First commit to issue fork.
  • Merge request !5248Twig Coding Standard Rules โ†’ (Open) created by saidatom
  • Pipeline finished with Failed
    about 1 year ago
    Total: 185s
    #44150
  • Pipeline finished with Failed
    about 1 year ago
    #44160
  • Pipeline finished with Failed
    about 1 year ago
    #44161
  • Pipeline finished with Failed
    about 1 year ago
    Total: 154s
    #44164
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal saidatom Lisbon

    Twig Coding Standard (twig-cs-fixer) found 120 errors, check attachment.

  • Pipeline finished with Failed
    about 1 year ago
    #44329
  • Pipeline finished with Failed
    about 1 year ago
    Total: 155s
    #44330
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal saidatom Lisbon
  • Pipeline finished with Failed
    about 1 year ago
    Total: 617s
    #47348
  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡ต๐Ÿ‡ฑPoland wotnak

    MR !5248 adds vincentlanglet/twig-cs-fixer instead of friendsoftwig/twigcs about which is this issue.

    That being said, friendsoftwig/twigcs maintainer is looking for someone to take over the maintainership and considers putting the project in the EOL status if no one will step up.
    https://github.com/friendsoftwig/twigcs/issues/304

    One alternative they point to is vincentlanglet/twig-cs-fixer (which MR !5248 adds).
    Personally, I also prefer vincentlanglet/twig-cs-fixer since it also includes automatic fixes. We already using it for some time at work in Drupal based projects, and it works great.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    Looks like `friendsoftwig/twigcs` will be EOL soon and `vincentlanglet/twig-cs-fixer` is a promising replacement.

    Should we change the title and description to be more generic?

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rodrigoaguilera Barcelona

    Yes, vincentlanglet/twig-cs-fixer is a tool with more adoption, more maintained and is more aligned with drupal releases in aspects like phpstan and following symfony releases.

    I don't see the failure in the current PR but anyway it needs a rebase.

  • Pipeline finished with Canceled
    6 months ago
    Total: 71s
    #202084
  • Pipeline finished with Failed
    6 months ago
    Total: 178s
    #202086
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal saidatom Lisbon
  • Pipeline finished with Failed
    5 months ago
    Total: 530s
    #209717
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    5 months ago
    Total: 815s
    #220555
  • Pipeline finished with Failed
    5 months ago
    Total: 450s
    #220605
  • Pipeline finished with Success
    5 months ago
    Total: 447s
    #220820
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal saidatom Lisbon
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    #2 is still not addressed; this issue could be a whole lot of wasted effort if the dependency doesn't pass the dependency evaluation. I recommend ceasing rerolling/rebasing/etc. and instead completing the dependency evaluation, then tagging it "Needs release manager review" and "Needs frontend framework manager review".

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Also things with lockfile changes are never good candidates for the friendly bot as they break constantly, and it's not worth rerolling something forever without other progress. So tagging so the bot leaves it alone. Thanks!

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Feuerwagen Bonn ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Took an initial stab at the dependency evaluation. Only thing that seems to be missing is the security policy โ€“ opened https://github.com/VincentLanglet/Twig-CS-Fixer/issues/255

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Feuerwagen Bonn ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Very nice work @Feuerwagen! Setting NR for review.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Thanks @Feuerwagen, as the maintainer is very responsive let's wait a few days for the security policy to hopefully be adopted and then we can move forward here.

    Also fixing obsolete link in the IS.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Feuerwagen Bonn ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    My security policy proposal got adopted, see https://github.com/VincentLanglet/Twig-CS-Fixer/security/policy

  • Status changed to RTBC 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Personally think the evaluation contains all good information.

    Think this would be a welcome addition, have a current project I'm scared how much will get flagged.

    I'm marking RTBC to get in front of the various managers :)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States papagrande US West Coast

    +1 for this.

    I've started using this on a client site and had to customize it a bit for Drupal:

    For spacing:

    $ruleset->overrideRule(new TwigCsFixer\Rules\Whitespace\IndentRule(
        spaceRatio : 2,
        useTab : FALSE,
    ));
    


    And for now I've had to exclude templates that use {% trans %} because it isn't defined in the default rules, and I couldn't get the ignore next line comments to work.

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Evaluation looks good to me and as release manager I have no issues with adding this as a dev dependency.

    However the MR currently has merge conflicts and also the package is added as a non-dev dependency so that needs to be fixed.

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal saidatom Lisbon
  • Pipeline finished with Failed
    4 months ago
    Total: 585s
    #257923
  • Pipeline finished with Success
    4 months ago
    #257944
  • Status changed to RTBC 4 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Feuerwagen Bonn ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Conflicts are resolved, tests are passing, twig-cs-fixer is moved to require-dev. Seems like everything is addressed.

  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States lhridley

    Per https://www.drupal.org/project/drupal/issues/3284817#comment-15729173 ๐Ÿ“Œ Adopt friendsoftwig/twigcs for Twig coding standards Needs review , I have had the same issue with templates that utilize {% trans %} tags as well.

    * The Symfony Twig documentation indicates that the proper syntax to use is

    </code>.  This syntax validates.
    * <a href="https://www.drupal.org/node/2047135">Drupal's documentation</a> indicates that the syntax to use for the {% trans %} tags is <code>{% trans %} Submitted by {{ author.name }} on {{ node.date }} {% endtrans %}

    , which does not validate.

    Which is correct?

    If it is the former, before we adopt this we should correct our documentation, and IMO this is worth noting in the release notes.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    TwigNodeTrans::compileString() calls trim() on the supplied text:

        return [
          new Node([new ConstantExpression(trim($text), $body->getTemplateLine())]),
          $tokens,
        ];
    

    This means that whitespace either side of the text inside the tags is removed, so it doesn't matter which syntax we use.

  • Status changed to RTBC 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Restoring to RTBC.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States thejimbirch Cape Cod, Massachusetts

    I am also getting

    Error: Tag "trans" is already registered.
    Failed to execute command vendor/bin/twig-cs-fixer lint --fix docroot/modules/custom --debug: exit status 2
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    @thejimbirch
    could you please provide more information on when and how you got that error.

    I just tested on TwigCSFixer 3.0.1, 3.0.3, 3.1.0 on D11.0.4 with and without $config->addTokenParser(new Drupal\Core\Template\TwigTransTokenParser()); on the following code

    {% trans %} Submitted by {{ author.name }} on {{ node.date }} {% endtrans %}
    {% trans %}Submitted by %author.name% on %node.date%{% endtrans %}
    

    and it passed in all cases without issues.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States papagrande US West Coast

    @alex.skrypnyk, thanks for your testing. Since #27 when I had v2 installed, I've updated to v3 and retested. Now all the lines with trans pass. I can remove the folder exclusions that I had as a temporary workaround.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    +1 on linting twig files and on the specific tool considered.

    Merge conflict in the MR + a few comments.

Production build 0.71.5 2024