Skip to content
This repository has been archived by the owner on Mar 5, 2025. It is now read-only.

Twig Lint is not maintained and fails valid twig code #1543

Closed
sarahjean opened this issue May 30, 2017 · 4 comments
Closed

Twig Lint is not maintained and fails valid twig code #1543

sarahjean opened this issue May 30, 2017 · 4 comments
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@sarahjean
Copy link

My system information:

  • Operating system type: OSX/drupal-vm
  • Operating system version: Sierra/drupal-vm 4.3
  • BLT version: 8.7

When I run this command:

blt validate:twig

I get the following output:
(Removed some project specific paths and file names)

blt > validate:twig:
     [echo] Validating twig syntax for all custom modules and themes...
KO in [path/to/]templates/content/node--[somecontenttype].html.twig (line 22)
   20           #}
   21           {% for image in node.field_product_offering_images %}
>> 22             {% set isRowEnd = loop.index is divisible by(4) %}
>> Unexpected token "name" of value "by" ("end of statement block" expected).
   23             {% set imageUrl = image.url %}
   24             {% set imageTitle = image.title %}

And I expected this to happen:
divisible by(4) is valid twig syntax and should not fail https://twig.sensiolabs.org/doc/1.x/tests/divisibleby.html

There's an issue on the twig lint project and a couple of PRs that haven't been updated since 2015 for this problem

asm89/twig-lint#25
asm89/twig-lint#33

PR that would address:
asm89/twig-lint#23

Filing this as it looks like we should probably patch this somehow, or find another linter that is being more actively maintained.

@grasmash grasmash added the Bug Something isn't working label May 30, 2017
@grasmash
Copy link
Contributor

@sarahjean Do you have another linter you'd suggest?

@sarahjean
Copy link
Author

@grasmash Not currently, doing some research

grasmash added a commit to grasmash/bolt that referenced this issue Sep 7, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Sep 7, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Sep 22, 2017
grasmash added a commit that referenced this issue Sep 22, 2017
@grasmash grasmash reopened this Sep 27, 2017
@grasmash
Copy link
Contributor

Would love for someone to close the loop on this, initial work was piloted here: grasmash@20560e8 but reverted due to failed tests. Needs testing and re-factoring.

@wu-edward
Copy link

Spent some time on this one. The Symfony linter kept failing on Drupal's link() Twig function, but there's not a good way I've found to get the linter to be aware of those filters and functions without bootstrapping Drupal. Never mind any custom functions or filters that might be created. I just added the current Drupal filters and functions manually to the linter's Twig environment so that they'd be ignored, and created config that can be updated for any custom filters and functions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants