All Projects → VincentLanglet → Twig-CS-Fixer

VincentLanglet / Twig-CS-Fixer

Licence: MIT license
A tool to automatically fix Twig Coding Standards issues

Programming Languages

PHP
23972 projects - #3 most used programming language
Twig
543 projects
Makefile
30231 projects

Projects that are alternatives of or similar to Twig-CS-Fixer

symfony-custom-coding-standard
Customized Symfony coding standard
Stars: ✭ 13 (-78.69%)
Mutual labels:  twig, coding-standards
Phpdish
🏠 PHPDish is a powerful forum system written in PHP. It is based on the Symfony PHP Framework.
Stars: ✭ 225 (+268.85%)
Mutual labels:  twig
Twigcs
The missing checkstyle for twig!
Stars: ✭ 166 (+172.13%)
Mutual labels:  twig
Gluebert
gluebert.js is a tiny helper lazy loading DOM Elements, StyleSheets and JavaScript files using dynamic import and code splitting
Stars: ✭ 194 (+218.03%)
Mutual labels:  twig
Twig Bundle
The Twig Bundle provides configuration for using Twig in your applications.
Stars: ✭ 2,150 (+3424.59%)
Mutual labels:  twig
Bitrix Project
Заготовка 1C Bitrix проекта: автозагрузка, композер, базовые ООП компоненты, миграции, модели, современный фронтенд стек, инструменты для деплоя.
Stars: ✭ 207 (+239.34%)
Mutual labels:  twig
Twing
First-class Twig engine for Node.js
Stars: ✭ 163 (+167.21%)
Mutual labels:  twig
Slugify
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
Stars: ✭ 2,697 (+4321.31%)
Mutual labels:  twig
Auditor Bundle
Doctrine audits logs made easy.
Stars: ✭ 221 (+262.3%)
Mutual labels:  twig
Grav
Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
Stars: ✭ 13,067 (+21321.31%)
Mutual labels:  twig
Bolt
The Bolt Design System provides robust Twig and Web Component-powered UI components, reusable visual styles, and powerful tooling to help developers, designers, and content authors build, maintain, and scale best of class digital experiences.
Stars: ✭ 186 (+204.92%)
Mutual labels:  twig
Twig Bridge
Provides integration for Twig with various Symfony components.
Stars: ✭ 2,170 (+3457.38%)
Mutual labels:  twig
Nofw
A no-framework application skeleton
Stars: ✭ 212 (+247.54%)
Mutual labels:  twig
Qr Code Bundle
Bundle for generating QR codes in Symfony
Stars: ✭ 169 (+177.05%)
Mutual labels:  twig
Cms
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.
Stars: ✭ 2,713 (+4347.54%)
Mutual labels:  twig
Command
A library to build command line applications using PHP
Stars: ✭ 164 (+168.85%)
Mutual labels:  twig
Lairdubois
L'Air du Bois is a Community Driven Woodworkers Sharing Platform.
Stars: ✭ 184 (+201.64%)
Mutual labels:  twig
Reactrenderer
Client and Server-side React rendering from PHP
Stars: ✭ 201 (+229.51%)
Mutual labels:  twig
Core
🧿 Bolt 4 core
Stars: ✭ 243 (+298.36%)
Mutual labels:  twig
Htmlpurifierbundle
HTML Purifier is a standards-compliant HTML filter library written in PHP.
Stars: ✭ 234 (+283.61%)
Mutual labels:  twig

Twig CS Fixer

PHP Version Latest Stable Version License Actions Status Coverage Type Coverage Infection MSI

Installation

This standard can be installed with Composer.

Add the coding standard 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 lint --fix /path/to/code

Twig Coding Standard Rules

From the official one.

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

Ensures there is a single space before and after the following operators: comparison operators (==, !=, <, >, >=, <=), math operators (+, -, /, *, %, //, **), logic operators (not, and, or), ~, is, in, and the ternary operator (?:).

Removes any space before and after the .. operator.

Punctuation spacing

Ensures there is a single space after : in hashes and , in arrays and hashes.

Removes any space after an opening parenthesis and before a closing parenthesis in expressions.

Removes any space before and after the following operators: |, ., [].

Removes any space before and after parenthesis in filter and function calls.

Removes any space before and after opening and closing of arrays and hashes.

Custom configuration

Standard

By default, the generic standard is enabled with the twig coding standard rules and the following sniffs:

  • BlankEOFSniff: ensures that files end with one blank line.
  • EmptyLinesSniff: ensures that 2 empty lines do not follow each other.
  • IndentSniff: ensures that files are not indented with tabs.
  • TrailingCommaSingleLineSniff: ensures that single-line arrays, objects and argument lists do not have a trailing comma.
  • TrailingSpaceSniff: ensures that files have no trailing spaces.

If you want to use a custom standard and/or add/disable a sniff, you can provide your own configuration with a .twig-cs-fixer.php file which returns a TwigCsFixer\Config\Config class:

<?php

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\Generic());
$ruleset->removeSniff(TwigCsFixer\Sniff\EmptyLinesSniff::class);

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);

return $config;

If your config is not located in your current directory, you can specify its path using --config when running the command:

vendor/bin/twig-cs-fixer lint --config=dir/.twig-cs-fixer.php /path/to/code

Files

By default, all .twig files in the current directory are linted, except the ones in the vendor directory.

If you want to lint specific files or directories you can pass them as argument. If you want a more sophisticated rule, you can configure it in the .twig-cs-fixer.php file:

<?php

$finder = new TwigCsFixer\File\Finder();
$finder->exclude('myCustomDirectory');

$config = new TwigCsFixer\Config\Config();
$config->setFinder($finder);

return $config;

Cache

By default, cache is enabled and stored in .twig-cs-fixer.cache. Further runs are therefore much faster. Cache is invalidated when a different PHP version, twig-cs-fixer version or ruleset is used.

If you want a custom cache location you can configure it in .twig-cs-fixer.php:

<?php

$config = new TwigCsFixer\Config\Config();
$config->setCacheFile('/tmp/.twig-cs-fixer.cache');

return $config;

To disable cache you can either pass --no-cache when running the command:

vendor/bin/twig-cs-fixer lint --no-cache

or set the cache file to null in your config:

<?php

$config = new TwigCsFixer\Config\Config();
$config->setCacheFile(null);

return $config;

Token parser

If you're using custom token parsers or binary/unary operators, they can be added in your config:

<?php

$config = new TwigCsFixer\Config\Config();
$config->addTwigExtension(new App\Twig\CustomTwigExtension());
$config->addTokenParser(new App\Twig\CustomTokenParser());

return $config;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].