You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,9 +23,9 @@
23
23
24
24
## 🤔 For What?
25
25
26
-
Every language in your stack has a formatter and a linter. HTML templates are the exception. Generic HTML tools can't parse `{% %}` and `{{ }}`, and template engines don't care what the markup around them looks like. Templates end up in a tooling blind spot: drifting indentation, mismatched tags and inconsistent spacing that survive every code review.
26
+
Every language in your stack has a formatter and a linter. HTML templates are the exception. Generic HTML tools can't parse `{% %}` and `{{ }}`, and template engines don't care what the markup around them looks like. So indentation drifts, tags go unclosed and spacing goes wherever, and none of it gets caught in review.
27
27
28
-
djLint covers that blind spot. It understands HTML _and_ the template syntax inside it, with profiles for Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go templates and more.
28
+
djLint reads HTML _and_ the template syntax inside it, with profiles for Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go templates and more.
29
29
30
30
Take a template only its author could love:
31
31
@@ -78,9 +78,9 @@ One `djlint --reformat --single-attribute-per-line` later:
78
78
79
79
One command rebuilt the indentation, fixed the tag case, split the long tag into one attribute per line, normalized the template tags and collapsed stray blank lines.
80
80
81
-
And the linter catches what formatting can't fix: orphan tags, missing `alt` attributes, hard-coded URLs and dozens of other checks.
81
+
The linter catches what formatting can't fix: orphan tags, missing `alt` attributes, hard-coded URLs and dozens of other checks.
82
82
83
-
**[Try it on your own templates in the online playground →](https://djlint.com/demo/)**
83
+
You can [try it on your own templates in the online playground](https://djlint.com/demo/).
84
84
85
85
## ✨ How?
86
86
@@ -189,7 +189,7 @@ uv sync
189
189
uv run pytest
190
190
```
191
191
192
-
## 🏃 Other Tools Of Note
192
+
## 🏃 Other tools of note
193
193
194
194
- [djade](https://github.com/adamchainz/djade) A fast Django template formatter that formats template syntax whilst leaving HTML as-is, and applies fixes for older Django versions.
195
195
- [djangofmt](https://github.com/UnknownPlatypus/djangofmt) A fast, HTML-aware Django/Jinja template formatter written in Rust that formats HTML and template syntax together.
|`1`| djLint found linting errors, or files that need reformatting. `--warn` reports these as warnings and exits `0` instead. |
99
99
|`2`| djLint did not check what you asked it to: the paths matched no files, the command line or config was invalid, or djLint failed. |
100
100
101
-
Only code `1` means "djLint looked at your templates and did not like what it
102
-
found". Code `2` always means the run itself did not deliver, so a pipeline can
103
-
treat the two differently instead of guessing.
104
-
105
-
That covers the "djLint checked nothing" case - a wrong path, an `--extension`
106
-
that no longer matches, or templates that have moved - a run that would
107
-
otherwise pass silently while checking none of your templates.
108
-
109
-
Files that djLint _did_ find and then skipped on purpose - through `exclude`,
110
-
`extend_exclude`, `use_gitignore` or `require_pragma` - are not an error. That
111
-
run exits `0`, because the configuration did exactly what it was told to. This
112
-
is what lets `exclude` work under pre-commit, which passes the names of your
113
-
staged files whether or not you want djLint to look at them.
114
-
115
-
If a path that legitimately has no templates is normal for your pipeline, turn
116
-
code `2` off with `allow_empty_input`:
101
+
Only code `1` means djLint looked at your templates and did not like what it found. Code `2` always means the run itself did not deliver, so a pipeline can treat the two differently instead of guessing.
102
+
103
+
Code `2` is what catches a run that checked nothing at all: a wrong path, an `--extension` that no longer matches, or templates that have moved. Without it such a run passes silently, having looked at none of your templates.
104
+
105
+
Files that djLint _did_ find and then skipped on purpose, through `exclude`, `extend_exclude`, `use_gitignore` or `require_pragma`, are not an error. That run exits `0`, because the configuration did exactly what it was told to. It is also what lets `exclude` work under pre-commit, which passes the names of your staged files whether or not you want djLint to look at them.
106
+
107
+
If a path that legitimately has no templates is normal for your pipeline, turn code `2` off with `allow_empty_input`:
Copy file name to clipboardExpand all lines: docs/src/docs/linter.md
+6-12Lines changed: 6 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -879,7 +879,7 @@ Do:
879
879
880
880
`Avoid use of <br> tags.`
881
881
882
-
`<br>` encodes presentation in markup: using it for spacing or to fake paragraphs breaks text reflow at narrow widths and degrades accessibility, since screen readers announce forced breaks instead of a natural pause between blocks. Separate thoughts belong in separate block elements, and vertical spacing belongs to CSS margins. Note that `<br>` is legitimate where the line break is part of the content itself (postal addresses, poems, lyrics), and this rule cannot tell those apart from presentational use: it flags every `<br>`. Leave it disabled if your templates render such content.
882
+
`<br>` encodes presentation in markup: using it for spacing or to fake paragraphs breaks text reflow at narrow widths and degrades accessibility, since screen readers announce forced breaks instead of a natural pause between blocks. Use separate block elements for separate thoughts, and CSS margins for the spacing between them. `<br>` is legitimate where the line break is part of the content itself (postal addresses, poems, lyrics), but this rule cannot tell those apart from presentational use and flags every `<br>`, so leave it disabled if your templates render such content.
883
883
884
884
Off by default; enable with `--include=H036`.
885
885
@@ -1047,9 +1047,7 @@ Please include a test to validate the rule.
1047
1047
1048
1048
## Custom Rules
1049
1049
1050
-
You can add custom rules just for your project by creating a `.djlint_rules.yaml` alongside
1051
-
your `pyproject.toml`. Rules can be added to this files and djLint will pick them up.
1052
-
A rules file in another location can be given with the `--rules` CLI option.
1050
+
You can add custom rules just for your project by creating a `.djlint_rules.yaml` alongside your `pyproject.toml`. Rules can be added to this files and djLint will pick them up. A rules file in another location can be given with the `--rules` CLI option.
1053
1051
1054
1052
### Pattern Rules
1055
1053
@@ -1075,20 +1073,16 @@ You can add rules that import and execute a custom python function:
1075
1073
python_module: your_package.your_module
1076
1074
```
1077
1075
1078
-
The specified `python_module` must contain a `run()` function that will be executed on
1079
-
every checked file. It must accept the following arguments:
1076
+
The specified `python_module` must contain a `run()` function that will be executed on every checked file. It must accept the following arguments:
1080
1077
1081
1078
::: content
1082
1079
1083
-
- `rule`: The dict that represent your rule in `.djlint_rules.yaml`. You will typically
1084
-
use this variable to access the rule name and message.
1080
+
- `rule`: The dict that represent your rule in `.djlint_rules.yaml`. You will typically use this variable to access the rule name and message.
1085
1081
- `config`: The DJLint configuration object.
1086
1082
- `html`: The full html content of the file.
1087
1083
- `filepath`: Path to the file that we are currently checking.
1088
-
- `line_ends`: List of line `start` and `end` character position that you can use with
1089
-
`djlint.lint.get_line()`to get line numbers from a character position. See the example.
1090
-
- `*args, **kwargs`: We might add other arguments in the future, so you should include
1091
-
those two arguments to reduce the risk of failure on djLint upgrade.
1084
+
- `line_ends`: List of line `start` and `end` character position that you can use with `djlint.lint.get_line()` to get line numbers from a character position. See the example.
1085
+
- `*args, **kwargs`: We might add other arguments in the future, so you should include those two arguments to reduce the risk of failure on djLint upgrade.
1092
1086
:::
1093
1087
1094
1088
It must return a list of dict, one for each errors, with the following keys:
0 commit comments