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

feature branch: lint Twig files with twigstan/twigstan #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

COil
Copy link
Member

@COil COil commented Oct 18, 2024

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 COil added DX Developer Experience feature branch Feeature branch demo wip labels Oct 18, 2024
@COil COil self-assigned this Oct 18, 2024
@COil
Copy link
Member Author

COil commented Oct 18, 2024

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 COil force-pushed the twigstan branch 2 times, most recently from 77b7a47 to b9ea9dd Compare October 18, 2024 18:41
@COil
Copy link
Member Author

COil commented Oct 18, 2024

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 COil force-pushed the twigstan branch 2 times, most recently from 8fc4d16 to 7e7edc1 Compare October 18, 2024 18:46
@COil COil changed the title feature branch: lint twig files with twigstan feature branch: lint Twig files with twigstan/twigstan Oct 18, 2024
@COil COil force-pushed the twigstan branch 2 times, most recently from 1c1c766 to 3e27c17 Compare October 18, 2024 19:18
castor.php Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
twig-loader.php Outdated Show resolved Hide resolved
twigstan.php Show resolved Hide resolved
src/Kernel.php Outdated Show resolved Hide resolved
@ruudk
Copy link

ruudk commented Oct 21, 2024

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

I created a PR with updates:

@COil COil force-pushed the twigstan branch 3 times, most recently from dfcce5d to 73af736 Compare October 21, 2024 19:38
@COil COil mentioned this pull request Oct 21, 2024
@COil COil removed the wip label Oct 21, 2024
@@ -45,7 +45,7 @@

<tr>
<th>Birthay</th>
<td>{{ dto.birthday|date('Y-m-d') }}</td>
<td>{{ dto.birthday ? dto.birthday|date('Y-m-d') : 'NA' }}</td>
Copy link
Member Author

Choose a reason for hiding this comment

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

Bug found ! 🐛

@COil
Copy link
Member Author

COil commented Nov 17, 2024

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

@ruudk
Copy link

ruudk commented Nov 17, 2024

Did you also update twig/twig?

@ruudk
Copy link

ruudk commented Nov 17, 2024

And phpstan/phpstan

@COil
Copy link
Member Author

COil commented Nov 17, 2024

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
Copy link
Member Author

COil commented Nov 17, 2024

Did you also update twig/twig?

  • Twig v3.15.0

@ruudk
Copy link

ruudk commented Nov 18, 2024

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:

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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Developer Experience feature branch Feeature branch demo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants