Skip to content

Commit

Permalink
feat(linter): added rule H036. Avoid use of <br> tags. Disabled by de…
Browse files Browse the repository at this point in the history
…fault

closes #571
  • Loading branch information
christopherpickering committed Apr 12, 2023
1 parent 1ecb562 commit cefa840
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/docs/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ The first letter of a code follows the pattern:
| T032 | Extra whitespace found in template tags. | ✔️ |
| T034 | Did you intend to use {% raw %}{% ... %} instead of {% ... }%? {% endraw %} | ✔️ |
| H035 | Meta tags should be self closing. | - |
| H036 | Avoid use of <br> tags. | - |

### Adding Rules

Expand Down
1 change: 1 addition & 0 deletions docs/src/fr/docs/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ La première lettre d'un code suit le modèle :
| T032 | Espace blanc supplémentaire trouvé dans les balises du modèle. | ✔️ |
| T034 | Aviez-vous l'intention d'utiliser {% raw %}{% ... %} au lieu de {% ... }% ? {% endraw %} | ✔️ |
| H035 | Meta doivent se fermer d'elles-mêmes. | - |
| H036 | Évitez d'utiliser les balises <br>. | - |

### Ajout de règles

Expand Down
1 change: 1 addition & 0 deletions docs/src/ru/docs/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ djlint . --lint --include=H017,H035 --ignore=H013,H015
| T032 | В тегах шаблона обнаружены лишние пробелы. | ✔️ |
| T034 | Вы намеревались использовать {% raw %}{% ... %} вместо {% ... }%? {% endraw %} | ✔️ |
| H035 | Meta должны быть самозакрывающимися. | - |
| H036 | Избегайте использования тегов <br>. | - |

### Добавление правил

Expand Down
7 changes: 7 additions & 0 deletions src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,10 @@
patterns:
- <(meta)(\b(\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{#[^#]*#}|[^'\">{}])*)(?<!/)>
- <(meta)>
- rule:
name: H036
message: Avoid use of <br> tags.
flags: re.I
default: false
patterns:
- <br\s*?\/?>
21 changes: 21 additions & 0 deletions tests/test_linter/test_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,27 @@ def test_H035(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H035 1:" in result.output


def test_H036(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<br><br ><br />")
result = runner.invoke(djlint, [tmp_file.name])
assert "H036" not in result.output

write_to_file(tmp_file.name, b"<br>")
result = runner.invoke(djlint, [tmp_file.name, "--include", "H036"])
assert result.exit_code == 1
assert "H036" in result.output

write_to_file(tmp_file.name, b"<br />")
result = runner.invoke(djlint, [tmp_file.name, "--include", "H036"])
assert result.exit_code == 1
assert "H036" in result.output

write_to_file(tmp_file.name, b"<br/>")
result = runner.invoke(djlint, [tmp_file.name, "--include", "H036"])
assert result.exit_code == 1
assert "H036" in result.output


def test_rules_not_matched_in_ignored_block(
runner: CliRunner, tmp_file: TextIO
) -> None:
Expand Down

0 comments on commit cefa840

Please sign in to comment.