Skip to content

Commit

Permalink
Adds Twig Coding Standards Fixer (#204)
Browse files Browse the repository at this point in the history
* Adds Twig Coding Standards Fixer

* Adds CircleCI job
  • Loading branch information
thejimbirch authored Sep 21, 2024
1 parent b217d48 commit 1620e2d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 27 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ workflows:
branches:
ignore:
- main
Twig lint:
jobs:
- ci-tools/composer:
tag: *CIMG_PHP_TAG
name: "Twig lint"
context: kanopi-code
command: 'twig-lint'
save-output: true
post-to-github: true
post-artifact-to-github-when: on_fail
report-title: ":x: twig-lint"
filters:
branches:
ignore:
- main
Deployment:
when:
not:
Expand Down
12 changes: 12 additions & 0 deletions .twig-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = new TwigCsFixer\File\Finder();
$finder->exclude('tests');

$config = new TwigCsFixer\Config\Config();
$config->setFinder($finder);
$config->setCacheFile(null);
# See https://www.drupal.org/project/drupal/issues/3284817#comment-15780893
#$config->addTokenParser(new Drupal\Core\Template\TwigTransTokenParser());

return $config;
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ Command | Description
`rector-fix-modules` | Refactors deprecations on the custom modules folder
`rector-fix-themes` | Refactors deprecations on the custom themes folder
`rector-fix` | Runs `rector-fix-modules` and `rector-fix-themes`
`twig-lint-modules` | Runs Twig-CS-Fixer on the custom modules folder
`twig-lint-themes` | Runs Twig-CS-Fixer on the custom themes folder
`twig-lint` | Runs `twig-lint-modules` and `twig-lint-themes`
`twig-fix-modules` | Runs Twig-CS-Fixer with the fix option on custom modules
`twig-fix-themes` | Runs Twig-CS-Fixer with the fix option on custom themes
`twig-fix` | Runs `twig-fix-modules` and `twig-fix-themes`
`code-check` | Runs `phpstan` `rector-modules` `rector-themes` `code-sniff`
`prepare-for-pantheon` | Used by CircleCI for Pantheon
`build-assets` | Used by CircleCI for Pantheon
Expand Down
84 changes: 57 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"drupal/core-dev": "^10.3",
"drupal/default_content": "^2.0@alpha",
"drupal/devel": "^5.1",
"palantirnet/drupal-rector": "^0.20.3"
"palantirnet/drupal-rector": "^0.20.3",
"vincentlanglet/twig-cs-fixer": "^3"
},
"conflict": {
"drupal/drupal": "*"
Expand Down Expand Up @@ -83,25 +84,37 @@
"vendor/bin/phpstan analyse --memory-limit=-1 web/modules/custom web/themes/custom"
],
"rector-modules": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/modules/custom/ --dry-run"
],
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/modules/custom/ --dry-run"
],
"rector-themes": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/themes/custom/ --dry-run"
],
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/themes/custom/ --dry-run"
],
"rector-fix-modules": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/modules/custom/"
],
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/modules/custom/"
],
"rector-fix-themes": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/themes/custom/"
],
"Composer\\Config::disableProcessTimeout",
"vendor/bin/rector process web/themes/custom/"
],
"rector-fix": [
"@rector-fix-modules",
"@rector-fix-themes"
],
"twig-lint-modules": "vendor/bin/twig-cs-fixer lint docroot/modules/custom",
"twig-lint-themes": "vendor/bin/twig-cs-fixer lint docroot/themes/custom",
"twig-lint": [
"@twig-lint-modules",
"@twig-lint-themes"
],
"twig-fix-modules": "vendor/bin/twig-cs-fixer lint --fix docroot/modules/custom",
"twig-fix-themes": "vendor/bin/twig-cs-fixer lint --fix docroot/themes/custom",
"twig-fix": [
"@twig-fix-modules",
"@twig-fix-themes"
],
"code-check": [
"@phpstan",
"@rector-modules",
Expand Down Expand Up @@ -130,21 +143,41 @@
"cypress-e2e"
],
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset"
],
"drush/contrib/{$name}": ["type:drupal-drush"],
"recipes/{$name}": ["type:drupal-recipe"],
"tests/cypress/cypress/support/{$name}": ["type:cypress-support"],
"tests/cypress/cypress/e2e/{$name}": ["type:cypress-e2e"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/private/scripts/quicksilver/{$name}/": ["type:quicksilver-script"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"web/themes/custom/{$name}": ["type:drupal-custom-theme"]
"drush/contrib/{$name}": [
"type:drupal-drush"
],
"recipes/{$name}": [
"type:drupal-recipe"
],
"tests/cypress/cypress/support/{$name}": [
"type:cypress-support"
],
"tests/cypress/cypress/e2e/{$name}": [
"type:cypress-e2e"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/private/scripts/quicksilver/{$name}/": [
"type:quicksilver-script"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-scaffold": {
"locations": {
Expand All @@ -160,9 +193,6 @@
},
"[web-root]/sites/development.services.yml": false
}
},
"patches": {
"drupal/core": { }
}
},
"config": {
Expand All @@ -183,4 +213,4 @@
"php-http/discovery": true
}
}
}
}

0 comments on commit 1620e2d

Please sign in to comment.