- 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.