Skip to content

Commit

Permalink
Add Twig CS Fixer for lint and fix tasks (#254)
Browse files Browse the repository at this point in the history
* Add Twig CS Fixer for Skeleton

* Fix code style for config files

* Adjust tasks

* Update version in composer.json file
  • Loading branch information
alexander-schranz authored Aug 29, 2024
1 parent 262ac02 commit 2e30526
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ phpstan.neon
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< php-cs-fixer/shim ###

###> vincentlanglet/twig-cs-fixer ###
/.twig-cs-fixer.php
/.twig-cs-fixer.cache
###< vincentlanglet/twig-cs-fixer ###
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->ignoreDotFiles(false)
->exclude('var')
->notName('bundles.php');

Expand Down
19 changes: 19 additions & 0 deletions .twig-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

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

$finder = new TwigCsFixer\File\Finder();
$finder->in('templates/');

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

// $config->addTwigExtension(new Sulu\Twig\Extensions\PortalExtension());
// $config->addTokenParser(new Sulu\Twig\Extensions\TokenParser\PortalTokenParser());

return $config;
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"symfony/phpunit-bridge": "^7.1",
"symfony/thanks": "^1.2",
"symfony/web-profiler-bundle": "^7.1",
"thecodingmachine/phpstan-strict-rules": "^1.0"
"thecodingmachine/phpstan-strict-rules": "^1.0",
"vincentlanglet/twig-cs-fixer": "^3.0"
},
"conflict": {
"symfony/symfony": "*"
Expand Down Expand Up @@ -140,14 +141,16 @@
"@lint-php-cs",
"@lint-rector",
"@lint-twig",
"@lint-twig-cs",
"@lint-yaml",
"@lint-container",
"@lint-composer",
"@lint-doctrine"
],
"fix": [
"@rector",
"@php-cs-fix"
"@php-cs-fix",
"@twig-cs-fix"
],
"phpstan": [
"@php bin/websiteconsole cache:warmup --env=dev",
Expand All @@ -162,6 +165,8 @@
],
"php-cs-fix": "@php vendor/bin/php-cs-fixer fix",
"lint-php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"twig-cs-fix": "@php vendor/bin/twig-cs-fixer lint --fix",
"lint-twig-cs": "@php vendor/bin/twig-cs-fixer lint",
"lint-composer": "@composer validate --no-check-publish --strict",
"lint-twig": "@php bin/console lint:twig templates/",
"lint-yaml": "@php bin/console lint:yaml config/ --parse-tags",
Expand Down
9 changes: 9 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,14 @@
"config/packages/web_profiler.yaml",
"config/routes/web_profiler.yaml"
]
},
"vincentlanglet/twig-cs-fixer": {
"version": "3.0",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "0.6",
"ref": "e4da12a48e8138479bd24a675321bcfd84950266"
}
}
}
12 changes: 6 additions & 6 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

{% block meta %}
{% include "@SuluWebsite/Extension/seo.html.twig" with {
"seo": extension.seo|default([]),
"content": content|default([]),
"localizations": localizations|default([]),
"shadowBaseLocale": shadowBaseLocale|default(),
} %}
{{ include('@SuluWebsite/Extension/seo.html.twig', {
seo: extension.seo|default([]),
content: content|default([]),
localizations: localizations|default([]),
shadowBaseLocale: shadowBaseLocale|default(),
}) }}
{% endblock %}

{% block style %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion templates/error/error.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html.twig" %}
{% extends 'base.html.twig' %}

{% block content %}
<h1>Error {{ status_code }}: {{ status_text }}</h1>
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/default.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html.twig" %}
{% extends 'base.html.twig' %}

{% block content %}
<h1>{{ content.title }}</h1>
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/homepage.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html.twig" %}
{% extends 'base.html.twig' %}

{% block content %}
<h1>{{ content.title }}</h1>
Expand Down
2 changes: 1 addition & 1 deletion templates/search/search.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html.twig" %}
{% extends 'base.html.twig' %}

{% block content %}
<h2>Showing {{ hits|length }} results for "{{ query }}"</h2>
Expand Down

0 comments on commit 2e30526

Please sign in to comment.