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 "] diff --git a/src/djlint/formatter/attributes.py b/src/djlint/formatter/attributes.py index eb962b2..596ed28 100644 --- a/src/djlint/formatter/attributes.py +++ b/src/djlint/formatter/attributes.py @@ -41,22 +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(), ) - )[-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 030df37..16a47ce 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. @@ -19,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 @@ -118,6 +120,68 @@ 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 = (