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

Twig Cs Fixer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: composer require --dev vincentlanglet/twig-cs-fixer
  2. Run the fixer on a single file: vendor/bin/twig-cs-fixer fix templates/base.html.twig
  3. Check formatting (CI-safe): vendor/bin/twig-cs-fixer check templates/ — exits with 1 if non-compliant
  4. Generate config: Run vendor/bin/twig-cs-fixer init to scaffold a .twig-cs-fixer.php config file in your project root — start here to understand defaults and available rules

Implementation Patterns

  • Project-wide integration: Add to scripts in composer.json:
    {
      "scripts": {
        "twig:fix": "twig-cs-fixer fix templates/",
        "twig:check": "twig-cs-fixer check templates/"
      }
    }
    
  • Pre-commit hook: Use husky or pre-commit to run twig-cs-fixer check on staged .twig files
  • CI pipeline: Include in lint step (e.g., GitHub Actions):
    - run: vendor/bin/twig-cs-fixer check templates/
    
  • Editor tooling: Hook into IDE linting (e.g., VS Code task runner) or formatter for live preview (note: only fix mode modifies files)
  • Team consistency: Commit .twig-cs-fixer.php to enforce shared rules — review diffs to identify style conflicts early

Gotchas and Tips

  • Deterministic output ≠ human preference: The fixer is opinionated — its defaults may conflict with your team’s style. Always review generated config and adjust rules (e.g., twig_operator_space, twig_filter_space, twig_indent)
  • Escaping matters: Enable autoescape mode in Twig config if using custom escaping strategies — the fixer respects Twig’s escaping context and may misbehave if not aligned
  • Partial fix mode: Use --path-mode=override and --allow-risky=yes only after evaluating risk (some rules like twig_tag_syntax may alter semantics if misconfigured)
  • Diff readability: The tool does not handle multiline raw blocks or embedded HTML well by default — consider disabling twig_raw_filter or twig_template_syntax rules if using embedded JS/CSS heavily
  • Extension points: Override rules in .twig-cs-fixer.php using registerCustomRuleset() or addRule() — for complex legacy templates, start with --verbose to trace rule triggers
  • Edge case: Templates using non-ASCII characters (e.g., Cyrillic in comments) may cause inconsistent line endings — ensure encoding is set to utf-8 in config
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport