Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX-5153: Add support for custom Twig tests in the Twig validator. #4580

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

pfrenssen
Copy link
Contributor

Fixes #4579

Testing steps

  1. Add the following code to an existing Twig template:
    <div>{{ myvar is instanceof('\\MyInterface') ? 'yes' : 'no' }}</div>
  2. Run the Twig validation. This is expected to throw an error because the instanceof test is not part of core Twig:
    $ blt validate:twig
    ERROR  in /app/docroot/themes/custom/mytheme/templates/mytemplate.html.twig
    >> Unknown "instanceof" test.
  3. Now edit blt.yml and add instanceof to the whitelisted Twig tests by adding the following section:
    validate:
      twig:
        tests:
          - instanceof
  4. Run the validation again. Now there should not be any errors.
    $ blt validate:twig
    [OK] All 235 Twig files contain valid syntax.

Copy link
Contributor

@danepowell danepowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the default value for validate.twig.tests to https://github.com/acquia/blt/blob/main/config/build.yml along with a comment explaining how to use it?

src/Robo/Commands/Validate/TwigCommand.php Outdated Show resolved Hide resolved
@pfrenssen
Copy link
Contributor Author

Thanks for the quick review and suggestions! I made the requested changes.

@danepowell danepowell added the Enhancement A feature or feature request label Aug 17, 2022
@danepowell
Copy link
Contributor

Thanks for the contribution.

@danepowell danepowell merged commit 068d4f1 into acquia:main Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A feature or feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DX-5153: Support custom Twig tests in validate:twig
2 participants