Twig-lint - Standalone twig linter

Related tags

Laravel twig-lint
Overview

twig-lint - Standalone twig linter

twig-lint is a lint tool for your twig files.

It can be useful to integrate in your ci setup or as the basis of editor plugins (e.g. syntastic for Vim).

Build Status

Installation / Usage

As a dev dependency (recommended)

Add the following to your composer.json:

{
    "require-dev": {
        "asm89/twig-lint": "*"
    }
}

Run ./bin/twig-lint lint .

As standalone executable

Install as a global composer dependency:

composer global require "asm89/twig-lint" "@stable"

Run ~/.composer/vendor/bin/twig-lint lint .

Vim and Syntastic configuration

For the standalone executable, add the following to your ~/.vimrc file:

let g:syntastic_twig_twiglint_exec = 'php'
let g:syntastic_twig_twiglint_exe = 'php /path/to/twig-lint'

For the composer dependency, twig-lint must be in your $PATH, no further configuration is needed.

Authors

Alexander [email protected]
Marc Weistroff [email protected] (creator of the original twig:lint command in the symfony framework)

License

  • twig-lint is licensed under the MIT License - see the LICENSE file for details
  • I am providing code in this repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not from my employer (Facebook).
Comments
  • Feature/add exclude option

    Feature/add exclude option

    Using the --exclude option enables users to exclude files from validation. The regex functionality should save people from having to fill in the complete path to a file.

    opened by frvge 8
  • twig >1.16.2

    twig >1.16.2

    As I suggested in #9 it would be possible to have two versions of twig-lint to work around the API changes currently breaking with twig >1.16.2

    This version is tested with 1.17, if this solution would be a possibility for you, @asm89, I would test all versions in between.

    Ideas, suggestions?

    opened by tolry 7
  • Makes 3rd arg Extension::getTestNodeClass optional

    Makes 3rd arg Extension::getTestNodeClass optional

    With warnings enabled, the the linter often throws a warning due to a missing third argument:

    PHP Warning:  Missing argument 3 for Asm89\Twig\Lint\Extension\StubbedCore::getTestNodeClass(), called in /path/to/project/vendor/twig/twig/lib/Twig/Extension/Core.php on line 302 and defined in /path/to/project/vendor/asm89/twig-lint/src/Asm89/Twig/Lint/Extension/StubbedCore.php on line 30
    

    Examining the parent class in twig 1.18, this arg is not even present in the signature. Rather than remove it entirely, I defaulted it to null. It's possible it needs to be dropped altogether for eliminating the strict warning about mismatched method signatures.

    opened by bryanagee 6
  • [quick fix] don't use twig version higher then 1.16.2

    [quick fix] don't use twig version higher then 1.16.2

    Liniter is no longer compatible with twig 1.16.2

    Since arguments changed for protected method getTestNodeClass of Twig_Extension_Core https://github.com/asm89/twig-lint/blob/master/src/Asm89/Twig/Lint/Extension/StubbedCore.php#L30 https://github.com/twigphp/Twig/blob/v1.16.2/lib/Twig/Extension/Core.php#L341

    Also some tests starts to faling for twig 1.16.2

    opened by adam187 6
  • Which rules are linted?

    Which rules are linted?

    There is an Atom linter Provider that has twig-lint as prerequisite, so I gave it a try.

    But my templates do not report any linter warnings (or Errors), even if i try to do some ugly code.

    Calling twig-lint in cmd line makes no difference. I always get OK in path\filename as an answer.

    So I have to ask, what rules are checked by the linter?

    opened by OwnerOfThisIsle 3
  • How do I allow Drupal 8 twig_tweak functions?

    How do I allow Drupal 8 twig_tweak functions?

    This package is part of Acquia's BLT framework, but it seems to fail when using the Drupal contributed module twig_tweak. How can I get twig-lint to recognize twig_tweak functions?

    opened by brooke-heaton 2
  • Exclude files or folders based on glob or regex

    Exclude files or folders based on glob or regex

    There's a syntax error that's on purpose in Symfony/Bridge/Twig/Tests/Fixtures/extractor/syntax_error.twig . Our CI always flags this one, which fails the builds.

    Please create an exclude flag that takes one or multiple directories or files and that excludes it from giving errors.

    enhancement 
    opened by frvge 2
  • Versionned binaries

    Versionned binaries

    Hi,

    Would you mind providing versionned binaries? Something like this would be great:

    https://asm89.github.io/d/twig-lint-1.0.1.phar
    

    You can also put binaries in GitHub releases.

    Versionned binaries don’t change and can be verified with a checksum. I’d like to write an Homebrew formula for twig-lint, so people would be able to install your program with brew install twig-lint, but I need a versionned URL.

    Thanks!

    opened by bfontaine 2
  • "same as" alias support

    Hi,

    Linter doesn't recognize same as alias fot sameas test and it throws exception:

    Unexpected token "name" of value "as" ("end of statement block" expected)

    http://twig.sensiolabs.org/doc/tests/sameas.html

    Linter from symfony doesn't throw this error.

    opened by adam187 2
  • Phar is out of date

    Phar is out of date

    http://asm89.github.com/d/twig-lint.phar leverages old dependencies. I noticed it when I upgraded my app to Twig 1.14 and began using the new 'matches' function in Twig Core. Syntastic started flagging it and I discovered it wasn't linting correctly. I downloaded the source, installed new vendors & updated composer.lock, and then built a new phar with Box against the updates and now it works perfectly.

    opened by natelenart 2
  • composer.json allows a too-old version of twig

    composer.json allows a too-old version of twig

    composer.json requires twig 1.*, but Asm89\Twig\Lint\StubbedEnvironment::__construct calls Twig_Environment::initExtensions which appears to have been first added in Twig 1.12.0-RC1 as of https://github.com/fabpot/Twig/commit/44873875ff6ca50c654e3bd28fe19b7ce5108f42

    A minor issue but a possible gotcha.

    opened by parsingphase 2
  • Twig version support

    Twig version support

    I'm not sure if/how many people are still using this linter, but it needs some love.

    One thing I wonder is what to do about supported twig versions. It seems Twig 1.x, 2.x and 3.x are all supported nowadays?

    needsinfo 
    opened by asm89 2
  • Use as tooling to find deprecated twig template elements?

    Use as tooling to find deprecated twig template elements?

    @lauriii looked at possibly using twig-lint to detect deprecated API use, see https://github.com/lauriii/twig-lint/commit/ce92148c3ed053f4cf4444e01269974b051ec269 -- which is obviously very raw, but we were wondering if you think this would be the right tool for this and if you had better ideas?

    enhancement 
    opened by goba 1
  • Null-coalescing operator (??) flagged as invalid

    Null-coalescing operator (??) flagged as invalid

    Using ?? in a Twig templated is flagged as invalid with the following warning:

    Unexpected token "punctuation" of value "?"
    

    It is a default Twig operator (https://twig.symfony.com/doc/2.x/templates.html#other-operators) so it should be valid?

    bug 
    opened by thijskaspers 2
  • Unexpected fail linting

    Unexpected fail linting

    It seems like this should pass, but fails. The template works and looks fine when viewing pages though.

    Twig Code:

    {% set n = content.field_content_blocks['#items']|length %}
    {% set classes = [
                    'n-' ~ p,
                    n is divisible by (2) ? 'n-twos',
                    n is divisible by (3) ? 'n-threes'
            ] %}
            <section class="row crocosmias">
                <div class="col-xs-12 {{ classes|myextensions_join_parts }}">
    

    Lint Error:

    [ExecStack] Done in 7.663s
    > validate:twig:files
    Linting twig files...
    Iterating over fileset files.twig...
    KO in /www/repos/uwmcms/docroot/themes/custom/cust_theme/templates/node/node--fact-page.html.twig (line 28)
       26             {% set classes = [
       27                     'n-' ~ p,
    >> 28                     (n is divisible by (2) ? 'n-twos',
    >> An opened parenthesis is not properly closed. Unexpected token "name" of value "by" ("punctuation" expected with value ")"). 
       29                     (n is divisible by (3)) ? 'n-threes'
       30             ] %}
    
    [error]  Executing `'/www/repos/cust_theme/vendor/bin/twig-lint' lint --only-print-errors '%s'` against fileset(s) files.twig returned a non-zero exit code.` 
    
    
    bug 
    opened by sodacrackers 0
  • Remove Twig_TokenParserBroker (deprecated) + all deprecation warnings

    Remove Twig_TokenParserBroker (deprecated) + all deprecation warnings

    Here's a PR that will fix all deprecation warnings including Twig_TokenParserBroker. This should help with (https://github.com/asm89/twig-lint/issues/31 & https://github.com/phpro/grumphp/pull/199).

    I've dig some things about the deprecation of the Twig_TokenParserBroker (https://github.com/twigphp/Twig/pull/903). One notable change is that Twig 2.x does not offer a way to dynamically add token parser (like it was done with the Twig_TokenParserBroker). Instead, it just look up an array and throws a syntax error. https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Parser.php#L148

    Therefore, you have to provide the list of tags to stub.

    ./bin/twig-lint lint tests/Asm89/Twig/Lint/Test/Fixtures/mixed.twig \
        --stub-tag some_other_block \
        --stub-tag stylesheets \
        --stub-tag meh \
        --stub-tag render \
        --stub-tag trans
    

    Or via the options of the StubbedEnvironment in the constructor.

    $twig = new StubbedEnvironment(
         new \Twig_Loader_Array(),
         array(
             'stub_tags' => $stubTagList,
         )
    );
    

    This might look like but thinking about it, it makes sense to only allow some tags to be stubbed so that a real "unknown tag" in your code can be detected by the linter.

    Additionally, that kind of config would end in the twigcs.yml file, see my other PR.

    opened by adrienrn 2
Owner
Alexander
Alexander
A Composer script to lint a Travis CI configuration file.

composer-travis-lint composer-travis-lint is a Composer script that lints a project/micro-package its Travis CI configuration aka its .travis.yml file

Raphael Stolt 6 Jan 31, 2020
This package wraps up the standalone executable version of the Tailwind CSS framework for a Laravel application.

Tailwind CSS for Laravel Introduction This package wraps the standalone Tailwind CSS CLI tool. No Node.js required. Inspiration This package was inspi

Tony Messias 240 Nov 19, 2022
Allows you to use Twig seamlessly in Laravel

Allows you to use Twig seamlessly in Laravel. Requirements TwigBridge >= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions. In

Rob Crowe 877 Dec 30, 2022
Twig-based PatternEngine for Pattern Lab.

Twig PatternEngine for Pattern Lab The Twig PatternEngine allows you to use Twig as the template language for Pattern Lab PHP. Once the PatternEngine

Pattern Lab 77 Oct 27, 2022
Give the power of Twig to Laravel

Allows you to use Twig seamlessly in Laravel. Requirements TwigBridge >= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions. In

Rob Crowe 866 Jan 30, 2022
⚡️Lightning-fast linter for .env files. Written in Rust 🦀

⚡️ Lightning-fast linter for .env files. Written in Rust ?? Dotenv-linter can check / fix / compare .env files for problems that may cause the applica

null 1.5k Dec 31, 2022
Tighten linter for Laravel conventions.

Install (Requires PHP 7.3+) composer global require tightenco/tlint Upgrade composer global update tightenco/tlint What Is It? This is an opinionate

Tighten 425 Dec 25, 2022
JSON Lint for PHP

JSON Lint Usage use Seld\JsonLint\JsonParser; $parser = new JsonParser(); // returns null if it's valid json, or a ParsingException object. $parser-

Jordi Boggiano 1.3k Dec 26, 2022
`phplint` is a tool that can speed up linting of php files by running several lint processes at once.

`phplint` is a tool that can speed up linting of php files by running several lint processes at once.

安正超 887 Dec 30, 2022
A Composer script to lint a Travis CI configuration file.

composer-travis-lint composer-travis-lint is a Composer script that lints a project/micro-package its Travis CI configuration aka its .travis.yml file

Raphael Stolt 6 Jan 31, 2020
PHP Parallel Lint - This tool check syntax of PHP files faster than serial check with fancier output

PHP Parallel Lint This application checks syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Ad

PHP Parallel lint 156 Apr 24, 2022
Provides a twig editor field with Twig & Craft API autocomplete

Twigfield for Craft CMS 3.x & 4.x Provides a twig editor field with Twig & Craft API autocomplete Requirements Twigfield requires Craft CMS 3.0 or 4.0

nystudio107 13 Nov 1, 2022
Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation

Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation #####On-The-Fly Image Resizing, On-the-fly LESS, SCSS, CoffeeScript Compiling, CSS & JavaS

Cody Lundquist 837 Dec 21, 2022
A standalone DateTime library originally based off of Carbon

CakePHP Chronos Chronos aims to be a drop-in replacement for nesbot/carbon. It focuses on providing immutable date/datetime objects. Immutable objects

CakePHP 1.3k Jan 1, 2023
Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

Cédric Dugat 1.2k Jan 3, 2023
PdfParser, a standalone PHP library, provides various tools to extract data from a PDF file.

PdfParser Pdf Parser, a standalone PHP library, provides various tools to extract data from a PDF file. Website : https://www.pdfparser.org Test the A

Sebastien MALOT 1.9k Jan 2, 2023
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021
A Virtualmin API designed to run standalone or as part of a Laravel Application

Virtualmin API A Virtualmin API designed to run standalone or as part of a Laravel Application Requirements: PHP 8.0 A running Virtualmin server Featu

Fintech Systems 6 Jan 26, 2022
Pat eu cookies law - 🌝 EU Cookie Law Compliance: A Textpattern plugin (or standalone script) for Third-Party Cookies (RGPD compliance)

pat_eu_cookies_law EU Cookie Law Compliance: A Textpattern plugin (or a standalone script) for Third-Party Cookies. A simple solution that respects th

Patrick LEFEVRE 3 Aug 16, 2020
Hprose asynchronous client & standalone server based on swoole

Hprose for Swoole Introduction Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform,

Hprose 186 Sep 9, 2022