Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/motet-a/jinjalint
A linter for Jinja-like templates
https://github.com/motet-a/jinjalint
jinja
Last synced: 3 months ago
JSON representation
A linter for Jinja-like templates
- Host: GitHub
- URL: https://github.com/motet-a/jinjalint
- Owner: motet-a
- License: mit
- Created: 2017-11-08T16:48:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-01T21:52:41.000Z (over 1 year ago)
- Last Synced: 2024-07-19T09:28:18.564Z (4 months ago)
- Topics: jinja
- Language: Python
- Homepage:
- Size: 74.2 KB
- Stars: 69
- Watchers: 4
- Forks: 25
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-linters - jinjalint - A prototype linter which (Linters / HTML)
README
# jinjalint
A prototype linter which checks the indentation and the correctness of
[Jinja][jinja]-like/HTML templates. Can [fix issues][django-commit].It works with [Django’s templates][djangotemplates] too, it should
work with [Twig](https://twig.symfony.com/) 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:```html+jinja
{% if something %}
{% endif %}
``````html+jinja
```
```html+jinja
{% if something %}
not indented properly
{% endif %}
``````html+jinja
{% if something %}{% endif %}
something
{% if not something %}{% 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:```sh
$ jinjalint template-directory/
```…or:
```sh
$ 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](https://pre-commit.com) git hooks framework
Add to your `.pre-commit-config.yaml`:
```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:```yaml
- id: jinjalint
types: [file] # restore the default `types` matching
files: \.(html|sls)$
```## Hacking
Jinjalint is powered by [Parsy][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`.[jinja]: http://jinja.pocoo.org/docs/2.9/
[django-commit]: https://github.com/django/djangoproject.com/commit/14a964d626196c857809d9b3b492ff4cfa4b3f40
[djangotemplates]: https://docs.djangoproject.com/en/1.11/ref/templates/language/
[parsy]: https://github.com/python-parsy/parsy