PHPackages                             friendsoftwig/twigcs - 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. friendsoftwig/twigcs

ActiveLibrary[Templating &amp; Views](/categories/templating)

friendsoftwig/twigcs
====================

Checkstyle automation for Twig

v6.6.1(3mo ago)3586.1M—4.6%35[21 issues](https://github.com/friendsoftwig/twigcs/issues)[1 PRs](https://github.com/friendsoftwig/twigcs/pulls)20MITPHPPHP ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Oct 12Pushed 3mo ago33 watchersCompare

[ Source](https://github.com/friendsoftwig/twigcs)[ Packagist](https://packagist.org/packages/friendsoftwig/twigcs)[ RSS](/packages/friendsoftwig-twigcs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (39)Used By (20)

Twigcs
======

[](#twigcs)

[![Integrate](https://github.com/friendsoftwig/twigcs/workflows/Integrate/badge.svg)](https://github.com/friendsoftwig/twigcs/actions)

[![Code Coverage](https://camo.githubusercontent.com/2138fb990f1490b99823fcd59c43e0bfd835d8f67677560d5ad81e2a68eb1849/68747470733a2f2f636f6465636f762e696f2f6769746875622f667269656e64736f66747769672f7477696763732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/github/friendsoftwig/twigcs)

[![Latest Stable Version](https://camo.githubusercontent.com/854602ab663a339ca8b3a2361dfff2b26b70d112ef458f12789426b73ea5ee2f/68747470733a2f2f706f7365722e707567782e6f72672f667269656e64736f66747769672f7477696763732f762f737461626c65)](https://packagist.org/packages/friendsoftwig/twigcs)[![Total Downloads](https://camo.githubusercontent.com/dc40b78b7910cdc6d7e201872420799028a271f24504d18c68e3e392b5e224e1/68747470733a2f2f706f7365722e707567782e6f72672f667269656e64736f66747769672f7477696763732f646f776e6c6f616473)](https://packagist.org/packages/friendsoftwig/twigcs)[![Monthly Downloads](https://camo.githubusercontent.com/d7947e7b04380bfe734a6ef3192cad5ecb56cff2c159e0745926f97811f02b8e/687474703a2f2f706f7365722e707567782e6f72672f667269656e64736f66747769672f7477696763732f642f6d6f6e74686c79)](https://packagist.org/packages/friendsoftwig/twigcs)

The missing checkstyle for twig!

Twigcs aims to be what [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) is to php. It checks your codebase for violations on coding standards.

How to install
--------------

[](#how-to-install)

Run

```
composer require --dev friendsoftwig/twigcs
```

to install `friendsoftwig/twigcs` with [`composer`](https://getcomposer.org).

Run

```
phive install friendsoftwig/twigcs
```

to install `friendsoftwig/twigcs` with [`phive`](https://phar.io).

How to run
----------

[](#how-to-run)

Basically, just run:

```
twigcs /path/to/views
```

On Symfony projects, you can run, for instance:

```
twigcs /project/dir/app/Resources/views
```

You will get a summary of the violations in the console. The exit code of the command is based on the severity of any violation found. By default, twigcs only tolerates info, this can be changed at run time:

```
twigcs /path/to/views --severity error   # Allows info and warnings
twigcs /path/to/views --severity warning # Allows info
twigcs /path/to/views --severity info    # Disallows info
twigcs /path/to/views --severity ignore  # Allows everything
```

With the example above, info is still displayed but not altering the exit code.

You can also exclude relative subfolders of path like this:

```
twigcs /path/to/views --exclude vendor
```

Tips: You can use multiple *exclude* parameters.

Restricting output
------------------

[](#restricting-output)

By default TwigCS will output all lines that have violations regardless of whether they match the severity level specified or not. If you only want to see violations that are greater than or equal to the severity level you've specified you can use the `--display` option. For example.

```
twigcs /path/to/views --severity error --display blocking
```

Would only display errors and not warnings.

Alternatively you can use `--display all` which is the default behaviour as described above.

Continuous Integration
----------------------

[](#continuous-integration)

Twigcs can be used with your favorite CI server. The command itself will return a consistent exit code telling the CI job if it failed or succeeded. You can also have a nice xml report (checkstyle format):

```
twigcs /path/to/views --reporter checkstyle > /path/to/report.xml
```

Reporters
---------

[](#reporters)

Twigcs currently supports to following reporters:

```
twigcs /path/to/views --reporter console
twigcs /path/to/views --reporter checkstyle
twigcs /path/to/views --reporter junit
twigcs /path/to/views --reporter emacs
twigcs /path/to/views --reporter json
twigcs /path/to/views --reporter csv
twigcs /path/to/views --reporter githubAction
twigcs /path/to/views --reporter gitlab
```

Using older twig versions
-------------------------

[](#using-older-twig-versions)

By default twigcs is using Twig 3. This means that features like `filter` tags or filtered loops using `if` are not supported anymore. You can use an older twig version using the `twig-version` option:

```
twigcs /path/to/views --twig-version 2
```

Custom coding standard
----------------------

[](#custom-coding-standard)

At the moment the only available standard is the [official one from twig](https://twig.symfony.com/doc/3.x/coding_standards.html).

You can create a class implementing `RulesetInterface` and supply it as a `--ruleset` option to the CLI script:

```
twigcs /path/to/views --ruleset \MyApp\TwigCsRuleset
```

*Note:* `twigcs` needs to be used via composer and the ruleset class must be reachable via composer's autoloader for this feature to work. Also note that depending on your shell, you might need to escape backslashes in the fully qualified class name:

```
twigcs /path/to/views --ruleset \\MyApp\\TwigCsRuleset
```

For more complex needs, have a look at the [custom ruleset documentation](doc/ruleset.md).

File-based configuration
------------------------

[](#file-based-configuration)

Using configuration, you can easily store per-project settings:

```
// ~/.twig_cs.dist.php
