Skip to content

Commit

Permalink
Add Twig linting. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzimmermann authored Aug 19, 2021
1 parent 36ca20a commit f4c60c7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
composer.lock
.idea
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"async-aws/s3": "^1.8",
"php": ">=7.4",
"drush/drush": "^8 || ^10",
"webflo/drupal-finder": "^1.2"
"webflo/drupal-finder": "^1.2",
"vincentlanglet/twig-cs-fixer": "^0.1.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions robo.drupal.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ phpcs_ignore_paths:
phpcs_standards:
- Drupal
- DrupalPractice
twig_lint_enable: true
1 change: 1 addition & 0 deletions robo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ phpcs_ignore_paths:
phpcs_standards:
- PSR12
drupal_document_root: web
twig_lint_enable: false
41 changes: 28 additions & 13 deletions src/Robo/Plugin/Commands/CICommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class CICommands extends Tasks
*/
protected $customCodePaths;

/**
* Boolean indicating whether Twig files should be linted.
*
* @var bool
*/
protected $lintTwigFiles;

/**
* RoboFile constructor.
*/
Expand All @@ -45,6 +52,7 @@ public function __construct()
$this->phpcsCheckExtensions = Robo::config()->get('phpcs_check_extensions');
$this->phpcsIgnorePaths = Robo::config()->get('phpcs_ignore_paths');
$this->customCodePaths = implode(' ', $this->getCustomCodePaths());
$this->lintTwigFiles = Robo::config()->get('twig_lint_enable', true);
}

/**
Expand Down Expand Up @@ -81,7 +89,7 @@ public function jobRunStaticAnalysis(): Result
/**
* Command to check coding standards.
*
* @aliases phpcs
* @aliases phpcs twigcs
*
* @return \Robo\Result
* The result of the set of tasks.
Expand All @@ -91,12 +99,15 @@ public function jobCheckCodingStandards(): Result
$standards = implode(',', $this->getCodingStandards());
$extensions = implode(',', $this->phpcsCheckExtensions);
$ignorePaths = implode(',', $this->phpcsIgnorePaths);
return $this->taskExecStack()
->stopOnFail()
->exec('vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer')
->exec("vendor/bin/phpcs --standard=$standards --extensions=$extensions \
--ignore=$ignorePaths $this->customCodePaths")
->run();
/** @var \Robo\Task\CommandStack $stack */
$stack = $this->taskExecStack()->stopOnFail();
$stack->exec('vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer');
$stack->exec("vendor/bin/phpcs --standard=$standards --extensions=$extensions \
--ignore=$ignorePaths $this->customCodePaths");
if ($this->lintTwigFiles) {
$stack->exec("vendor/bin/twig-cs-fixer lint $this->customCodePaths");
}
return $stack->run();
}

/**
Expand All @@ -112,12 +123,16 @@ public function jobFixCodingStandards(): Result
$standards = implode(',', $this->getCodingStandards());
$extensions = implode(',', $this->phpcsCheckExtensions);
$ignorePaths = implode(',', $this->phpcsIgnorePaths);
return $this->taskExecStack()
->stopOnFail()
->exec('vendor/bin/phpcbf --config-set installed_paths vendor/drupal/coder/coder_sniffer')
->exec("vendor/bin/phpcbf --standard=$standards --extensions=$extensions \
--ignore=$ignorePaths $this->customCodePaths")
->run();
/** @var \Robo\Task\CommandStack $stack */
$stack = $this->taskExecStack()->stopOnFail();
$stack->exec('vendor/bin/phpcbf --config-set installed_paths vendor/drupal/coder/coder_sniffer');
$stack->exec("vendor/bin/phpcbf --standard=$standards --extensions=$extensions \
--ignore=$ignorePaths $this->customCodePaths");
if ($this->lintTwigFiles) {
$stack->exec("vendor/bin/twig-cs-fixer lint $this->customCodePaths --fix");
}

return $stack->run();
}

/**
Expand Down

0 comments on commit f4c60c7

Please sign in to comment.