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_ARGUMENTS: ["--profile", "django"]
to select django format
djlint documentation
- Version in MegaLinter: 1.34.1
- 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_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter 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_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling HTML_DJLINT and its pre/post commands | 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 |
HTML_DJLINT_CLI_EXECUTABLE | Override CLI executable | ['djlint'] |
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 | 125 | ||
c_cpp | Optimized for pure C/C++ projects | 56 | ||
cupcake | MegaLinter for the most commonly used languages | 84 | ||
documentation | MegaLinter for documentation projects | 51 | ||
dotnet | Optimized for C, C++, C# or VB based projects | 63 | ||
dotnetweb | Optimized for C, C++, C# or VB based projects with JS/TS | 72 | ||
go | Optimized for GO based projects | 53 | ||
java | Optimized for JAVA based projects | 54 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 61 | ||
php | Optimized for PHP based projects | 56 | ||
python | Optimized for PYTHON based projects | 64 | ||
ruby | Optimized for RUBY based projects | 52 | ||
rust | Optimized for RUST based projects | 52 | ||
salesforce | Optimized for Salesforce based projects | 56 | ||
swift | Optimized for SWIFT based projects | 52 | ||
terraform | Optimized for TERRAFORM based projects | 56 |
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.
--include TEXT Codes to include. ex: "H014,H017"
--ignore-case Do not fix case on known html tags.
--ignore-blocks TEXT Comma list of template blocks to not indent.
--blank-line-after-tag TEXT Add an additional blank line after {% <tag>
... %} tag groups.
--blank-line-before-tag TEXT Add an additional blank line before {% <tag>
... %} tag groups.
--line-break-after-multiline-tag
Do not condense the content of multi-line
tags into the line of the last attribute.
--custom-blocks TEXT Indent custom template blocks. For example
{% toc %}...{% endtoc %}
--custom-html TEXT Indent custom HTML tags. For example <mjml>
--exclude TEXT Override the default exclude paths.
--extend-exclude TEXT Add additional paths to the default exclude.
--linter-output-format TEXT Customize order of linter output message.
--max-line-length INTEGER Max line length. [default: 120]
--max-attribute-length INTEGER Max attribute length. [default: 70]
--format-attribute-template-tags
Attempt to format template syntax inside of
tag attributes.
--per-file-ignores <TEXT TEXT>...
Ignore linter rules on a per-file basis.
--indent-css INTEGER Set CSS indent level.
--indent-js INTEGER Set JS indent level.
--close-void-tags Add closing mark on known void tags. Ex:
<img> becomse <img />
--no-line-after-yaml Do not add a blank line after yaml front
matter.
--no-function-formatting Do not attempt to format function contents.
--no-set-formatting Do not attempt to format set contents.
--max-blank-lines INTEGER Consolidate blank lines down to x lines.
[default: 0]
-h, --help Show this message and exit.
Installation on mega-linter Docker image
- PIP packages (Python):