Commit 1f2e226f authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3162997 by andypost, Gábor Hojtsy, vacho, uzlov: Exclude node_modules...

Issue #3162997 by andypost, Gábor Hojtsy, vacho, uzlov: Exclude node_modules and bower_components from scan
parent 7d7efe38
...@@ -13,3 +13,5 @@ parameters: ...@@ -13,3 +13,5 @@ parameters:
- */tests/Drupal/Tests/Listeners/Legacy/* - */tests/Drupal/Tests/Listeners/Legacy/*
- */tests/fixtures/*.php - */tests/fixtures/*.php
- */settings*.php - */settings*.php
- */bower_components/*
- */node_modules/*
...@@ -13,6 +13,7 @@ use DrupalFinder\DrupalFinder; ...@@ -13,6 +13,7 @@ use DrupalFinder\DrupalFinder;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Twig\Util\DeprecationCollector; use Twig\Util\DeprecationCollector;
use Twig\Util\TemplateDirIterator;
final class DeprecationAnalyzer { final class DeprecationAnalyzer {
...@@ -486,7 +487,11 @@ final class DeprecationAnalyzer { ...@@ -486,7 +487,11 @@ final class DeprecationAnalyzer {
* @return array * @return array
*/ */
protected function analyzeTwigTemplates($directory) { protected function analyzeTwigTemplates($directory) {
return (new DeprecationCollector($this->twigEnvironment))->collectDir($directory, '.html.twig'); $iterator = new TemplateDirIterator(
new TwigRecursiveIterator($directory)
);
return (new DeprecationCollector($this->twigEnvironment))
->collect($iterator);
} }
/** /**
......
...@@ -243,11 +243,9 @@ final class LibraryDeprecationAnalyzer { ...@@ -243,11 +243,9 @@ final class LibraryDeprecationAnalyzer {
* @return \Drupal\upgrade_status\DeprecationMessage[] * @return \Drupal\upgrade_status\DeprecationMessage[]
*/ */
private function analyzeTwigLibraryDependencies(Extension $extension): array { private function analyzeTwigLibraryDependencies(Extension $extension): array {
$iterator = new TemplateDirIterator(new \RegexIterator( $iterator = new TemplateDirIterator(
new \RecursiveIteratorIterator( new TwigRecursiveIterator($extension->getPath())
new \RecursiveDirectoryIterator($extension->getPath()), \RecursiveIteratorIterator::LEAVES_ONLY );
), '{'.preg_quote('.html.twig').'$}'
));
$deprecations = []; $deprecations = [];
foreach ($iterator as $name => $contents) { foreach ($iterator as $name => $contents) {
......
<?php
namespace Drupal\upgrade_status;
use Drupal\Core\Site\Settings;
/**
* Filters a RecursiveDirectoryIterator to discover Drupal twig template files.
*/
class TwigRecursiveIterator extends \RecursiveIteratorIterator {
/**
* TwigRecursiveIteratorIterator constructor.
*
* @param string $directory
* Directory to search files.
*/
public function __construct(string $directory) {
$exclude = Settings::get('file_scan_ignore_directories', []);
parent::__construct(new \RecursiveCallbackFilterIterator(
new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS),
function ($current) use ($exclude) {
$name = $current->getFilename();
// RecursiveDirectoryIterator::SKIP_DOTS only skips '.' and '..', but
// not hidden directories (like '.git').
return $name[0] !== '.' &&
(($current->isDir() && !in_array($name, $exclude, TRUE)) ||
($current->isFile() && substr($name, -10) === '.html.twig'));
}
), \RecursiveIteratorIterator::LEAVES_ONLY);
}
}
{% set kitten = 'Kitten' %}
{{kitten|deprecatedfilter}}
<?php
function update_status_test_10_compatible_ignored() {
upgrade_status_test_contrib_error_function_8_to_9();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment