設定
設定は、プロジェクトの pyproject.toml、djlint.toml か .djlint.toml、または .djlintrc に書きます。コマンドラインオプションは設定ファイルより優先されますが、フラグはオプションをオンにすることしかできないため、設定ファイルでオンにしたスイッチをオフにはできません。--prefer-configuration を指定しない限り、プロジェクトの設定は --configuration で指定したグローバル設定ファイルよりも優先されます。
djLint は、最初にチェックするパス(- の場合は --stdin-filename のフォルダー、指定がなければカレントディレクトリ)から上に向かってこれらのファイルを探します。djlint.toml、.djlint.toml、.djlintrc、.djlint_rules.yaml、または [tool.djlint] のある pyproject.toml がある最初のフォルダーで探すのをやめ、リポジトリのルート(.git フォルダーまたはファイル、あるいは .hg フォルダーのあるフォルダー)より上には進みません。djLint の設定がない pyproject.toml では止まらないため、自分の pyproject.toml を持つモノレポ内のパッケージにもリポジトリの設定が適用されます。読み込むのは止まったフォルダーだけで、pyproject.toml の [tool.djlint](中に設定があるとき)、なければ djlint.toml か .djlint.toml、それもなければ .djlintrc です。同じフォルダーにあって読み込まれないファイルについては警告が出ます。
コマンドラインでも設定でも indent や max_line_length が指定されていない場合、djLint はエディターと同じように .editorconfig ファイルから indent_size や max_line_length を読み取ります。値はファイルごとにそのパスで決まり、いちばん近い .editorconfig が優先され、上にあるものが足りない値を補います。探すのは root = true のあるファイルかプロジェクトのルートまでです。
pyproject.toml の形式は toml です。
[tool.djlint]profile = "django"ignore = ["H014", "H015"]djlint.toml と .djlint.toml の形式は toml です。
profile = "django"ignore = ["H014", "H015"].djlintrc の形式は json です。
{ "profile": "django", "ignore": ["H014", "H015"] }ignore のように複数の値を取るオプションにはリストを指定します。"H014,H015" のようなカンマ区切りの文字列も使え、djLint 1.41 より前ではこちらが必要です。
バージョン 1.51 からは、知らない設定やルールコードがあると、いちばん近い既知のものを添えて警告します。
見つかりませんでした。別のキーワードで検索してください。
allow_empty_input
デフォルト: false
指定したパスに一致するファイルがまったくない場合に、2 ではなく 0 で終了します。見つかったうえで exclude、extend_exclude、use_gitignore、require_pragma によってスキップされたファイルは、もともと 0 で終了します。
allow_empty_input=trueallow_empty_input=true"allow_empty_input": true--allow-empty-inputblank_line_after_tag
デフォルト: なし
後ろに空行を入れるテンプレートタグ。例:load、extends。このタグが連続する場合は最後のタグの後にだけ空行が入り、ブロックの末尾には空行は追加されません。
blank_line_after_tag=["load", "extends", "include"]blank_line_after_tag=["load", "extends", "include"]"blank_line_after_tag": ["load", "extends", "include"]--blank-line-after-tag "load,extends,include"blank_line_before_tag
デフォルト: なし
前に空行を入れるテンプレートタグ。例:load、extends。このタグが連続する場合は最初のタグの前にだけ空行が入り、ファイルやブロックの先頭には空行は追加されません。
blank_line_before_tag=["load", "extends", "include"]blank_line_before_tag=["load", "extends", "include"]"blank_line_before_tag": ["load", "extends", "include"]--blank-line-before-tag "load,extends,include"close_void_tags
デフォルト: false
既知の空要素のタグをスラッシュで閉じ、<img> を <img /> にします。このオプションを指定すると、逆を求める H018 は報告されません。
close_void_tags=trueclose_void_tags=true"close_void_tags": true--close-void-tagsconfiguration
ホームフォルダーにあるものなど、グローバルな設定ファイル(pyproject.toml、djlint.toml、.djlintrc)。両者が同じオプションを設定している場合、prefer_configuration が有効でない限り、プロジェクト自身の設定ファイルが優先されます。
--configuration ~/.djlintrccustom_blocks
デフォルト: なし
インデントするカスタムのテンプレートブロックの名前。例:{% toc %}...{% endtoc %} なら toc。
custom_blocks=["toc", "example"]custom_blocks=["toc", "example"]"custom_blocks": ["toc", "example"]--custom-blocks "toc,example"custom_html
デフォルト: なし
インデントするカスタムの HTML タグの名前。例:mjml、simple-greeting。mj-\w+ のように正規表現も使えます。
custom_html=["mjml", "simple-greeting", 'mj-\w+']custom_html=["mjml", "simple-greeting", 'mj-\w+']"custom_html": ["mjml", "simple-greeting", "mj-\\w+"]--custom-html "mjml,simple-greeting,mj-\w+"exclude
デフォルト: "__pypackages__,
スキップするパス。デフォルトのリストの代わりに使われます。各エントリーは正規表現で、プロジェクトのルートまたはチェックするフォルダーからの相対パスに含まれるフォルダー名やファイル名の全体(vendor や templates/legacy など)と照合されます。そのため *.min.html は .*\.min\.html と書きます。
exclude=[".venv", "venv", "build"]exclude=[".venv", "venv", "build"]"exclude": [".venv", "venv", "build"]--exclude ".venv,venv,build"extend_exclude
デフォルト: なし
スキップするパス。exclude に加えて、exclude が設定されていない場合はデフォルトのリストに加えて使われます。exclude と同じく正規表現で書きます。
extend_exclude=[".custom"]extend_exclude=[".custom"]"extend_exclude": [".custom"]--extend-exclude ".custom"extension
デフォルト: "html"
フォルダー内で探すファイルの拡張子。指定できる拡張子は 1 つだけです。名前で指定したファイルは、拡張子に関係なくチェックされます。
extension="html.dj"extension="html.dj""extension": "html.dj"--extension "html.dj"# or-e "html.dj"files
デフォルト: なし
コマンドラインのパスの代わりにチェックするパス。この場合、コマンドラインのパスは、標準入力を使うときと同じく - にする必要があります。--stdin-filename を指定すると、- はどの場合でも標準入力を意味します。
[tool.djlint]files=["index.html"]files=["index.html"]"files": [ "index.html"]index.htmlformat_attribute_js_json
デフォルト: false
onclick や x-data など、format_attribute_js_json_pattern で指定した属性内の JavaScript と JSON もフォーマットします。プロパティの数が format_attribute_js_json_min_props より少ないオブジェクトは 1 行のまま残ります。
format_attribute_js_json=trueformat_attribute_js_json=true"format_attribute_js_json": true--format-attribute-js-jsonformat_attribute_js_json_min_props
デフォルト: 2
プロパティがこの数以上あるオブジェクトだけをフォーマットします。これより少ないオブジェクトは 1 行のまま残ります。
format_attribute_js_json_min_props=3format_attribute_js_json_min_props=3"format_attribute_js_json_min_props": 3--format-attribute-js-json-min-props 3format_attribute_js_json_pattern
デフォルト: "^(?:on[a-z]+|
JavaScript または JSON としてフォーマットする属性の名前に一致する正規表現。デフォルトでは、on* のイベントハンドラーと、Alpine、Vue、Angular、Aurelia のバインディングが対象になります。
format_attribute_js_json_pattern="^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"format_attribute_js_json_pattern="^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$""format_attribute_js_json_pattern": "^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"--format-attribute-js-json-pattern "^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"format_attribute_template_tags
デフォルト: false
タグの属性内のテンプレート構文をフォーマットします。
format_attribute_template_tags=trueformat_attribute_template_tags=true"format_attribute_template_tags": true--format-attribute-template-tagsformat_css
デフォルト: false
css-beautify を使って <style> タグの中身もフォーマットします。その中のテンプレート構文は完全にはサポートされていません。
css テーブルの indent_size、またはコマンドラインの --indent-css で、<style> タグ内のインデントを設定します。デフォルトは 4 です。このテーブルでは、ほかの css-beautify のオプションも使えます。
[tool.djlint]format_css=true
[tool.djlint.css]indent_size=5format_css=true
[css]indent_size=5"format_css": true,"css": { "indent_size": 5 }--format-css --indent-css 5format_js
デフォルト: false
js-beautify を使って <script> タグ内の JavaScript と JSON もフォーマットします。type が JavaScript でも JSON でもないスクリプト(text/template のクライアントサイドテンプレートなど)は、書かれたまま残ります。その中のテンプレート構文は完全にはサポートされていません。
js テーブルの indent_size、またはコマンドラインの --indent-js で、<script> タグ内のインデントを設定します。デフォルトは 4 です。このテーブルでは、ほかの js-beautify のオプションも使えます。
[tool.djlint]format_js=true
[tool.djlint.js]indent_size=5format_js=true
[js]indent_size=5"format_js": true,"js": { "indent_size": 5 }--format-js --indent-js 5github_output
デフォルト: なし
結果を GitHub Actions のアノテーションとして出力します。GitHub Actions 内ではデフォルトで有効で、--no-github-output で無効にできます。GitHub Actions を参照してください。
--github-outputignore
デフォルト: なし
スキップするリンターのコード。
ignore=["H014", "H015"]ignore=["H014", "H015"]"ignore": ["H014", "H015"]--ignore "H014,H015"ignore_blocks
デフォルト: なし
中身にインデントを加えないテンプレートブロック。子要素はブロックの兄弟要素として扱われ、それに応じてインデントされます。
ignore_blocks=["raw", "example"]ignore_blocks=["raw", "example"]"ignore_blocks": ["raw", "example"]--ignore-blocks "raw,example"ignore_case
デフォルト: false
既知の HTML タグの大文字・小文字を修正しません。このオプションを指定すると、H009 と H010 は報告されません。
[tool.djlint]ignore_case=trueignore_case=true"ignore_case": true--ignore-caseinclude
デフォルト: なし
有効にするリンターのコード。デフォルトで無効のルールや、プロファイルに含まれないルールも有効になります。
include=["H014", "H015"]include=["H014", "H015"]"include": ["H014", "H015"]--include "H014,H015"indent
デフォルト: 4
インデント 1 段あたりのスペース数。設定されていない場合、.editorconfig でそのファイルに indent_size が指定されていれば、djLint はそれを使います。
indent=3indent=3"indent": 3--indent 3keep_br_inline
デフォルト: false
<br> を独立した行に置かず、改行するテキストと同じ行に残します。直前のコンテンツの下に罫線として表示される <hr> には影響しません。
keep_br_inline=truekeep_br_inline=true"keep_br_inline": true--keep-br-inlineline_break_after_multiline_tag
デフォルト: false
タグの属性が複数行にわたるとき、その中身を新しい行から始めます。
line_break_after_multiline_tag=trueline_break_after_multiline_tag=true"line_break_after_multiline_tag": true--line-break-after-multiline-taglinter_output_format
デフォルト: "{code} {line} {message} {match}"
各リントメッセージのレイアウト。{filename}、{line}、{end}、{code}、{message}、{match} を組み合わせて指定します。{filename} を含めない場合、出力はファイルごとにグループ化され、各グループにヘッダーが付きます。
linter_output_format="{filename}:{line}: {code} {message} {match}"linter_output_format="{filename}:{line}: {code} {message} {match}""linter_output_format": "{filename}:{line}: {code} {message} {match}"--linter-output-format "{filename}:{line}: {code} {message} {match}"max_attribute_length
デフォルト: 70
タグの属性がこの長さを超えると、フォーマッターは属性を複数行に分けます。
max_attribute_length=10max_attribute_length=10"max_attribute_length": 10--max-attribute-length 10max_blank_lines
デフォルト: 0
連続する空行を最大でこの行数まで残します。0 にすると空行は削除されます。preserve_blank_lines を有効にすると、この設定は効きません。
max_blank_lines=5max_blank_lines=5"max_blank_lines": 5--max-blank-lines 5max_line_length
デフォルト: 120
フォーマッターは、行がこの長さに収まる場合に限り、一部の HTML タグとテンプレートタグを 1 行にまとめます。設定されていない場合、.editorconfig でそのファイルに max_line_length が指定されていれば、djLint はそれを使います。
max_line_length=100max_line_length=100"max_line_length": 100--max-line-length 100name_endblocks
デフォルト: false
複数行にわたって書かれたブロックについて、それを閉じる {% endblock %} にブロックの名前を書き込みます。これは T003 が求めていることです。
name_endblocks=truename_endblocks=true"name_endblocks": true--name-endblocksno_entity_formatting
デフォルト: false
実体参照を、それが表す文字に書き換えません。たとえば © は © にならず、書かれたまま残ります。構文上の意味を持つ実体参照と目に見えない文字の実体参照は、どちらにしても書き換えられません。このオプションを指定しても H023 は実体参照を報告します。実体参照を残すには、H023 を ignore に追加してください。
no_entity_formatting=trueno_entity_formatting=true"no_entity_formatting": true--no-entity-formattingno_function_formatting
デフォルト: false
{{ }} の中にある関数呼び出しの引数をフォーマットしません。
no_function_formatting=trueno_function_formatting=true"no_function_formatting": true--no-function-formattingno_indent_inner_html
デフォルト: false
<head> と <body> を <html> の中でインデントしません。VS Code 組み込みの HTML フォーマッターは、ドキュメントをこのようにレイアウトします。
no_indent_inner_html=trueno_indent_inner_html=true"no_indent_inner_html": true--no-indent-inner-htmlno_line_after_yaml
デフォルト: false
YAML のフロントマターの後に空行を追加しません。
no_line_after_yaml=trueno_line_after_yaml=true"no_line_after_yaml": true--no-line-after-yamlno_set_formatting
デフォルト: false
{% set %} タグの中身をフォーマットしません。
no_set_formatting=trueno_set_formatting=true"no_set_formatting": true--no-set-formattingper_file_ignores
デフォルト: なし
パスが正規表現に一致するファイルでスキップするリンターのコード。設定ファイルでのキーは、ハイフン区切りの per-file-ignores です。
[tool.djlint.per-file-ignores]"file.html"= "H026,H025""file_two.html"="H001"[per-file-ignores]"file.html"= "H026,H025""file_two.html"="H001""per-file-ignores": { "file.html": "H026,H025", "file_two.html":"H001" }--per-file-ignores "file.html" "H026,H025" --per-file-ignores "file_two.html" "H001"prefer_configuration
デフォルト: false
--configuration で指定したファイルが、プロジェクト自身の設定ファイルを上書きするようにします。デフォルトでは、両者が同じオプションを設定している場合、プロジェクトの設定ファイルが優先されます。設定ファイル自体の読み込み方を決めるものなので、コマンドラインでのみ指定できます。
--prefer-configurationpreserve_blank_lines
デフォルト: false
可能な場合、空行を保持します。空行が意図的な、HTML 以外のテンプレートに便利です。
preserve_blank_lines=truepreserve_blank_lines=true"preserve_blank_lines": true--preserve-blank-linespreserve_class_newlines
デフォルト: false
複数行にわたって書かれた class 属性の中の改行を保持します。
preserve_class_newlines=truepreserve_class_newlines=true"preserve_class_newlines": true--preserve-class-newlinespreserve_leading_space
デフォルト: false
可能な場合、テキスト行の先頭のスペースを保持します。テキストのインデントが意図的な、HTML 以外のテンプレートに便利です。
preserve_leading_space=truepreserve_leading_space=true"preserve_leading_space": true--preserve-leading-spaceprofile
デフォルト: なし
テンプレート言語。どのリンターのルールを実行するか、テンプレート構文をどうフォーマットするかを決めます。たとえば handlebars では、{{#if}} タグの内側にスペースを入れません。
プロファイルを設定しない場合、djLint は all と同じくすべてのテンプレート言語の構文をフォーマットし、html のルールでリントします。
選択肢:
- html
- django
- jinja
- nunjucks(nunjucks と twig 用)
- handlebars(handlebars と mustache 用)
- liquid(shopify、jekyll、eleventy)
- golang(go テンプレート。hugo、helm)
- angular
- tera(zola にも対応。minijinja には jinja を使用)
- askama(rust の jinja 形式のテンプレート。rust の式は再フォーマットされません)
- mako(制御行と
##コメントはそのまま残ります) - all(すべてのテンプレート言語をまとめて扱う)
profile="django"profile="django""profile": "django"--profile "django"quiet
デフォルト: false
差分、進行状況バー、集計を表示しません。
quiet=truequiet=true"quiet": true--quietquote_style
デフォルト: "double"
テンプレートタグ内の文字列に使う引用符で、double または single のいずれかです。T002 も同じ引用符を求め、フォーマッターは {% if x == "a" %} のような条件の中でもこの引用符を使うため、1 つのファイルで同じ文字列が 2 通りの書き方になることはありません。HTML 属性の引用符は H008 に任されます。
quote_style="single"quote_style="single""quote_style": "single"--quote-style singlerequire_pragma
デフォルト: false
djlint:on コメントで始まるファイルだけをフォーマットまたはリントします。コメントは、HTML コメントか、profile のテンプレート言語のコメントにできます。プロファイルがない場合は、どのテンプレート言語のコメントでもかまいません。
<!-- djlint:on -->{# djlint:on #}{% comment %} djlint:on {% endcomment %}{{ /* djlint:on */ }}{{!-- djlint:on --}}require_pragma=truerequire_pragma=true"require_pragma": true--require-pragmarules
.djlint_rules.yaml 形式のカスタムルールファイル。プロジェクトのルートにあるものの代わりに読み込まれます。
--rules ../shared/.djlint_rules.yamlsarif
デフォルト: false
検出結果を SARIF 2.1.0 ドキュメントとして出力します。GitHub のコードスキャンやその他のツール向けです。GitHub Actions を参照してください。
--sarifsingle_attribute_per_line
デフォルト: false
開始タグが折り返されるとき、タグ名、各属性、閉じかっこをそれぞれ別の行に置きます。
single_attribute_per_line=truesingle_attribute_per_line=true"single_attribute_per_line": true--single-attribute-per-linesort_attributes
デフォルト: false
属性を名前順に並べ替え、id を最初に、class を 2 番目に置きます。属性がテンプレートタグで制御されているタグは、書かれた順序のままになります。属性を分岐の外に移すとページが変わってしまうためです。
sort_attributes=truesort_attributes=true"sort_attributes": true--sort-attributessort_load_tags
デフォルト: false
{% load %} タグ内のライブラリを並べ替え、2 回書かれたものを削除します。たとえば {% load static i18n %} は {% load i18n static %} になります。{% load a b from library %} では、from の前の名前が並べ替えられます。2 つのライブラリが同じ名前のタグやフィルターを定義している場合は最後に読み込まれたものが優先されるため、並べ替えによってテンプレートが使うものが変わることがあります。
sort_load_tags=truesort_load_tags=true"sort_load_tags": true--sort-load-tagsstatistics
デフォルト: false
リントの後に、各コードが見つかった回数を表示します。
--statisticsstdin_filename
デフォルト: "-"
メッセージと、exclude や per-file-ignores との照合で、標準入力を表すパス。
--stdin-filename templates/index.htmluse_gitignore
デフォルト: false
プロジェクトのルートにある .gitignore に書かれたパスもスキップします。
use_gitignore=trueuse_gitignore=true"use_gitignore": true--use-gitignoreversion
バージョンを表示して終了します。
--versionwarn
デフォルト: false
リントのエラーや再フォーマットが必要なファイルがあっても、終了コード 1 ではなく 0 で終了します。
--warn