djlint
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
- Version in MegaLinter: 1.19.16
- Visit Official Web Site
- See How to configure djlint rules
- See How to disable djlint rules in files
- See Index of problems detected by djlint
Configuration in MegaLinter
- Enable djlint by adding
HTML_DJLINT
in ENABLE_LINTERS variable - Disable djlint by adding
HTML_DJLINT
in DISABLE_LINTERS variable
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 filesEx: [".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 |
MegaLinter Flavours
This linter is available in the following flavours
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
all | Default MegaLinter Flavor | 114 | ||
cupcake | MegaLinter for the most commonly used languages | 82 | ||
documentation | MegaLinter for documentation projects | 48 | ||
dotnet | Optimized for C, C++, C# or VB based projects | 60 | ||
go | Optimized for GO based projects | 50 | ||
java | Optimized for JAVA based projects | 51 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 57 | ||
php | Optimized for PHP based projects | 51 | ||
python | Optimized for PYTHON based projects | 59 | ||
ruby | Optimized for RUBY based projects | 48 | ||
rust | Optimized for RUST based projects | 48 | ||
salesforce | Optimized for Salesforce based projects | 51 | ||
swift | Optimized for SWIFT based projects | 48 | ||
terraform | Optimized for TERRAFORM based projects | 53 |
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):