Skip to content

djlint

GitHub last commit

DjLint can analyse multiple formats of HTML:

  • html (default)
  • django
  • jinja
  • nunjucks (for nunjucks and twig)
  • handlebars (for handlebars and mustache)
  • golang
  • angular

For example, define HTML_DJLINT_HTMLHINT_ARGUMENTS: ["--profile", "django"] to select django format

djlint documentation

djlint - GitHub

Configuration in MegaLinter

Variable Description Default value
HTML_DJLINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
HTML_DJLINT_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
HTML_DJLINT_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
HTML_DJLINT_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
list_of_files
HTML_DJLINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".html", ".htm"]
HTML_DJLINT_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
HTML_DJLINT_PRE_COMMANDS List of bash commands to run before the linter None
HTML_DJLINT_POST_COMMANDS List of bash commands to run after the linter None
HTML_DJLINT_DISABLE_ERRORS Run linter but consider errors as warnings false
HTML_DJLINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use djlint in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Sublime Text SublimeLinter-contrib-djlint Visit Web Site
Visual Studio Code djlint-vscode Install in VsCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 107 Docker Image Size (tag) Docker Pulls
documentation MegaLinter for documentation projects 46 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 55 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 48 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 49 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 55 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 50 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 56 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 47 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 47 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 49 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 47 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 52 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .html, .htm

How the linting is performed

  • djlint is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

djlint myfile1.html myfile2.html

Help content

Usage: djlint [OPTIONS] SRC ...

  djLint ยท HTML template linter and formatter.

Options:
  --version                 Show the version and exit.
  -e, --extension TEXT      File extension to check [default: html]
  -i, --ignore TEXT         Codes to ignore. ex: "H014,H017"
  --reformat                Reformat the file(s).
  --check                   Check formatting on the file(s).
  --indent INTEGER          Indent spacing. [default: 4]
  --quiet                   Do not print diff when reformatting.
  --profile TEXT            Enable defaults by template language. ops: django,
                            jinja, nunjucks, handlebars, golang, angular, html
                            [default: html]
  --require-pragma          Only format or lint files that starts with a
                            comment with the text 'djlint:on'
  --lint                    Lint for common issues. [default option]
  --use-gitignore           Use .gitignore file to extend excludes.
  --warn                    Return errors as warnings.
  --preserve-leading-space  Attempt to preserve leading space on text.
  --preserve-blank-lines    Attempt to preserve blank lines.
  --format-css              Also format contents of <style> tags.
  --format-js               Also format contents of <script> tags.
  --configuration PATH      Path to global configuration file in .djlintrc
                            format
  --statistics              Count the number of occurrences of each
                            error/warning code.
  -h, --help                Show this message and exit.

Installation on mega-linter Docker image

  • PIP packages (Python):