MicroSymfony icon indicating copy to clipboard operation
MicroSymfony copied to clipboard

feature branch: lint Twig files with twigstan/twigstan

Open COil opened this issue 1 year ago • 9 comments

This branch adds twigstan/twigstan to lint Twig files with types check.

Q A
Branch? twigstan
Cleanup? no
Bug fix? may be
Fixed tickets NA
New feature? yes
Doc added? todo
Tests pass? yes
Deprecations? no
License MIT

COil avatar Oct 18 '24 16:10 COil

Before :

18/10/2024 : 17 errors found :

vendor/bin/twigstan                                                                                                                                                   ✔   8.3.11  18:19:58
TwigStan by Ruud Kamphuis and contributors.
Finding dependencies for 8 templates...
Found 0 dependencies...
Compiling 8 templates...
Flattening 8 templates...
Collecting scopes...
 8/8 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

Injecting scope into templates...
Analyzing templates
 8/8 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

Variable 'composer' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_ComposerAction.php:126
🌱 templates/App/Controller/ComposerAction.html.twig:16

Variable 'form' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:148
🌱 templates/App/Controller/FormAction.html.twig:21

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:152
🌱 templates/App/Controller/FormAction.html.twig:28

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:156
🌱 templates/App/Controller/FormAction.html.twig:33

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:160
🌱 templates/App/Controller/FormAction.html.twig:38

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:164
🌱 templates/App/Controller/FormAction.html.twig:43

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:168
🌱 templates/App/Controller/FormAction.html.twig:48

Variable 'dto' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:172
🌱 templates/App/Controller/FormAction.html.twig:53

Variable 'form' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_FormAction.php:183
🌱 templates/App/Controller/FormAction.html.twig:67

Variable 'readme' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_HomeAction.php:126
🌱 templates/App/Controller/HomeAction.html.twig:9

Variable 'form' does not exist.
🔖 offsetAccess.notFound
🐘 compiled__form.php:19
🌱 templates/_form.html.twig:2

Variable 'status_code' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:138
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:5

Variable 'status_code' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:152
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:10

Variable 'status_text' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:156
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:12

Variable 'status_code' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:160
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:12

Variable 'status_code' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:164
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:14

Variable 'status_code' does not exist.
🔖 offsetAccess.notFound
🐘 compiled_error.php:168
🌱 templates/bundles/TwigBundle/Exception/error.html.twig:15

Found 17 errors

COil avatar Oct 18 '24 16:10 COil

After :

TwigStan by Ruud Kamphuis and contributors.
Finding dependencies for 8 templates...
Found 0 dependencies...
Compiling 8 templates...
Flattening 8 templates...
Collecting scopes...
 8/8 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

Injecting scope into templates...
Analyzing templates
 8/8 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

No errors found

COil avatar Oct 18 '24 18:10 COil

After looking at this, I spotted a few bugs/problems in TwigStan that I solved.

I created a PR with updates:

  • https://github.com/strangebuzz/MicroSymfony/pull/99

ruudk avatar Oct 21 '24 10:10 ruudk

Hello @ruudk, I have rebased the branch and updated TwigStan and I have many new errors, it is expected?

  • https://github.com/strangebuzz/MicroSymfony/actions/runs/11880748477/job/33104272440?pr=95

COil avatar Nov 17 '24 17:11 COil

Did you also update twig/twig?

ruudk avatar Nov 17 '24 17:11 ruudk

And phpstan/phpstan

ruudk avatar Nov 17 '24 17:11 ruudk

And phpstan/phpstan

Yes, it is Phpstan 2 (2.0.2) now!

I have reverted Phpstan to 1.0.2 for now. You can drop me a message here, but you think the PHPStab 2.0 can be done.

COil avatar Nov 17 '24 17:11 COil

Did you also update twig/twig?

  • Twig v3.15.0

COil avatar Nov 17 '24 17:11 COil

I found the problem. Twig 3.15 was released in the weekend without me knowing it.

I made sure this won't happen again by doing:

  • https://github.com/twigstan/twigstan/pull/101
  • https://github.com/twigstan/twigstan/pull/102

From now on, TwigStan will support specific / fixed versions of Twig.

Please update twigstan/twigstan.

Btw, PHPStan 2 is not yet supported, it will be soon:

  • https://github.com/twigstan/twigstan/pull/96
  • https://github.com/twigstan/twigstan/pull/103

so it would be best if you could use 1.12 for now.

ruudk avatar Nov 18 '24 08:11 ruudk