Skip to content

[TwigBridge] Remove random file name for lint:twig output in case of error #57608

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
Jul 1, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jun 30, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? no
Deprecations? no
Issues Part of #57588
License MIT

In the lint:twig, uniqid is used to generate a file name when linting a template from STDIN.

  • I don't find any reason to use a unique file name. The file name is never stored when the template is tokenized and compiled. The cache is not used.
  • This meaningless file name is displayed in the output in case of error, which is better replaced by the text "Standard Input".

Before:

$ bin/console lint:twig - < vendor/symfony/twig-bridge/Resources/views/Email/zurb_2/notification/body.html.twig
  ERROR  in sf_6681e2dd64a2e2.02015003 (line -1)
  >> The "inky_to_html" filter is part of the InkyExtension, which is not installed/enabled; try running "composer require twig/inky-extra". 
 [WARNING] 0 Twig files have valid syntax and 1 contain errors.

After:

$ bin/console lint:twig - < vendor/symfony/twig-bridge/Resources/views/Email/zurb_2/notification/body.html.twig
  ERROR  in Standard Input (line -1)
  >> The "inky_to_html" filter is part of the InkyExtension, which is not installed/enabled; try running "composer require twig/inky-extra".                                                                                 
 [WARNING] 0 Twig files have valid syntax and 1 contain errors.                                                                                                 

Note: the line -1 is due to the lack of context provided to Twig\Extra\TwigExtraBundle\MissingExtensionSuggestor::suggestFilter()

For reference, this was introduced by #10843

Before: ERROR  in sf_6681e2dd64a2e2.02015003 (line -1)

After:   ERROR  in Standard Input (line -1)
@carsonbot carsonbot added this to the 7.2 milestone Jun 30, 2024
@@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->format = $input->getOption('format') ?? (GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt');

if (['-'] === $filenames) {
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), uniqid('sf_', true))]);
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), 'Standard Input')]);
Copy link
Member

Choose a reason for hiding this comment

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

other alternatives would be php://stdin or just stdin instead, as we are already familiar with these stream abbreviations.

outputs e.g.

ERROR in php://stdin (line -1)
// or
ERROR in stdin (line -1)

Copy link
Member Author

@GromNaN GromNaN Jul 1, 2024

Choose a reason for hiding this comment

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

It's also aimed at front-end developers who only know Twig and not PHP. It could be more specific:

ERROR in Input Template (line -1)

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case, I don't think it matters, there's only one linted template, so no doubt about it.

@nicolas-grekas
Copy link
Member

Thank you @GromNaN.

@nicolas-grekas nicolas-grekas merged commit 0fde17e into symfony:7.2 Jul 1, 2024
9 of 10 checks passed
@GromNaN GromNaN deleted the twig-uniqid branch July 1, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants