Skip to content

Commit

Permalink
feat(linter): added rule H037
Browse files Browse the repository at this point in the history
checks for duplicate attributes on html tags.
  • Loading branch information
christopherpickering committed May 8, 2023
1 parent 13d0d4f commit 6048c46
Show file tree
Hide file tree
Showing 5 changed files with 23 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 @@ -76,6 +76,7 @@ This can also be done through the [{{ "configuration" | i18n }}]({{ "lang_code_u
| T034 | Did you intend to use {% raw %}{% ... %} instead of {% ... }%? {% endraw %} | ✔️ |
| H035 | Meta tags should be self closing. | - |
| H036 | Avoid use of <br> tags. | - |
| H037 | Duplicate attribute found. | ✔️ |

### Code Patterns

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 @@ -76,6 +76,7 @@ Cela peut également se faire par l'intermédiaire de l'option [{{ "configuratio
| 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>. | - |
| H037 | Attribut en double trouvé. | ✔️ |

### Modèles de code

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 @@ -76,6 +76,7 @@ djlint . --lint --include=H017,H035 --ignore=H013,H015
| T034 | Вы намеревались использовать {% raw %}{% ... %} вместо {% ... }%? {% endraw %} | ✔️ |
| H035 | Meta должны быть самозакрывающимися. | - |
| H036 | Избегайте использования тегов <br>. | - |
| H037 | Найдено дублирование атрибута. | ✔️ |

### Кодовые шаблоны

Expand Down
6 changes: 6 additions & 0 deletions src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,9 @@
default: false
patterns:
- <br\s*?\/?>
- rule:
name: H037
message: Duplicate attribute found.
flags: re.I
patterns:
- <\w[^>]*?\s([a-z][a-z-]*?)(?==.+?\1=[^>]*?>)
14 changes: 14 additions & 0 deletions tests/test_linter/test_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,20 @@ def test_H036(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H036" in result.output


def test_H037(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<br class='a' id=asdf class='b'>")
result = runner.invoke(djlint, [tmp_file.name])
assert "H037" in result.output

write_to_file(tmp_file.name, b"<div data-class='a' id=asdf data-class='b'>")
result = runner.invoke(djlint, [tmp_file.name])
assert "H037" in result.output

write_to_file(tmp_file.name, b"<div data-class='a' data=asdf class='b'>")
result = runner.invoke(djlint, [tmp_file.name])
assert "H037" not in result.output


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

0 comments on commit 6048c46

Please sign in to comment.