Skip to content

Commit

Permalink
Issue #638: Replace sserbin/twig-linter with vincentlanglet/twig-cs-f…
Browse files Browse the repository at this point in the history
…ixer
  • Loading branch information
justafish committed Aug 8, 2024
1 parent cd5d5f6 commit 1545b6d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
21 changes: 11 additions & 10 deletions drainpipe-dev/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
"php": "^8.1",
"ext-json": "*",
"composer-plugin-api": "^2.0",
"phpunit/phpunit": "^9.6.20",
"sserbin/twig-linter": "^3.1.0",
"mikey179/vfsstream": "^1.6.11",
"mockery/mockery": "^1.6.12",
"behat/mink": "^1.11.0",
"symfony/phpunit-bridge": "^6|^7",
"behat/mink-browserkit-driver": "^2.2.0",
"drupal/coder": "^8.3.24",
"lullabot/drainpipe": "*",
"mglaman/phpstan-drupal": "^1.2.11",
"mikey179/vfsstream": "^1.6.11",
"mockery/mockery": "^1.6.12",
"phpspec/prophecy-phpunit": "^2",
"phpstan/phpstan-deprecation-rules": "^1.2.0",
"phpunit/phpunit": "^9|^10",
"symfony/phpunit-bridge": "^6|^7",
"symfony/yaml": "^6|^7",
"drupal/coder": "^8.3.24",
"behat/mink-browserkit-driver": "^2.2.0",
"tijsverkoyen/convert-to-junit-xml": "^1.11.0",
"phpstan/phpstan-deprecation-rules": "^1.2.0",
"phpspec/prophecy-phpunit": "^2"
"vincentlanglet/twig-cs-fixer": "^3.0.0"
},
"require-dev": {
"composer/composer": "^2.7.7"
Expand All @@ -49,7 +49,8 @@
"[project-root]/.ddev/docker-compose.selenium.yaml": "scaffold/nightwatch/docker-compose.selenium.yaml",
"[project-root]/test/nightwatch/example.nightwatch.js": "scaffold/nightwatch/example.nightwatch.js",
"[project-root]/phpcs.xml.dist": "scaffold/phpcs.xml.dist",
"[project-root]/phpstan.neon.dist": "scaffold/phpstan.neon.dist"
"[project-root]/phpstan.neon.dist": "scaffold/phpstan.neon.dist",
"[project-root]/.twig-cs-fixer.dist.php": "scaffold/.twig-cs-fixer.dist.php"
}
}
},
Expand Down
34 changes: 14 additions & 20 deletions drainpipe-dev/bin/drainpipe-twig-linter → ...pipe-dev/scaffold/.twig-cs-fixer.dist.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/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';
print_r(__DIR__);
if (is_file(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
else {
echo "Composer autoload file not found.\n";
Expand All @@ -20,37 +20,31 @@
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;

$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);

$ruleset = new TwigCsFixer\Ruleset\Ruleset();

// default standard.
$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer());

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);
$config->addTwigExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator));

if (class_exists('\TwigStorybook\Twig\TwigExtension')) {
$composer_json = json_decode(file_get_contents(__DIR__ . '/../../../../composer.json'), true);
if (json_last_error()) {
throw new \RuntimeException('Could not parse composer.json');
}

$web_root = $composer_json['extra']['drupal-scaffold']['locations']['web-root'];
$twig->addExtension(new \TwigStorybook\Twig\TwigExtension(new \TwigStorybook\Service\StoryCollector(), '/../../../../' . $web_root));
$config->addExtension(new \TwigStorybook\Twig\TwigExtension(new \TwigStorybook\Service\StoryCollector(), '/../../../../' . $web_root));
}

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

$lintCommand = new LintCommand($twig);

$app = new Application('twig-linter', (string) Versions::getVersion('sserbin/twig-linter'));
$app->add($lintCommand);
$app->setDefaultCommand('lint');
$app->run();
return $config;
11 changes: 10 additions & 1 deletion tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ tasks:
- |
DIRS_ARR=({{.TWIG_DIRS}})
for DIR in "${DIRS_ARR[@]}"; do
./vendor/bin/drainpipe-twig-linter lint $DIR
if [ "{{.format}}" == "junit" ]; then
./vendor/bin/twig-cs-fixer lint $DIR --format junit
else
./vendor/bin/twig-cs-fixer lint $DIR
fi
done
- |
if [ -f ".prettierrc.json" ] && [ -f "yarn.lock" ]; then
Expand Down Expand Up @@ -161,6 +165,11 @@ tasks:
elif [ -f ".stylelintrc.json" ] && [ -f "package-lock.json" ]; then
npm run stylelint "**/*.{css,scss,sass}" --fix
fi
- |
DIRS_ARR=({{.TWIG_DIRS}})
for DIR in "${DIRS_ARR[@]}"; do
./vendor/bin/twig-cs-fixer lint --fix $DIR
done
nightwatch:check:
#desc: Verifies Nightwatch is setup correctly
cmds:
Expand Down
2 changes: 1 addition & 1 deletion tests/local-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eux
# Helper script to setup a local test of Drainpipe
# Copy this to the same directory level that your drainpipe directory is in
composer create-project drupal/recommended-project drainpipe-test --ignore-platform-req=ext-gd
composer create-project drupal/recommended-project drainpipe-test --ignore-platform-reqs
cd drainpipe-test
cp -R ../drainpipe .

Expand Down

0 comments on commit 1545b6d

Please sign in to comment.