vincentlanglet/twig-cs-fixer
A coding standards fixer for Twig templates. Analyze and automatically format Twig files with consistent style rules, configurable presets, and CI-friendly checks to keep templates clean and readable across your project.
twig/bridge or spatie/laravel-twig). It enforces Twig-specific coding standards, complementing PHP-CS-Fixer for backend logic.--dev dependency) and integrates seamlessly with Laravel’s vendor/bin CLI tools..twig-cs-fixer.php (parallel to Laravel’s .php-cs-fixer.dist.php), allowing granular control over rules (e.g., disabling VariableNameRule for legacy templates).--no-cache flag) reduces CI/CD overhead, critical for large template repos.composer.json constraints.NamedArgumentSeparatorRule require Twig ≥3.12.0. Audit Laravel’s Twig version (twig/twig) before adoption.FileNameRule) may flag legitimate legacy templates. Requires explicit whitelisting in config.--dry-run first.Finder config accordingly.--report=github/--report=gitlab.PascalCase variables) needed? Override VariableNameRule or NamedArgumentNameRule.--allow-risky=yes or phased rollouts.spatie/laravel-twig or custom Twig setups.php-cs-fixer for PHP, twig-cs-fixer for templates).laravel-pint or roave/security-advisories) or post-merge check (GitHub Actions).twig-cs-fixer lint --report=text).resources/views).vendor/bin/twig-cs-fixer lint --dry-run resources/views → Review output.vendor/bin/twig-cs-fixer fix --allow-risky=yes resources/views..twig-cs-fixer.php with project-specific rules (e.g., override snake_case for kebab-case variables).$ruleset->overrideRule(new TwigCsFixer\Rules\Naming\VariableNameRule('kebab-case'));
.github/workflows/lint.yml:
- name: Twig Lint
run: vendor/bin/twig-cs-fixer lint --report=github --config=.twig-cs-fixer.php resources/views
if: always() and require success() for PRs.storage/framework/views if cached).docs/CODING_STANDARDS.md.twig-cs-fixer.phar).composer.json:
"require": {
"twig/twig": "^3.12"
}
Finder:
$finder->exclude('*.blade.php');
--config to scope rules per project (e.g., --config=packages/app/.twig-cs-fixer.php).composer show twig/twig).git checkout -- resources/views).twig-cs-fixer (templates).composer.json scripts:
"scripts": {
"lint:twig": "twig-cs-fixer lint --report=text",
"fix:twig": "twig-cs-fixer fix"
}
vincentlanglet/twig-cs-fixer updates..twig-cs-fixer.php in version control (not .gitignore)..dist files for team-specific overrides (e.g., .twig-cs-fixer.dist.php).Class not found: Run composer dump-autoload.Twig version mismatch: Update twig/twig or use PHAR.Permission denied: Set cache dir to /tmp/.twig-cs-fixer.cache.--verbose flag or enable custom reporters for logs.docs/ with:
vendor/, node_modules/).@twig-cs-fixer:disable comments).--fix command in a team workshop.--parallel (if supported) or split by directory:
twig-cs-fixer lint resources/views/{admin,public} --parallel
--cache) or use GitHub Actions caching:
- uses: actions/cache@v3
with:
path: ~/.twig-cs-fixer.cache
key: twig-cs-fixer-${{ hashFiles('.twig-cs-fixer.php') }}
How can I help you explore Laravel packages today?