Skip to content

Commit

Permalink
NOTICKET: Add storybook twig linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
elvism-lullabot committed Apr 25, 2024
1 parent 9d89be8 commit 0b8aa9b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions drainpipe-dev/bin/storybook-twig-linter
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);

if (PHP_SAPI !== 'cli') {
return;
}

if (is_file(__DIR__ . '/../../../autoload.php')) {
require_once __DIR__ . '/../../../autoload.php';
}
else {
echo "Composer autoload file not found.\n";
echo "You need to run 'composer install'.\n";
exit(1);
}

use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\File\FileUrlGenerator;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\Console\Application;
use Twig\Loader\ArrayLoader;
use PackageVersions\Versions;

use Sserbin\TwigLinter\StubEnvironment;
use Drupal\Core\Template\TwigExtension;
use Sserbin\TwigLinter\Command\LintCommand;

use TwigStorybook\Service\StoryCollector;
use TwigStorybook\Twig\TwigExtension as StorybookTwigExtension;

$twig = new StubEnvironment(new ArrayLoader, []);

$renderer = Mockery::mock(RendererInterface::class);
$urlGenerator = Mockery::mock(UrlGeneratorInterface::class);
$themeManager = Mockery::mock(ThemeManagerInterface::class);
$dateFormatter = Mockery::mock(DateFormatterInterface::class);
$fileUrlGenerator = Mockery::mock(FileUrlGenerator::class);

$twig->addExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator));

$storyCollector= new StoryCollector();
$twig->addExtension(new StorybookTwigExtension($storyCollector, __DIR__));

$lintCommand = new LintCommand($twig);

$app = new Application('twig-linter', (string) Versions::getVersion('sserbin/twig-linter'));
$app->add($lintCommand);
$app->setDefaultCommand('lint');
$app->run();
1 change: 1 addition & 0 deletions drainpipe-dev/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"composer/composer": "^2.7.2"
},
"bin": [
"bin/storybook-twig-linter",
"bin/drainpipe-twig-linter",
"bin/drainpipe-convert-to-junit-xml"
],
Expand Down

0 comments on commit 0b8aa9b

Please sign in to comment.