diff --git a/.gitignore b/.gitignore index b0de3ae..f1694b8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ .phpunit.result.cache .phpunit.cache ###< phpunit/phpunit ### + +###> vincentlanglet/twig-cs-fixer ### +/.twig-cs-fixer.cache +###< vincentlanglet/twig-cs-fixer ### diff --git a/Makefile b/Makefile index 0d7d69b..dc6e6a2 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,9 @@ lint-container: ## Lint the Symfony DI container lint-twig: ## Lint Twig files @bin/console lint:twig templates/ +fix-twig: ## Fix Twig files with Twig CS Fixer + @vendor/bin/twig-cs-fixer lint --fix ./templates + lint-yaml: ## Lint YAML files @bin/console lint:yaml --parse-tags config/ @@ -78,7 +81,7 @@ cs: ## Run all CS checks cs: fix-php stan lint: ## Run all lints -lint: lint-php lint-container lint-twig lint-yaml +lint: lint-php lint-container lint-twig lint-yaml fix-twig ci: ## Run CI locally ci: coverage warmup cs lint diff --git a/castor.php b/castor.php index f3c6c9c..3b7628b 100644 --- a/castor.php +++ b/castor.php @@ -205,6 +205,14 @@ function lint_twig(): int return exit_code('bin/console lint:twig templates/'); } +#[AsTask(name: 'fix-twig', namespace: 'cs', description: 'Lint Twig files', aliases: ['fix-twig'])] +function fix_twig(): int +{ + title('fix:twig'); + + return exit_code('@vendor/bin/twig-cs-fixer lint --fix ./templates'); +} + #[AsTask(name: 'yaml', namespace: 'lint', description: 'Lint Yaml files', aliases: ['lint-yaml'])] function lint_yaml(): int { diff --git a/composer.json b/composer.json index 27b1a20..8a71d32 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ "symfony/maker-bundle": "^1.61", "symfony/requirements-checker": "^2.0", "symfony/stopwatch": "~7.1.0", - "symfony/web-profiler-bundle": "~7.1.0" + "symfony/web-profiler-bundle": "~7.1.0", + "vincentlanglet/twig-cs-fixer": "^3.3" }, "replace": { "symfony/polyfill-ctype": "*", diff --git a/composer.lock b/composer.lock index fea43a0..3e5b65c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e037fde2e1ee94aa91287693db228676", + "content-hash": "a54cb7579771be7526a3f125a100aacc", "packages": [ { "name": "composer/semver", @@ -8385,6 +8385,144 @@ } ], "time": "2024-03-03T12:36:25+00:00" + }, + { + "name": "vincentlanglet/twig-cs-fixer", + "version": "3.3.1", + "source": { + "type": "git", + "url": "https://github.com/VincentLanglet/Twig-CS-Fixer.git", + "reference": "595fe48a3bf43282d21e6930e433d22014f9ecbd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/VincentLanglet/Twig-CS-Fixer/zipball/595fe48a3bf43282d21e6930e433d22014f9ecbd", + "reference": "595fe48a3bf43282d21e6930e433d22014f9ecbd", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.0.0", + "ext-ctype": "*", + "ext-json": "*", + "php": ">=8.0", + "symfony/console": "^5.4.9 || ^6.4 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.4 || ^7.0", + "symfony/finder": "^5.4 || ^6.4 || ^7.0", + "symfony/string": "^5.4.42 || ^6.4.10 || ~7.0.10 || ^7.1.3", + "twig/twig": "^3.4", + "webmozart/assert": "^1.10" + }, + "require-dev": { + "composer/semver": "^3.2.0", + "dereuromark/composer-prefer-lowest": "^0.1.10", + "ergebnis/composer-normalize": "^2.29", + "friendsofphp/php-cs-fixer": "^3.13.0", + "infection/infection": "^0.26.16 || ^0.27.0", + "phpstan/phpstan": "^1.9.1", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpstan/phpstan-symfony": "^1.2.16", + "phpstan/phpstan-webmozart-assert": "^1.2.2", + "phpunit/phpunit": "^9.5.26 || ^10.0.9", + "psalm/plugin-phpunit": "^0.18.4", + "psalm/plugin-symfony": "^5.0.0", + "rector/rector": "^1.0.0", + "shipmonk/composer-dependency-analyser": "^1.6", + "symfony/process": "^5.4 || ^6.4 || ^7.0", + "symfony/twig-bridge": "^5.4 || ^6.4 || ^7.0", + "symfony/ux-twig-component": "^2.2.0", + "twig/cache-extra": "^3.2", + "vimeo/psalm": "^5.2.0" + }, + "bin": [ + "bin/twig-cs-fixer" + ], + "type": "coding-standard", + "autoload": { + "psr-4": { + "TwigCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Vincent Langlet" + } + ], + "description": "A tool to automatically fix Twig code style", + "homepage": "https://github.com/VincentLanglet/Twig-CS-Fixer", + "support": { + "issues": "https://github.com/VincentLanglet/Twig-CS-Fixer/issues", + "source": "https://github.com/VincentLanglet/Twig-CS-Fixer/tree/3.3.1" + }, + "funding": [ + { + "url": "https://github.com/VincentLanglet", + "type": "github" + } + ], + "time": "2024-11-06T16:21:28+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" } ], "aliases": [], @@ -8403,6 +8541,6 @@ "ext-simplexml": "*", "ext-xml": "*" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/symfony.lock b/symfony.lock index ee67a77..78cc279 100644 --- a/symfony.lock +++ b/symfony.lock @@ -183,5 +183,14 @@ }, "twig/extra-bundle": { "version": "v3.5.1" + }, + "vincentlanglet/twig-cs-fixer": { + "version": "3.3", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "0.6", + "ref": "e4da12a48e8138479bd24a675321bcfd84950266" + } } } diff --git a/templates/App/Controller/FormAction.html.twig b/templates/App/Controller/FormAction.html.twig index 6601f31..0e7f94e 100644 --- a/templates/App/Controller/FormAction.html.twig +++ b/templates/App/Controller/FormAction.html.twig @@ -64,7 +64,7 @@
{% endif %} {% endblock %} diff --git a/templates/App/Controller/StimulusAction.html.twig b/templates/App/Controller/StimulusAction.html.twig index 8493028..265da87 100644 --- a/templates/App/Controller/StimulusAction.html.twig +++ b/templates/App/Controller/StimulusAction.html.twig @@ -64,7 +64,7 @@