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

How to exclude node_modules from \Twig\Util\DeprecationCollector::collectDir() #3382

Closed
andypost opened this issue Aug 3, 2020 · 5 comments

Comments

@andypost
Copy link

andypost commented Aug 3, 2020

Drupal's https://www.drupal.org/project/upgrade_status using this class to find deprecated stuff in templates and code

Often at development time node_modules directory exist withing templates and it makes scan very slow

Is there a way to exclude some subdirs from this scan?

@stof
Copy link
Member

stof commented Aug 3, 2020

For now, there is no way to restrict that. This collector is kept simple.

Does the node_modules folder exists without the directory containing the template ? This looks weird to me (and could create issues if you have some user-defined templates in your projects, as they will have access to all files in that folder from Twig).
If the template folder is actually a sibling of the node_modules folder, this would be a matter of specifying the right directory instead.

@andypost
Copy link
Author

andypost commented Aug 3, 2020

Not in templates but in theme directory, the example is



 STATUS         LINE                           MESSAGE                           
--------------------------------------------------------------------------------
Check manually 0    The spaceless tag in                                        
                    "themes/custom/custom_theme/node_modules/twig-loader/test/fixtures/in
                    clude/template.html.twig" at line 19 is deprecated since    
                    Twig 2.7, use the "spaceless" filter with the "apply" tag   
                    instead. See https://drupal.org/node/3071078. 

Looks I can build custom iterator using Finder component and pass it to \Twig\Util\DeprecationCollector::collect() instead of collectDir() https://git.drupalcode.org/project/upgrade_status/-/blob/8.x-2.x/src/DeprecationAnalyzer.php#L445

@stof
Copy link
Member

stof commented Aug 3, 2020

hmm, indeed. I forgot that the collect() method is public, allowing to collect deprecations on an arbitrary file iterator. So this is indeed the solution to your problem.

I'm closing this issue as there is nothing to change in Twig to unlock that.

@stof stof closed this as completed Aug 3, 2020
@andypost
Copy link
Author

andypost commented Aug 3, 2020

@stof thank you a lot!

@uzlov
Copy link

uzlov commented Aug 14, 2020

as for me, will be cool to have ability to add the "ignore list" of dirs or files
something like
public function collectDir($dir, $ext = '.twig', $exclude)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants