PHPackages                             vincentlanglet/twig-cs-fixer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. vincentlanglet/twig-cs-fixer

ActiveCoding-standard[Templating &amp; Views](/categories/templating)

vincentlanglet/twig-cs-fixer
============================

A tool to automatically fix Twig code style

3.14.0(2mo ago)3398.4M—6.4%36[6 issues](https://github.com/VincentLanglet/Twig-CS-Fixer/issues)20MITPHPPHP &gt;=8.1CI passing

Since Jul 4Pushed yesterday6 watchersCompare

[ Source](https://github.com/VincentLanglet/Twig-CS-Fixer)[ Packagist](https://packagist.org/packages/vincentlanglet/twig-cs-fixer)[ Docs](https://github.com/VincentLanglet/Twig-CS-Fixer)[ GitHub Sponsors](https://github.com/VincentLanglet)[ RSS](/packages/vincentlanglet-twig-cs-fixer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (25)Versions (81)Used By (20)

Twig CS Fixer
=============

[](#twig-cs-fixer)

[![PHP Version](https://camo.githubusercontent.com/31b59a5dcc80514933b231fbec90bc9fc2d514b092523fbae0ae3e1d27bb8d0b/68747470733a2f2f706f7365722e707567782e6f72672f76696e63656e746c616e676c65742f747769672d63732d66697865722f726571756972652f706870)](https://packagist.org/packages/vincentlanglet/twig-cs-fixer)[![Latest Stable Version](https://camo.githubusercontent.com/addb7008913d7dd19133f892b4ee4a008fd97037714721d52c7eb282cc8c9503/68747470733a2f2f706f7365722e707567782e6f72672f76696e63656e746c616e676c65742f747769672d63732d66697865722f76)](https://github.com/VincentLanglet/Twig-CS-Fixer/releases/latest)[![License](https://camo.githubusercontent.com/b7bad7b134ffc53ce3cc19c290132d2c31babdb3a3f5ef95b9060fd33fa74b05/68747470733a2f2f706f7365722e707567782e6f72672f76696e63656e746c616e676c65742f747769672d63732d66697865722f6c6963656e7365)](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/LICENCE)[![Actions Status](https://github.com/VincentLanglet/Twig-CS-Fixer/workflows/Test/badge.svg)](https://github.com/VincentLanglet/Twig-CS-Fixer/actions/workflows/test.yaml?query=branch%3Amain)[![Coverage](https://camo.githubusercontent.com/aa22919a0498d270bc7453757635721db1a65b93dd01857c5a87082f9b40f10f/68747470733a2f2f636f6465636f762e696f2f67682f56696e63656e744c616e676c65742f547769672d43532d46697865722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/VincentLanglet/Twig-CS-Fixer/branch/main)[![Infection MSI](https://camo.githubusercontent.com/3b1aa2578b96ca47dc4949867ec650247181203636337c574fc325255d23ad50/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324656696e63656e744c616e676c6574253246547769672d43532d46697865722532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/VincentLanglet/Twig-CS-Fixer/main)

Installation
------------

[](#installation)

### From composer

[](#from-composer)

This tool can be installed with [Composer](https://getcomposer.org/).

Add the package as a dependency of your project

```
composer require --dev vincentlanglet/twig-cs-fixer
```

Then, use it!

```
vendor/bin/twig-cs-fixer lint /path/to/code
vendor/bin/twig-cs-fixer fix /path/to/code
```

Note

Although [bin-dependencies may have composer conflicts](https://github.com/bamarni/composer-bin-plugin#why-a-hard-problem-with-a-simple-solution), this is the recommended way because it will autoload everything you need.

### As a PHAR

[](#as-a-phar)

You can always fetch the stable version as a Phar archive through the following link with the `VERSION` you're looking for:

```
wget -c https://github.com/VincentLanglet/Twig-CS-Fixer/releases/download/VERSION/twig-cs-fixer.phar
```

The PHAR files are signed with a public key which can be queried at `keys.openpgp.org` with the id `AC0E7FD8858D80003AA88FF8DEBB71EDE9601234`.

Tip

You will certainly need to add

```
require_once __DIR__.'/vendor/autoload.php';
```

in your [config file](docs/configuration.md) in order to:

- Use existing [node based rules](docs/configuration.md#node-based-rules).
- Write your own custom rules.

Twig Coding Standard Rules
--------------------------

[](#twig-coding-standard-rules)

From the [official one](https://twig.symfony.com/doc/3.x/coding_standards.html).

### Delimiter spacing

[](#delimiter-spacing)

Ensures there is a single space after a delimiter opening (`{{`, `{%` and `{#`) and before a delimiter closing (`}}`, `%}` and `#}`).

When using a whitespace control character, do not put any spaces between it and the delimiter.

### Operator spacing

[](#operator-spacing)

Ensures there is a single space before and after the following operators: comparison operators (`==`, `!=`, ``, `>=`, `
