Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Twigcs Laravel Package

friendsoftwig/twigcs

Twigcs is a checkstyle/linter for Twig templates, like phpcs for PHP. Scan template directories for coding standard violations, control exit codes via severity, and exclude paths. Install via Composer or PHIVE and run as a CLI tool.

View on GitHub
Deep Wiki
Context7

Checkstyle automation for Twig

Frequently asked questions about Twigcs
Can TwigCS work with Laravel Blade templates directly?
TwigCS is designed for Twig syntax, not Blade. If you use Blade, you’ll need to pre-process templates to Twig syntax (e.g., via a custom script or tool like `twig/extra-bundle`) before linting. This is a common workaround for hybrid projects.
How do I integrate TwigCS into Laravel’s CI/CD pipeline?
Add TwigCS to your `composer.json` under `require-dev`, then run it in CI with a command like `vendor/bin/twigcs check resources/views --format=json`. Fail the build on errors by checking the exit code (non-zero = violations). Use GitHub Actions or GitLab CI for seamless integration.
What Laravel versions and Twig versions does TwigCS support?
TwigCS works with PHP 8.1+ and supports Twig 2.x/3.x. Laravel compatibility depends on your project’s PHP version (e.g., Laravel 9+ requires PHP 8.1+). Ensure your Twig version aligns with the package’s requirements (check the [GitHub repo](https://github.com/friendsoftwig/twigcs)).
How can I customize TwigCS rules for my project?
Create a `.twigcs.yml` config file in your project root to override default rules. For example, to enforce `{% %}` over `{{ }}`, add `rules: { 'TagSyntax': { 'preferred': 'brace' } }`. You can also extend TwigCS with custom PHP rules by implementing the `RuleInterface`.
Does TwigCS conflict with other tools like PHPStan or twiglint?
TwigCS focuses on Twig-specific coding standards (e.g., indentation, tag syntax), while tools like `twiglint` or PHPStan’s Twig extension may cover broader validation (e.g., syntax errors). Audit your stack to avoid redundancy—run both tools in CI and compare outputs to identify overlaps.
Can TwigCS auto-fix Twig template issues like PHP-CS-Fixer?
TwigCS primarily lints templates and doesn’t auto-fix by default. However, you can use the `--fix` flag (if supported in your version) for minor issues like spacing or indentation. For complex fixes, combine it with manual reviews or custom scripts.
How do I exclude specific directories from TwigCS scans?
Use the `--exclude` flag to skip directories, like `twigcs resources/views --exclude vendor`. You can exclude multiple paths by repeating the flag (e.g., `--exclude vendor --exclude tests`). This is useful for ignoring third-party or test templates.
What output formats does TwigCS support for CI integration?
TwigCS supports JSON, XML, and text output. For CI, use `--format=json` to generate machine-readable results, which can be parsed for custom notifications or SonarQube integration. Example: `twigcs check --format=json > twigcs-results.json`.
How do I handle false positives in TwigCS?
Start with default rules, then refine `.twigcs.yml` to allow exceptions. For example, add `rules: { 'DynamicVariable': { 'ignore': ['dynamic_var'] } }` to skip specific cases. Test changes incrementally in CI to avoid breaking builds.
Is TwigCS actively maintained, and how do I contribute?
TwigCS is maintained by the [FriendsOfTwig](https://github.com/friendsoftwig) team, with regular updates for Twig and PHP changes. Contribute by opening issues, submitting PRs, or extending rules via the [GitHub repo](https://github.com/friendsoftwig/twigcs). Check the `CONTRIBUTING.md` for guidelines.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields
splash/sonata-admin
splash/metadata