Giter Club home page Giter Club logo

twig-lint's Introduction

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 <file>.

As standalone executable

Install as a global composer dependency:

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

Run ~/.composer/vendor/bin/twig-lint lint <file>.

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).

twig-lint's People

Contributors

asm89 avatar bronzehedwick avatar inside avatar nyholm avatar smoench avatar tolry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

twig-lint's Issues

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!

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.

what does twig-lint check?

Can I use twig-lint to check for:

  • trailing whitespace
  • correct indentation
  • maximum line length
  • whether the template is likely to result in correct HTML

Please add some words to the README explaining the scope of twig-lint. Can I write my own sniffs like with PHP Codesniffer?

Custom operator flagged as invalid

I wrote a custom Twig operator in Symfony using a Twig Extension. Symfony recognizes it just fine -- my pages render and app/console twig:lint reports the file is ok. However, Syntastic flags the line as invalid since it triggers twig-lint outside of Symfony and does not know about my extension. Is there an easy way to teach twig-lint about my Symfony extensions?

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.

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.` 

Version `v1.0.2` reports itself as `v1.0.1`

When I install v1.0.2 via Composer the installed code claims to be v1.0.1:

$ twig-lint --version
Twig lint v1.0.1

I tried a few different variants of invoking Composer, but none of those installed a package that would report its version as v1.0.2:

  • composer global require "asm89/twig-lint" "@stable"
  • composer global require "asm89/twig-lint" "1.0.2"
  • composer global require --prefer-source "asm89/twig-lint" "1.0.2"

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?

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?

Print a summary of the lint results

When linting multiple files in CI it makes sense to only print the results of the failed lints. I suggested adding a flag for that in #17. One thing that concerns me is that if we add the flag there's no visibility in the amount of files that got linted in total (it might have linted none!). Let's print a summary at the end of the command. Something like:

Linted 300 files, found 0 errors

Support JSON output

Currently only "csv" and "full" output modes are supported. It would be great to have a JSON output format as well.

Lint fails with "same as" test

Hi,

here is an unexpected lint error :

{% if foo.attribute is same as(false) %}
    the foo attribute really is the 'false' PHP value
{% endif %}

Error :

>> 1      {% if foo.attribute is same as(false) %}
           >> Unexpected token "name" of value "as" ("end of statement block" expected).
              2          the foo attribute really is the 'false' PHP value
              3      {% endif %}

However it works with the test "sameas".

(Twig doc : http://twig.sensiolabs.org/doc/2.x/tests/sameas.html)

Thanks for your help.

Only print errors option

Hi,

It'd be awesome to be able to have an 'only errors' option for printing out. At the moment we lint all our files in our CI process and in the majority of cases we only want the errors to be shown.

In the meantime, I've used the following to filter output:

twig-lint lint ./filepath | grep -v 'OK'

Thanks!

Twig_TokenParserBroker is deprecated

I get the following message while running this tool:

Deprecated: The Twig_TokenParserBroker class is deprecated since version 1.12 and will be removed in 2.0. in vendor/twig/twig/lib/Twig/TokenParserBroker.php on line 36

Twig Lint spacing

It would be great if lint could check for proper indentation in a twig file. Even better would be the ability to configure what it's looking for via an argument or config file. For example, tabs/spaces (and # of spaces).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.