시작하기
djLint는 PyPI와 npm에 게시되어 있습니다. PyPI 판은 Python 3.11 이상이 필요하고, npm 판은 자체 Python을 함께 제공합니다. Python 프로젝트에서는 uv나 pip으로, Angular 앱, Eleventy 사이트, Shopify 테마 같은 JavaScript 프로젝트에서는 npm으로 추가하세요.
uv를 사용한다면 프로젝트에 개발 의존성으로 추가합니다.
uv add --dev djlint또는 독립 실행형 도구로 설치합니다.
uv tool install djlintpip install djlintnpm 패키지는 자체 Python을 함께 제공하므로 Node.js 16.9 이상만 있으면 됩니다. Linux(x64, Arm64, ppc64le, s390x, riscv64), macOS(x64, Arm64), Windows(x64, x86, Arm64)용 빌드가 있습니다. Alpine처럼 musl을 쓰는 Linux에서는 x64와 Arm64에서 동작합니다. 프로젝트에 개발 의존성으로 추가합니다.
npm i -D djlint또는 전역으로 설치합니다.
npm i -g djlintpipx로 설치합니다.
pipx install djlintmacOS나 Linux에서는 커뮤니티가 관리하는 Homebrew 포뮬러로 설치합니다.
brew install djlint편집기에서 또는 커밋할 때마다 djLint를 실행하려면 통합과 pre-commit을 참고하세요.
처음 실행하기
섹션 제목: “처음 실행하기”템플릿이 있는 폴더를 djLint에 넘기고 --profile에 템플릿 언어를 지정합니다. 어떤 린터 규칙을 실행하고 템플릿 문법을 어떻게 포맷할지는 프로필이 정합니다. Django 프로젝트라면 다음과 같습니다.
템플릿을 린트합니다(린트가 기본 모드이므로 --lint는 생략해도 됩니다).
djlint templates --lint --profile=django포맷하면 무엇이 바뀌는지 확인합니다. --check를 쓰면 djLint는 diff만 출력하고 파일은 건드리지 않습니다.
djlint templates --check --profile=django파일을 그 자리에서 포맷합니다.
djlint templates --reformat --profile=django모든 프로필은 profile 옵션에 나와 있습니다. 템플릿 언어마다 별도 페이지도 있으며(예: Django, Jinja, Handlebars), 매번 넘기지 않도록 구성 파일에 프로필을 설정하는 방법도 그곳에 나와 있습니다.
uv add --dev로 프로젝트에 추가했다면 djLint는 프로젝트 환경에 있습니다. 명령 앞에 uv run을 붙이세요. 예: uv run djlint templates --lint --profile=django. npm i -D로 추가했다면 대신 npx를 붙이세요. 예: npx djlint templates --lint --profile=django.
경로와 stdin 사용
섹션 제목: “경로와 stdin 사용”djLint는 경로나 stdin으로 입력을 받습니다.
경로를 지정해 실행하는 경우:
djlint /path/to/templates --lint특정 파일을 지정하는 경우:
djlint /path/to/this.mustache --lintstdin을 사용하는 경우:
echo "<div></div>" | djlint -stdin으로 코드를 다시 포맷할 수도 있습니다. 이때는 메시지 없이 포맷된 코드만 출력합니다.
echo "<div></div>" | djlint - --reformat출력:
<div></div>stdin에서 읽을 때는 per-file-ignores와 대조하거나 메시지에 표시할 실제 경로가 없으므로, djLint는 기본값으로 -를 사용합니다. 예를 들어 에디터 통합이 저장할 때 파일 내용을 파이프로 넘기는 경우처럼, 파이프로 넘긴 내용의 실제 경로를 djLint에 알려 주려면 --stdin-filename을 전달하세요.
echo "<div></div>" | djlint - --stdin-filename templates/index.html종료 코드
섹션 제목: “종료 코드”| 코드 | 의미 |
|---|---|
0 |
djLint에 검사를 요청한 모든 대상에 문제가 없거나, 찾은 파일을 구성에 따라 모두 건너뛰었습니다. |
1 |
djLint가 린트 오류나 다시 포맷해야 하는 파일을 찾았습니다. --warn을 쓰면 이를 경고로 보고하고 대신 0으로 종료합니다. |
2 |
djLint가 요청한 대상을 검사하지 못했습니다. 경로에 일치하는 파일이 없거나, 파일을 읽을 수 없거나(UTF-8이 아니거나 권한이 없음), 명령줄이나 구성이 잘못되었거나, djLint가 실패했습니다. |
코드 1만이 djLint가 템플릿을 살펴보고 마음에 들지 않는 점을 발견했다는 뜻입니다. 그래서 파이프라인에서 검사 실패와, 경로가 잘못되었거나 --extension이 더 이상 일치하지 않아 아무것도 검사하지 않은 실행을 구분할 수 있습니다.
djLint가 찾은 뒤 exclude, extend_exclude, use_gitignore, require_pragma에 따라 의도적으로 건너뛴 파일은 오류가 아닙니다. 덕분에 pre-commit에서도 exclude가 동작합니다. 템플릿이 없는 것이 정상인 경로를 파이프라인에서 다룬다면 allow_empty_input으로 코드 2를 끄세요.
djlint /path/to/templates --lint --allow-empty-inputCLI 사용법
섹션 제목: “CLI 사용법”Usage: djlint [OPTIONS] SRC ...
djLint · HTML template linter and formatter.
Modes: --lint Lint the files. This is the default when neither --reformat nor --check is given. --reformat Format the files in place. --check Show what formatting would change, without changing the files. --lsp Run as a language server over stdio, for editors.
Files: -e, --extension EXT Extension of the files to look for in folders. [default: html] --exclude PATHS Regexes of the paths to skip, comma-separated, in place of the default list. --extend-exclude PATHS Regexes of the paths to skip on top of the exclude list, comma-separated. --use-gitignore Also skip the paths that the .gitignore in the project root lists. --require-pragma Only format or lint files whose first line is a djlint:on comment. --stdin-filename PATH Path that stands for stdin in messages, excludes and per-file ignores. [default: -] --allow-empty-input Exit with 0 instead of 2 when the given paths match no files.
Configuration: --profile NAME Template language: html, django, jinja, nunjucks, handlebars, liquid, golang, angular, tera, askama, mako or all. It decides which linter rules run and how template syntax is formatted. Without one, formatting follows all and the linter runs the rules of html. --configuration FILE Global config file: a pyproject.toml, djlint.toml or .djlintrc. The project's own config file wins where both set an option. --prefer-configuration Let the --configuration file win over the project's own config file.
Linter: -i, --ignore CODES Linter codes to skip, comma-separated, for example H014,H017. --include CODES Linter codes to turn on, comma-separated, for example H017. Works for rules that are off by default and for rules the profile leaves out. --per-file-ignores <PATTERN CODES>... Skip linter codes in the files whose path matches a regex. Can be repeated. --rules FILE Custom linter rules, in the .djlint_rules.yaml format.
Output: --quiet Do not print diffs, the progress bar or the summary. --warn Exit with 0 instead of 1 when there are lint errors or files to reformat. --statistics After linting, print how many times each code was found. --linter-output-format FORMAT Layout of each lint message, from {filename}, {line}, {end}, {code}, {message} and {match}. [default: {code} {line} {message} {match}] --github-output / --no-github-output Print results as GitHub Actions annotations. On by default inside GitHub Actions. --sarif Print findings as a SARIF 2.1.0 JSON document, for GitHub code scanning and other tools.
Layout: --indent N Spaces per indent level. [default: 4, or indent_size from .editorconfig] --max-line-length N Join tags onto one line only when the line fits within this length. [default: 120, or max_line_length from .editorconfig] --max-attribute-length N Spread a tag's attributes over lines once they are longer than this. [default: 70] --single-attribute-per-line When an opening tag wraps, put each attribute on its own line. --line-break-after-multiline-tag When a tag's attributes are spread over lines, start its content on a new line. --no-indent-inner-html Do not indent <head> and <body> inside <html>. --keep-br-inline Keep <br> on the line of the text it breaks. --custom-blocks TAGS Names of the custom template blocks to indent, comma-separated, for example toc. --custom-html TAGS Names of the custom HTML tags to indent, comma-separated, for example mjml. --ignore-blocks TAGS Template blocks that do not indent their contents, comma-separated. --blank-line-after-tag TAGS Template tags to follow with a blank line, comma-separated, for example load,extends. --blank-line-before-tag TAGS Template tags to precede with a blank line, comma-separated, for example load,extends. --max-blank-lines N Keep at most this many blank lines in a row. Has no effect with --preserve-blank-lines. [default: 0] --preserve-blank-lines Keep blank lines where possible. --preserve-leading-space Keep the leading spaces of text lines where possible. --no-line-after-yaml Do not add a blank line after YAML front matter.
Rewrites: --close-void-tags Close void tags with a slash, so <img> becomes <img />. --ignore-case Do not fix the case of known HTML tags. --sort-attributes Sort attributes by name, with id first and class second. --sort-load-tags Sort the libraries in {% load %} tags and drop repeated ones. --name-endblocks Name the block in its {% endblock %} when the block spans lines. --quote-style [double|single] Quotes for strings inside template tags. [default: double] --no-entity-formatting Do not rewrite entity references such as © as the characters they name. --no-function-formatting Do not format the arguments of function calls inside {{ }}. --no-set-formatting Do not format the contents of {% set %} tags. --preserve-class-newlines Keep the line breaks in class attributes written across lines. --format-attribute-template-tags Format template syntax inside tag attributes.
CSS and JavaScript: --format-css Also format the contents of <style> tags, with css-beautify. --indent-css N Indent width inside <style> tags, for --format-css. [default: 4] --format-js Also format JavaScript and JSON in <script> tags, with js-beautify. --indent-js N Indent width inside <script> tags, for --format-js. [default: 4] --format-attribute-js-json Also format JavaScript and JSON in attributes such as onclick and x-data. --format-attribute-js-json-pattern REGEX Regex for the names of the attributes to format as JavaScript or JSON. [default: on* event handlers and Alpine, Vue, Angular and Aurelia bindings] --format-attribute-js-json-min-props N Format an object only when it has at least this many properties. [default: 2]
Other: --version Show the version and exit. -h, --help Show this message and exit.