From f29cb66a36e274ee5bb972d0e3a6438bc99335ba Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 2 Aug 2022 16:49:20 +0000 Subject: [PATCH 1/3] chore(release): 1.9.4 [skip ci] ## [1.9.4](https://github.com/Riverside-Healthcare/djLint/compare/v1.9.3...v1.9.4) (2022-08-02) ### Bug Fixes * **requirements:** removed optional deps from requirements section. Cleaned up tox ([237e844](https://github.com/Riverside-Healthcare/djLint/commit/237e84464cbea4a6de23779077cdb0d1e4abf5dd)), closes [#322](https://github.com/Riverside-Healthcare/djLint/issues/322) --- package.json | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8a9b338..9eed4ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "djlint", - "version": "1.9.3", + "version": "1.9.4", "description": "HTML Template Linter and Formatter", "main": "./bin/index.js", "directories": { diff --git a/pyproject.toml b/pyproject.toml index ba46f23..4ecf3e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name="djlint" -version="1.9.3" +version="1.9.4" description="HTML Template Linter and Formatter" license="GPL-3.0-or-later" authors=["Christopher Pickering "] From a3ccc1974c4dbb35043e20b714171a60ac0f77bb Mon Sep 17 00:00:00 2001 From: Ruan Bahia Date: Thu, 4 Aug 2022 23:48:38 -0300 Subject: [PATCH 2/3] fix(formatter): fix IndexError while adding indentation to attributes solves issue with boolean attributes at the start of tags. closes #290 --- src/djlint/formatter/attributes.py | 4 +- tests/test_html/test_attributes.py | 63 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/djlint/formatter/attributes.py b/src/djlint/formatter/attributes.py index eb962b2..7408151 100644 --- a/src/djlint/formatter/attributes.py +++ b/src/djlint/formatter/attributes.py @@ -56,7 +56,9 @@ def format_template_tags(config: Config, attributes: str) -> str: attributes.splitlines()[0].strip(), ) ) - )[-1] + ) + if start_test: + start_test = start_test[-1] base_indent = len(attr_name.group()) diff --git a/tests/test_html/test_attributes.py b/tests/test_html/test_attributes.py index 030df37..9f6aeac 100644 --- a/tests/test_html/test_attributes.py +++ b/tests/test_html/test_attributes.py @@ -6,6 +6,8 @@ run:: --cov-report xml:coverage.xml --cov-report term-missing pytest tests/test_html/test_attributes.py::test_long_attributes + pytest tests/test_html/test_attributes.py::test_ignored_attributes + pytest tests/test_html/test_attributes.py::test_boolean_attributes Some tests may be from prettier.io's html test suite. @@ -118,6 +120,67 @@ def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None: ) +def test_boolean_attributes(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""""", + ) + + # boolean attributes after tag must be reformatted correctly + assert output.exit_code == 1 + print(output.text) + assert ( + output.text + == """ +""" + ) + + # boolean attributes after tag with long attributes must be reformatted correctly + output = reformat( + tmp_file, + runner, + b"""""", + ) + assert output.exit_code == 1 + print(output.text) + assert ( + output.text + == """ +""" + ) + + # boolean attributes after tag are accepted + output = reformat( + tmp_file, + runner, + b"""""" + ) + assert output.exit_code == 0 + # def test_attributes(runner: CliRunner, tmp_file: TextIO) -> None: # html_in = ( From 183c4fc8f03b72f59da006f13aaa855c9778f404 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Tue, 16 Aug 2022 07:42:44 -0500 Subject: [PATCH 3/3] fixed lint --- src/djlint/formatter/attributes.py | 27 ++++++++++++--------------- tests/test_html/test_attributes.py | 11 ++++++----- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/djlint/formatter/attributes.py b/src/djlint/formatter/attributes.py index 7408151..596ed28 100644 --- a/src/djlint/formatter/attributes.py +++ b/src/djlint/formatter/attributes.py @@ -41,24 +41,21 @@ def format_template_tags(config: Config, attributes: str) -> str: ) )[-1] - start_test = ( - list( - re.finditer( - re.compile( - r"^.*?(?=" + config.template_indent + r")", re.I | re.X | re.M - ), - attributes.splitlines()[0].strip(), - ) + start_test_list = list( + re.finditer( + re.compile( + r"^.*?(?=" + config.template_indent + r")", re.I | re.X | re.M + ), + attributes.splitlines()[0].strip(), ) - + list( - re.finditer( - re.compile(r"^<\w+\b\s*[^\"']+?[\"']", re.M), - attributes.splitlines()[0].strip(), - ) + ) + list( + re.finditer( + re.compile(r"^<\w+\b\s*[^\"']+?[\"']", re.M), + attributes.splitlines()[0].strip(), ) ) - if start_test: - start_test = start_test[-1] + + start_test = start_test_list[-1] if start_test_list else None base_indent = len(attr_name.group()) diff --git a/tests/test_html/test_attributes.py b/tests/test_html/test_attributes.py index 9f6aeac..16a47ce 100644 --- a/tests/test_html/test_attributes.py +++ b/tests/test_html/test_attributes.py @@ -21,7 +21,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -# pylint: disable=C0116 +# pylint: disable=C0116,C0302 from typing import TextIO from click.testing import CliRunner @@ -124,14 +124,14 @@ def test_boolean_attributes(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, - b"""""", ) - + # boolean attributes after tag must be reformatted correctly assert output.exit_code == 1 print(output.text) @@ -146,7 +146,7 @@ def test_boolean_attributes(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, - b"""