Skip to main content

Django Template Linter

Project description

djlint

Simple Django template linter and reformatter. Ps, reformatting might work with Jinja and Handlebar templates as well! Test it out with the --check flag.

codecov test Codacy Badge Maintainability

Install

pip install djlint

Linter Usage

djlint src # file or path

# with custom extensions
djlint src -e html.dj

Reformatter Usage

Reforamtting is beta. Check the output before applying changes. Please PR any changes needed 👍🏽

djlint src --reformat --check

djlint src --reformat

Optional args

Arg Definition Default
-e, --extension File extension to lint. default=html
--check Checks file formatting
--reformat Reformats html

Linter Rules

Error Codes

Code Meaning
E001 Variables should be wrapped in a single whitespace. Ex: {{ this }}
E002 Double quotes should be used in tags. Ex {% extends "this.html" %}

Warning Codes

Code Meaning
W003 Endblock should have name. Ex: {% endblock body %}.
W004 Status urls should follow {% static path/to/file %} pattern.
W005 Html tag should have lang attribute.
W006 Img tag should have alt, height and width attributes.
W007 <!DOCTYPE ... > should be present before the html tag.
W008 Attributes should be double quoted.
W009 Tag names should be lowercase.
W010 Attribute names should be lowercase.
W011 Attirbute values should be quoted.
W012 There should be no spaces around attribute =.
W013 Line is longer than 99 chars.
W014 More than 2 blank lines.
W015 Follow h tags with a blank line.
W016 Missging title tag in html.

Adding Rules

A good rule consists of

  • Name
  • Code - Codes beginning with "E" signify error, and "W" warning.
  • Message - Message to display when error is found.
  • Patterns - regex expressions that will find the error.

Contributing - Please Help!

Checkout the issue list and help where you can!

Changelog

0.0.8

Added rules.

0.0.1

Initial release.

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

djlint-0.1.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djlint-0.1.1-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file djlint-0.1.1.tar.gz.

File metadata

  • Download URL: djlint-0.1.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for djlint-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b0b754ae3b712ebac7855b98abb0e10582b4f0c88ae119e1a5bc83d7e19b6455
MD5 0e72dfc08d5561081b521a3dfd0ee9ae
BLAKE2b-256 cd582a9400b6fdd3cb60d23653ed8d6f9d5125e4886c52f716c669b978013e46

See more details on using hashes here.

File details

Details for the file djlint-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: djlint-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for djlint-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a3d1747147bee09764e08dd95cd3b782c3be256e35fcb2e380677c58b1c3d07
MD5 6365335e209372936745e2b7b5c7765b
BLAKE2b-256 e5d876aef4cc28b7a6addafb83751e84ca6eb6c205f4409a9f594684cadf3569

See more details on using hashes here.

Supported by

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