Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTWEBTAKEN-85: Add Twig linter. #19

Merged
merged 9 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
"drupal/core": "^8.8 || ^9.0",
"drupal/drupal-extension": "^4.1",
"ergebnis/composer-normalize": "^2.11",
"friendsoftwig/twigcs": "^4.0",
"irstea/phpcpd-shim": "^6.0",
"irstea/phpmd-shim": "^2.9",
"mglaman/phpstan-drupal": "^0.12.6",
"nette/neon": "^3.2",
"nielsdeblaauw/twigcs-a11y": "^2.0",
"phpro/grumphp-shim": "^1.1",
"phpspec/prophecy": "^1.10",
"phpstan/phpstan-deprecation-rules": "^0.12.5",
Expand Down
8 changes: 8 additions & 0 deletions configs/grumphp-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ grumphp:
- phpcs
- phpmd
- phpstan
- twigcs
- yamllint
tests:
tasks:
Expand Down Expand Up @@ -121,6 +122,13 @@ grumphp:
end_point: ~
timeout: ~
run_always: false
twigcs:
path: 'templates'
severity: 'warning'
ruleset: 'FriendsOfTwig\Twigcs\Ruleset\Official'
MPParsley marked this conversation as resolved.
Show resolved Hide resolved
triggered_by:
- twig
exclude: []
yamllint:
ignore_patterns:
- node_modules/
Expand Down
9 changes: 9 additions & 0 deletions configs/grumphp-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ grumphp:
- phpcs
- phpmd
- phpstan
- twigcs
- yamllint
tests:
tasks:
Expand Down Expand Up @@ -139,6 +140,14 @@ grumphp:
end_point: ~
timeout: ~
run_always: false
twigcs:
path: 'web/themes/custom'
severity: 'warning'
ruleset: 'FriendsOfTwig\Twigcs\Ruleset\Official'
MPParsley marked this conversation as resolved.
Show resolved Hide resolved
triggered_by:
- twig
exclude:
- vendor
yamllint:
whitelist_patterns:
- "#^(\\.[^/]+/)?[^/]+\\.yml$#"
Expand Down
33 changes: 33 additions & 0 deletions src/Digipolisgent/QA/Drupal/Twigcs/Ruleset/Twig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Digipolisgent\QA\Drupal\Twigcs\Ruleset;

use FriendsOfTwig\Twigcs\Ruleset\Official;
use FriendsOfTwig\Twigcs\Ruleset\RulesetInterface;
use NdB\TwigCSA11Y\Ruleset;

/**
* Twig ruleset.
*
* Combines official and wcag rulesets.
*/
class Twig implements RulesetInterface
{
private $twigMajorVersion;

public function __construct(int $twigMajorVersion)
{
$this->twigMajorVersion = $twigMajorVersion;
}

/**
* {@inheritdoc}
*/
public function getRules()
{
$official = new Official($this->twigMajorVersion);
$wcag = new Ruleset($this->twigMajorVersion);

return array_merge($official->getRules(), $wcag->getRules());
}
}