Skip to content

Commit

Permalink
Merge pull request #665 from grasmash/issue-43-twig-lint
Browse files Browse the repository at this point in the history
Adding validate:twig target.
  • Loading branch information
grasmash authored Nov 14, 2016
2 parents 7108f60 + 2b2fcf8 commit 94da228
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bin/blt-console
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ else {
$application = new Application();
$application->add(new ComposerMungeCommand());
$application->add(new YamlMungeCommand());
$application->add(new LintCommand());
$application->add(new \Acquia\Blt\Console\Command\TwigLintCommand);
$application->run();
8 changes: 8 additions & 0 deletions phing/tasks/filesets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<exclude name="**/vendor/**/*"/>
</patternset>

<!--
PHP Files
-->
<fileset dir="${repo.root}" id="files.php.all">
<patternset refid="files.php"/>
</fileset>
Expand All @@ -36,7 +39,12 @@
<patternset refid="files.php"/>
</fileset>

<!--
Frontend Files
-->
<fileset dir="${docroot}/themes/custom" id="files.frontend.custom.themes" expandsymboliclinks="true">
<patternset refid="files.frontend"/>
</fileset>


</project>
14 changes: 12 additions & 2 deletions phing/tasks/validate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- Run all validation targets. -->
<target name="validate:all" description="Runs all code validation targets."
depends="validate:composer, validate:lint, validate:phpcs"
depends="validate:composer, validate:lint, validate:phpcs, validate:twig"
hidden="true" />

<!-- Verify that composer json and lock files are in sync. -->
Expand Down Expand Up @@ -62,7 +62,7 @@
showWarnings="true"
haltonerror="true"
haltonwarning="true"
verbosity="1"/>
verbosity="${blt.verbose}"/>
</target>

<!-- Run code sniffer against all custom code. -->
Expand All @@ -85,4 +85,14 @@
</phpcodesniffer>
</target>

<target name="validate:twig" description="Validates twig syntax on custom twig files.">
<echo>Validating twig syntax for all custom modules and themes...</echo>
<exec dir="${repo.root}" command="${composer.bin}/blt-console lint:twig ${repo.root} ${docroot}/modules/custom ${docroot}/themes/custom" logoutput="true" checkreturn="true" passthru="true" level="${blt.exec_level}" />
</target>

<target name="validate:twig:files" description="Validates twig syntax on custom twig files.">
<fail unless="files" message="Missing files parameter."/>
<exec dir="${repo.root}" command="${composer.bin}/blt-console lint:twig ${repo.root} ${files}" logoutput="true" checkreturn="true" passthru="true" level="${blt.exec_level}" />
</target>

</project>
11 changes: 5 additions & 6 deletions scripts/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ if [ ! -f $PHPCS_BIN ];
then
echo "PHP Code Sniffer was not found in this project's bin directory. Please run composer install. "
exit 1
else
echo "Sniffing staged files via PHP Code Sniffer."
fi

${ROOT_DIR}/vendor/bin/blt validate:phpcs:files -Dfiles="$LIST" -q
echo "Sniffing staged files via PHP Code Sniffer..."
${ROOT_DIR}/vendor/bin/blt validate:phpcs:files -Dfiles="$LIST" -silent -emacs || exit 1;
echo "Linting staged twig files..."
${ROOT_DIR}/vendor/bin/blt validate:twig:files -Dfiles="$LIST" -silent -emacs || exit 1;

# Return the status of the phing task. Any target executed should throw a build exception to prevent
# code from being committed during the precommit. The hooks can be skipped by adding `--no-verify` to
# a commit.
# Return the status of the last run command.
exit $?
28 changes: 28 additions & 0 deletions src/Console/Command/TwigLintCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Acquia\Blt\Console\Command;

use Symfony\Bridge\Twig\Command\LintCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;

class TwigLintCommand extends LintCommand
{

protected function configure() {
$this->addArgument('environment-dir', InputOption::VALUE_REQUIRED);
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$loader = new \Twig_Loader_Filesystem($input->getArgument('environment-dir'));
$this->setTwigEnvironment(new \Twig_Environment($loader));
parent::execute($input, $output);
}
}

0 comments on commit 94da228

Please sign in to comment.