From 07a812ee1d6941e500a86825214e301c5ffc388e Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 4 Oct 2021 14:41:07 +0200 Subject: [PATCH] split alt from H006 to H013, closes #47 --- docs/djlint/changelog.rst | 4 ++++ docs/djlint/rules.rst | 4 +++- src/djlint/rules.yaml | 9 +++++++-- tests/test_linter.py | 11 ++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/djlint/changelog.rst b/docs/djlint/changelog.rst index 21fef9b..4ca915b 100644 --- a/docs/djlint/changelog.rst +++ b/docs/djlint/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +Next Release +------------ +- Split ``alt`` requirement from H006 to H013 + 0.5.1 ----- - Added rule H019 diff --git a/docs/djlint/rules.rst b/docs/djlint/rules.rst index 1f6d85b..c1afd04 100644 --- a/docs/djlint/rules.rst +++ b/docs/djlint/rules.rst @@ -19,7 +19,7 @@ Codes +--------+-------------------------------------------------------------------------+ | H005 | Html tag should have lang attribute. | +--------+-------------------------------------------------------------------------+ -| H006 | Img tag should have alt, height and width attributes. | +| H006 | Img tag should have height and width attributes. | +--------+-------------------------------------------------------------------------+ | H007 | should be present before the html tag. | +--------+-------------------------------------------------------------------------+ @@ -33,6 +33,8 @@ Codes +--------+-------------------------------------------------------------------------+ | H012 | There should be no spaces around attribute =. | +--------+-------------------------------------------------------------------------+ +| H013 | Img tag should have alt attributes. | ++--------+-------------------------------------------------------------------------+ | H014 | More than 2 blank lines. | +--------+-------------------------------------------------------------------------+ | H015 | Follow h tags with a line break. | diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index c0a8fe0..606322a 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -52,12 +52,11 @@ - - rule: name: H006 - message: Img tag should have alt, height and width attributes. + message: Img tag should have height and width attributes. flags: re.DOTALL|re.I patterns: - - - - - rule: name: H007 message: should be present before the html tag. @@ -217,6 +216,12 @@ patterns: - <\w+?(?:(?!\{[%|{|#])[^\n|>])*\s+= - <\w+?(?:(?!\{[%|{|#])[^\n|>])*=\s +- rule: + name: H013 + message: Img tag should have an alt attribute. + flags: re.DOTALL|re.I + patterns: + - - rule: name: H014 message: More than 2 blank lines. diff --git a/tests/test_linter.py b/tests/test_linter.py index f2f89e8..16dadc8 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -74,7 +74,7 @@ def test_H005(runner: CliRunner, tmp_file: TextIO) -> None: def test_H006(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file(tmp_file.name, b"") + write_to_file(tmp_file.name, b'test') result = runner.invoke(djlint, [tmp_file.name]) assert result.exit_code == 1 assert "H006 1:" in result.output @@ -156,6 +156,15 @@ def test_H012(runner: CliRunner, tmp_file: TextIO) -> None: assert "H012 1:" not in result.output +def test_H013(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file(tmp_file.name, b'') + result = runner.invoke(djlint, [tmp_file.name]) + assert result.exit_code == 1 + assert "H013 1:" in result.output + print(result.output) + assert "found 1 error" in result.output + + def test_H014(runner: CliRunner, tmp_file: TextIO) -> None: write_to_file(tmp_file.name, b"\n\n\n

") result = runner.invoke(djlint, [tmp_file.name])