Skip to content

Commit

Permalink
Merge pull request #16287 from mauriciofauth/twig-linter
Browse files Browse the repository at this point in the history
Add a linter for the Twig templates
  • Loading branch information
MauricioFauth committed Jul 31, 2020
2 parents bd35815 + 168cf05 commit 1079964
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -50,6 +50,7 @@ jobs:
- composer phpcs
- yarn run js-lint --quiet
- yarn run css-lint
- php scripts/console lint:twig templates --show-deprecations

- stage: "Lint and analyse code"
name: "Run phpstan"
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -89,7 +89,9 @@
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
"pragmarx/google2fa-qrcode": "^1.0.1",
"samyoul/u2f-php-server": "^1.1",
"symfony/console": "^4.3",
"symfony/console": "^4.4",
"symfony/finder": "^4.4",
"symfony/twig-bridge": "^4.4",
"tecnickcom/tcpdf": "^6.3",
"vimeo/psalm": "^3.11"
},
Expand Down
44 changes: 44 additions & 0 deletions scripts/console
Expand Up @@ -3,7 +3,24 @@

use PhpMyAdmin\Command\AdvisoryRulesCommand;
use PhpMyAdmin\Command\CacheWarmupCommand;
use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Twig\CoreExtension;
use PhpMyAdmin\Twig\I18nExtension;
use PhpMyAdmin\Twig\MessageExtension;
use PhpMyAdmin\Twig\PluginsExtension;
use PhpMyAdmin\Twig\RelationExtension;
use PhpMyAdmin\Twig\SanitizeExtension;
use PhpMyAdmin\Twig\TableExtension;
use PhpMyAdmin\Twig\TrackerExtension;
use PhpMyAdmin\Twig\TransformationsExtension;
use PhpMyAdmin\Twig\UrlExtension;
use PhpMyAdmin\Twig\UtilExtension;
use Symfony\Bridge\Twig\Command\LintCommand;
use Symfony\Component\Console\Application;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

if (! defined('ROOT_PATH')) {
define('ROOT_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR);
Expand All @@ -19,9 +36,36 @@ if (! class_exists(Application::class)) {
exit(1);
}

$cfg['environment'] = 'production';
$PMA_Config = new Config(CONFIG_FILE);
$PMA_Config->set('environment', $cfg['environment']);
$dbi = new DatabaseInterface(new DbiDummy());
$tplDir = ROOT_PATH . 'templates';
$tmpDir = ROOT_PATH . 'twig-templates';

$loader = new FilesystemLoader($tplDir);
$twig = new Environment($loader, [
'auto_reload' => true,
'cache' => $tmpDir,
]);
$twig->setExtensions([
new CoreExtension(),
new I18nExtension(),
new MessageExtension(),
new PluginsExtension(),
new RelationExtension(),
new SanitizeExtension(),
new TableExtension(),
new TrackerExtension(),
new TransformationsExtension(),
new UrlExtension(),
new UtilExtension(),
]);

$application = new Application('phpMyAdmin Console Tool');

$application->add(new AdvisoryRulesCommand());
$application->add(new CacheWarmupCommand());
$application->add(new LintCommand($twig));

$application->run();

0 comments on commit 1079964

Please sign in to comment.