Skip to content

Commit 1f3669c

Browse files
By alex.skrypnyk: Fixed Twig standards violations in templates and replaced TwigCS with Twig-CS-Fixer. (#1411)
Co-authored-by: rgaunt <[email protected]>
1 parent 3a3f98d commit 1f3669c

28 files changed

+161
-100
lines changed

.ahoy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ commands:
171171
usage: Lint front-end code (NodeJS dependencies should already be installed).
172172
cmd: |
173173
ahoy cli "npm run --prefix \${DREVOPS_WEBROOT}/themes/contrib/\${DRUPAL_THEME} lint"
174+
ahoy cli "vendor/bin/twig-cs-fixer lint"
174175
ahoy cli "vendor/bin/twig-cs-fixer lint --config=/app/web/themes/contrib/civictheme/.twig-cs-fixer.php /app/web/themes/contrib/civictheme"
175176
lint-check:
176177
cmd: |

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ job-build: &job-build
247247
name: Lint code with PHPMD
248248
command: docker compose exec -T cli vendor/bin/phpmd . text phpmd.xml || [ "${DREVOPS_CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ]
249249
- run:
250-
name: Lint code with Twigcs
251-
command: docker compose exec -T cli vendor/bin/twigcs || [ "${DREVOPS_CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
250+
name: Lint code with Twig CS Fixer
251+
command: docker compose exec -T cli vendor/bin/twig-cs-fixer lint --config=/app/web/themes/contrib/civictheme/.twig-cs-fixer.php /app/web/themes/contrib/civictheme || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ]
252252
- run:
253253
name: Lint code with NPM linters
254254
command: docker compose exec -T cli bash -c "npm run --prefix \${DREVOPS_WEBROOT}/themes/contrib/\${DRUPAL_THEME} lint" || [ "${DREVOPS_CI_NPM_LINT_IGNORE_FAILURE:-0}" -eq 1 ]

.twig-cs-fixer.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

.twig-cs-fixer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$ruleset = new TwigCsFixer\Ruleset\Ruleset();
6+
$ruleset->addStandard(new TwigCsFixer\Standard\Twig());
7+
$ruleset->addRule(new TwigCsFixer\Rules\Delimiter\BlockNameSpacingRule());
8+
$ruleset->addRule(new TwigCsFixer\Rules\Delimiter\DelimiterSpacingRule());
9+
$ruleset->addRule(new TwigCsFixer\Rules\Function\NamedArgumentSpacingRule());
10+
$ruleset->addRule(new TwigCsFixer\Rules\Operator\OperatorNameSpacingRule());
11+
$ruleset->addRule(new TwigCsFixer\Rules\Operator\OperatorSpacingRule());
12+
$ruleset->addRule(new TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule());
13+
$ruleset->addRule(new TwigCsFixer\Rules\Punctuation\TrailingCommaMultiLineRule());
14+
$ruleset->addRule(new TwigCsFixer\Rules\Punctuation\TrailingCommaSingleLineRule());
15+
$ruleset->addRule(new TwigCsFixer\Rules\Literal\HashQuoteRule());
16+
$ruleset->addRule(new TwigCsFixer\Rules\Literal\SingleQuoteRule());
17+
$ruleset->addRule(new TwigCsFixer\Rules\Variable\VariableNameRule(TwigCsFixer\Rules\Variable\VariableNameRule::SNAKE_CASE, '_'));
18+
$ruleset->addRule(new TwigCsFixer\Rules\Whitespace\BlankEOFRule());
19+
$ruleset->addRule(new TwigCsFixer\Rules\Whitespace\EmptyLinesRule());
20+
$ruleset->addRule(new TwigCsFixer\Rules\Whitespace\IndentRule(2));
21+
$ruleset->addRule(new TwigCsFixer\Rules\Whitespace\TrailingSpaceRule());
22+
23+
$finder = new TwigCsFixer\File\Finder();
24+
$finder->in(__DIR__ . '/web/modules/custom');
25+
$finder->in(__DIR__ . '/web/themes/contrib/civictheme/templates')->exclude([
26+
'.components-civictheme',
27+
'components_combined',
28+
]);
29+
30+
$config = new TwigCsFixer\Config\Config();
31+
$config->setRuleset($ruleset);
32+
$config->setFinder($finder);
33+
$config->allowNonFixableRules();
34+
$config->addTokenParser(new Drupal\Core\Template\TwigTransTokenParser());
35+
36+
return $config;

.twig_cs.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
"drupal/core-dev": "^11",
3636
"drupal/drupal-extension": "^5",
3737
"ergebnis/composer-normalize": "^2.42",
38-
"friendsoftwig/twigcs": "^6.2",
3938
"mglaman/phpstan-drupal": "^1.2",
4039
"palantirnet/drupal-rector": "^0.20",
4140
"php-parallel-lint/php-parallel-lint": "^1.3",
4241
"phpcompatibility/php-compatibility": "^9.3",
4342
"phpmd/phpmd": "^2.13",
4443
"phpspec/prophecy-phpunit": "^2.0",
4544
"phpstan/extension-installer": "^1.3",
46-
"pyrech/composer-changelogs": "^1.8"
45+
"pyrech/composer-changelogs": "^1.8",
46+
"vincentlanglet/twig-cs-fixer": "^3.9"
4747
},
4848
"conflict": {
4949
"drupal/drupal": "*"

composer.lock

Lines changed: 78 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"@civictheme/uikit": "github:civictheme/uikit#921eef60baf3dc4bd1aef23beb5c429d199e49b8"
3+
"@civictheme/uikit": "github:civictheme/uikit#fe7fe80b114737aa579576a244c5c54618bcca86"
44
},
55
"scripts": {
66
"uikit-change": "node scripts/civictheme-uikit-version-manager/index.mjs"

scripts/drevops/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ info "Installing development dependencies."
124124
# for production images), so we are installing them here.
125125
#
126126
note "Copying development configuration files into container."
127-
docker compose cp -L .twig_cs.php cli:/app/ 2>"${composer_verbose_output}"
127+
docker compose cp -L .twig-cs-fixer.php cli:/app/ 2>"${composer_verbose_output}"
128128
docker compose cp -L behat.yml cli:/app/ 2>"${composer_verbose_output}"
129129
docker compose cp -L phpcs.xml cli:/app/ 2>"${composer_verbose_output}"
130130
docker compose cp -L phpmd.xml cli:/app/ 2>"${composer_verbose_output}"

0 commit comments

Comments
 (0)