Skip to main content

A linter for Jinja-like templates

Project description

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 :upside_down_face:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

r2c_jinjalint-0.6.2-py2.py3-none-any.whl (24.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file r2c_jinjalint-0.6.2-py2.py3-none-any.whl.

File metadata

  • Download URL: r2c_jinjalint-0.6.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.9

File hashes

Hashes for r2c_jinjalint-0.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1f17302ebed58899b58ee0b7e4b0c4315cc729997b41320fe34f1f5e3b286751
MD5 f39035c9eb19edb720aa4df2e40fbec4
BLAKE2b-256 eeccb82df054be4e7097f60512a824942c40ef93644faefed9c19c55c3dc16bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page