Skip to content

[TwigComponent] Fix twig:lint bug with anonymous component tag #1199

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

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

smnandre
Copy link
Member

Q A
Bug fix? yes
New feature? no
Tickets Fix #1089
License MIT

Sincerely i'm not sure how to handle this properly "today"..

There is a lot of things i'd like to refactor in a future version, and the fact than auto-closing tags and classic ones are handled by two entirely different processes is at the top of my todo :)

But right now, i'm not sure we can do better than a quick patch, allowing the "lint:twig" to not crash for anonymous twig:Foo</twig:Foo> tags.

Timeline of what "bugs":

  • the lint:twig command find all templates, and for each one create an empty template loader, then parse & compile the template
  • during the parsing, the ComponentParser calls ComponentFactory::metadataFor to find the template matching the component name
  • if no class-based component matches, the ComponentFactory calls the the ComponentTemplateFinder
  • the ComponentTemplateFinder then asks the Loader if a matching template exists
  • but as the Loader is temporary "empty".... 🐞

So we must ether:

  • A) stop resolving template during the parser/compiler work
  • B) ensure the TemplateFinder always contains the real "full" loader
  • C) change the way the lint:twig command works

A is my long-term objective, but clearly not "today".
C is not so easy, as the corresponding code is hidden between 3 private methods

So.... first suggestion (dirty but working)

* @internal
*/
private LoaderInterface $loader;

Copy link
Member

Choose a reason for hiding this comment

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

Can we, instead, replace the $environment constructor argument with $loader? We would just need a BC layer (remove the Environment type, then have an if statement that checks the type, and trigger deprecation if it is an Environmnet).

Copy link
Member Author

Choose a reason for hiding this comment

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

Is Environment|LoaderInterface wrong ? (real question, i'm not really used to BC break handling :) )

Copy link
Member

Choose a reason for hiding this comment

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

I think that will work - I still forget we can do this now :)

* @internal
*/
private LoaderInterface $loader;

Copy link
Member

Choose a reason for hiding this comment

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

I think that will work - I still forget we can do this now :)

@weaverryan weaverryan force-pushed the fix/twig-component-lint branch from e44893f to 632954e Compare October 18, 2023 14:32
@weaverryan
Copy link
Member

Thank you Simon - beautiful PR

@weaverryan weaverryan merged commit d3ce11f into symfony:2.x Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TwigComponent] Twig linter does not recognize anonymous components
2 participants