{{ 🎀}} Prototype linter for Jinja and Django templates, forked from jinjalint
Project description
curlylint
{{ 🎀}} Prototype linter for Jinja and Django templates, forked from jinjalint.
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. Curlylint doesn’t work with Python 2. Install it with
pip install curlylint
(or pip3 install curlylint
depending on how pip
is
called on your system), then run it with:
curlylint template-directory/
…or:
curlylint some-file.html some-other-file.html
This is a work in progress. Feel free to contribute :upside_down_face:
CLI flags
--verbose
Turns on verbose mode. This makes it easier to troubleshoot what configuration is used, and what files are being linted.
curlylint --verbose template-directory/
--parse-only
Don’t lint, check for syntax errors and exit.
curlylint --parse-only template-directory/
Configuration
Curlylint supports defining a config file with the flag --config
. Here is an example config file with the available options:
# Specify additional Jinja elements which can wrap HTML here. You
# don't need to specify simple elements which can't wrap anything like
# {% extends %} or {% include %}.
# Default: [].
jinja_custom_elements_names = [
('cache', 'endcache'),
('captureas', 'endcaptureas'),
# ('for', 'else', 'empty', 'endfor'),
]
# How many spaces to use when checking indentation.
# Default: 4
indent_size = 4
This config file can then be used with:
curlylint --config example_config.py template-directory/
Usage with pre-commit git hooks framework
Add to your .pre-commit-config.yaml
:
- repo: https://github.com/thibaudcolas/curlylint
rev: "" # select a tag / sha to point at
hooks:
- id: curlylint
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: curlylint
types: [file] # restore the default `types` matching
files: \.(html|sls)$
Contributing
See anything you like in here? Anything missing? We welcome all support, whether on bug reports, feature requests, code, design, reviews, tests, documentation, and more. Please have a look at our contribution guidelines.
If you just want to set up the project on your own computer, the contribution guidelines also contain all of the setup commands.
Credits
Image credit: FxEmojis.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file curlylint-0.6.0.tar.gz
.
File metadata
- Download URL: curlylint-0.6.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fd04c2f2d7e6b029379c30a0ea0d59058f4a6a73b2fe34d1ff40f59933a0e7d |
|
MD5 | 65769fa10cac96208197ae312ee0133e |
|
BLAKE2b-256 | 3c365ad426b24d790c0aad65184bc5645d5c1b4c7a95604f77c81a8bc9b48316 |