Skip to content

Commit

Permalink
[#1108] Replaced Twigcs with Twig-cs-fixer. (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored Feb 21, 2024
1 parent 5f0c27c commit 7f99229
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ commands:
lint-fe:
usage: Lint front-end code.
cmd: |
ahoy cli vendor/bin/twigcs
ahoy cli vendor/bin/twig-cs-fixer
ahoy cli "npm run --prefix \${DREVOPS_WEBROOT}/themes/custom/\${DRUPAL_THEME} lint"
lint-fix:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ jobs:
command: docker compose exec -T cli vendor/bin/phpmd . text phpmd.xml || [ "${DREVOPS_CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ]
- run:
name: Lint code with Twigcs
command: docker compose exec -T cli vendor/bin/twigcs || [ "${DREVOPS_CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
command: docker compose exec -T cli vendor/bin/twig-cs-fixer || [ "${DREVOPS_CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
- run:
name: Lint code with NPM linters
command: docker compose exec -T cli bash -c "npm run --prefix \${DREVOPS_WEBROOT}/themes/custom/\${DRUPAL_THEME} lint" || [ "${DREVOPS_CI_NPM_LINT_IGNORE_FAILURE:-0}" -eq 1 ]
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ drush/contrib/
!.env
!.eslintrc.json
!.sass-lint.yml
!.twig_cs.php
!.twig-cs-fixer.php
!Gruntfile.js
!auth.json
!behat.yml
Expand Down
2 changes: 1 addition & 1 deletion .drevops/docs/content/drupal/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ effective development environment.
Behat extension that provides integration with Drupal, offering step
definitions specific to Drupal functionality. It facilitates the creation and
management of Drupal sites for testing purposes.
- [`friendsoftwig/twigcs`](https://github.com/friendsoftwig/twigcs): This tool
- [`VincentLanglet/Twig-CS-Fixer`](https://github.com/VincentLanglet/Twig-CS-Fixer): This tool
ensures that Twig templates adhere to a set coding standard, helping maintain
consistency and readability in template files.
- [`mglaman/phpstan-drupal`](https://github.com/mglaman/phpstan-drupal):
Expand Down
2 changes: 1 addition & 1 deletion .drevops/docs/content/introduction/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ with addition of several configuration files and directories.
β”œβ”€β”€ .gitignore # Intentionally untracked files to ignore in Git.
β”œβ”€β”€ .gitignore.deployment # Intentionally untracked files to ignore in artifact deployment.
β”œβ”€β”€ .lagoon.yml # Lagoon configuration file. Removed if not using Lagoon hosting.
β”œβ”€β”€ .twig_cs.php # Twigcs configuration file.
β”œβ”€β”€ .twig-cs-fixer.php # Twigcs configuration file.
β”œβ”€β”€ behat.yml # Behat configuration file.
β”œβ”€β”€ composer.json # Composer configuration file.
β”œβ”€β”€ docker-compose.yml # Docker Compose configuration file.
Expand Down
2 changes: 1 addition & 1 deletion .drevops/docs/content/introduction/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The following list includes βœ… completed and πŸ’‘ upcoming features.
* βœ… [PHPUnit](https://phpunit.de/)
* βœ… [SASS Lint](https://github.com/sasstools/sass-lint)
* βœ… [SASS](https://sass-lang.com/)
* βœ… [Twigcs](https://github.com/friendsoftwig/twigcs)
* βœ… [Twigcs](https://github.com/VincentLanglet/Twig-CS-Fixer)
* πŸ’‘ [Pa11y](https://pa11y.org/)
* βš™οΈ Workflow
* βœ… Database from FTP, CURL, Docker image, hosting provider
Expand Down
30 changes: 18 additions & 12 deletions .drevops/docs/content/tools/twigcs.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Twigcs

https://github.com/friendsoftwig/twigcs
https://github.com/VincentLanglet/Twig-CS-Fixer

> The missing checkstyle for twig!
>
> Twigcs aims to be what phpcs is to php. It checks your codebase for violations on coding standards.
DrevOps comes with [pre-configured Twigcs ruleset](../../../../.twig_cs.php) for Drupal projects.
DrevOps comes with [pre-configured Twigcs ruleset](../../../../.twig-cs-fixer.php) for Drupal projects.

## Usage

```shell
vendor/bin/twigcs
vendor/bin/twig-cs-fixer
```
or
```shell
Expand All @@ -20,20 +20,26 @@ ahoy lint-be

## Configuration

See [configuration reference](https://github.com/friendsoftwig/twigcs#file-based-configuration).
See [configuration reference](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md).

All global configuration takes place in the [`.twig_cs.php`](../../../../.twig_cs.php) file.
All global configuration takes place in the [`.twig-cs-fixer.php`](../../../../.twig-cs-fixer.php) file.

Targets include custom modules and themes.

Adding or removing targets:
```php hl_lines="6"
return Twigcs\Config\Config::create()
->setName('custom-config')
->setSeverity('error')
->setReporter('console')
->setRuleSet(Twigcs\Ruleset\Official::class)
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/themes/custom/mytheme'));
```php hl_lines="12"
$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\Twig());

$finder = new TwigCsFixer\File\Finder();
$finder->in(__DIR__ . '/web/modules/custom');
$finder->in(__DIR__ . '/web/themes/custom');

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);
$config->setFinder($finder);

return $config;
```

## Ignoring
Expand Down
6 changes: 0 additions & 6 deletions .drevops/tests/bats/_helper.workflow.bash
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,6 @@ assert_ahoy_lint_fe() {
sync_to_container
run ahoy lint-fe
assert_failure

substep "Assert that FE lint tool disabling works"
replace_string_content "setSeverity('error')" "setSeverity('ignore')" "$(pwd)"
sync_to_container
run ahoy lint-fe
assert_success
}

assert_ahoy_test() {
Expand Down
16 changes: 16 additions & 0 deletions .twig-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types = 1);

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\Twig());

$finder = new TwigCsFixer\File\Finder();
$finder->in(__DIR__ . '/web/modules/custom');
$finder->in(__DIR__ . '/web/themes/custom');

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);
$config->setFinder($finder);

return $config;
13 changes: 0 additions & 13 deletions .twig_cs.php

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The following list includes βœ… completed and πŸ’‘ upcoming features.
* βœ… [PHPUnit](https://phpunit.de/)
* βœ… [SASS Lint](https://github.com/sasstools/sass-lint)
* βœ… [SASS](https://sass-lang.com/)
* βœ… [Twigcs](https://github.com/friendsoftwig/twigcs)
* βœ… [Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer)
* πŸ’‘ [Pa11y](https://pa11y.org/)
* βš™οΈ Workflow
* βœ… Database from FTP, CURL, Docker image, hosting provider
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
"drevops/behat-steps": "^2",
"drupal/core-dev": "^10.2.0",
"drupal/drupal-extension": "^5@rc",
"friendsoftwig/twigcs": "^6.2",
"mglaman/phpstan-drupal": "^1.2",
"palantirnet/drupal-rector": "^0.19",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.13",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.3",
"pyrech/composer-changelogs": "^1.8"
"pyrech/composer-changelogs": "^1.8",
"vincentlanglet/twig-cs-fixer": "^2.4"
},
"conflict": {
"drupal/drupal": "*"
Expand Down

0 comments on commit 7f99229

Please sign in to comment.