Giter Site home page Giter Site logo

jinjalint's Introduction

jinjalint

A prototype linter which checks the indentation and the correctness of Jinja-like/HTML templates. Can fix issues.

It works with Django’s templates too, it should work with Twig and similar template languages. It should work fine with any kind of HTML 4 and 5, however XHTML is not supported.

This linter parses both HTML and Jinja tags and will report mismatched tags and indentation errors:

<div>
    {% if something %}
    </div>
{% endif %}
<div>
    <span>
    </div>
</span>
  {% if something %}
 <div> not indented properly
      </div>
   {% endif %}
{% if something %}<a href="somewhere">{% endif %}
    <p>something</p>
{% if not something %}</a>{% endif %}

Usage

You need Python 3. Jinjalint doesn’t work with Python 2. Install it with pip install jinjalint (or pip3 install jinjalint depending on how pip is called on your system), then run it with:

$ jinjalint template-directory/

…or:

$ jinjalint some-file.html some-other-file.html

This is a work in progress. Feel free to contribute 🙃

Usage with pre-commit git hooks framework

Add to your .pre-commit-config.yaml:

-   repo: https://github.com/motet-a/jinjalint
    rev: ''  # select a tag / sha to point at
    hooks:
    -   id: jinjalint

Make sure to fill in the rev with a valid revision.

Note: by default this configuration will only match .jinja and .jinja2 files. To match by regex pattern instead, override types and files as follows:

    -   id: jinjalint
        types: [file]  # restore the default `types` matching
        files: \.(html|sls)$

Hacking

Jinjalint is powered by Parsy. Parsy is an extremely powerful library and Jinjalint’s parser relies heavily on it. You have to read Parsy’s documentation in order to understand what’s going on in parse.py.

jinjalint's People

Contributors

motet-a avatar joesuf4 avatar asottile avatar malikolivier avatar revelt avatar

Stargazers

 avatar Roman avatar

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.