Skip to main content

{{ 🎀}} Prototype linter for Jinja and Django templates, forked from jinjalint

Project description

curlylint

PyPI PyPI downloads Travis Total alerts Language grade: Python

{{ 🎀}} 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/

--quiet

Don’t emit non-error messages to stderr. Errors are still emitted; silence those with 2>/dev/null.

curlylint --quiet template-directory/

--parse-only

Don’t lint, check for syntax errors and exit.

curlylint --parse-only template-directory/

Configuration with pyproject.toml

curlylint is able to read project-specific default values for its command line options from a PEP 518 pyproject.toml file.

Where curlylint looks for the file

By default curlylint looks for pyproject.toml starting from the common base directory of all files and directories passed on the command line. If it's not there, it looks in parent directories. It stops looking when it finds the file, or a .git directory, or a .hg directory, or the root of the file system, whichever comes first.

You can also explicitly specify the path to a particular file that you want with --config. In this situation curlylint will not look for any other file.

If you're running with --verbose, you will see a blue message if a file was found and used.

Configuration format

As the file extension suggests, pyproject.toml is a TOML file. It contains separate sections for different tools. curlylint is using the [tool.curlylint] section. The option keys are the same as long names of options on the command line.

Example `pyproject.toml`
[tool.curlylint]
# How many spaces
indent-size = 4
# Specify additional Jinja elements which can wrap HTML here. You
# don't neet to specify simple elements which can't wrap anything like
# {% extends %} or {% include %}.
jinja-custom-elements-names = [
  ["cache", "endcache"],
  ["captureas", "endcaptureas"]
]
include = '\.(html|jinja)$'
exclude = '''
(
  /(
      \.eggs           # exclude a few common directories in the root of the project
    | \.git
    | \.venv
    | build
    | dist
  )/
  | webpack-stats.html # also separately exclude a file named webpack-stats.html in the root of the project
)
'''

Lookup hierarchy

Command-line options have defaults that you can see in --help. A pyproject.toml can override those defaults. Finally, options provided by the user on the command line override both.

curlylint will only ever use one pyproject.toml file during an entire run. It doesn't look for multiple files, and doesn't compose configuration from different levels of the file hierarchy.

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.

This project is a fork of jinjalint.

Test templates extracted from third-party projects. View the full list in tests/README.md.

View the full list of contributors. MIT licensed.

Project details


Download files

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

Source Distribution

curlylint-0.7.0.tar.gz (21.9 kB view hashes)

Uploaded Source

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