Merge pull request #326 from ruanmed/master

This commit is contained in:
sur.la.route 2022-08-16 07:47:04 -05:00 committed by GitHub
commit 07e31dc832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 17 deletions

View file

@ -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": {

View file

@ -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 <cpickering@rhc.net>"]

View file

@ -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())

View file

@ -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"""<select
multiple
class="selectpicker show-tick"
id="device-select"
title="">
</select>""",
)
# boolean attributes after tag must be reformatted correctly
assert output.exit_code == 1
print(output.text)
assert (
output.text
== """<select multiple class="selectpicker show-tick" id="device-select" title="">
</select>
"""
)
# boolean attributes after tag with long attributes must be reformatted correctly
output = reformat(
tmp_file,
runner,
b"""<select
multiple
class="selectpicker show-tick"
id="device-select"
title=""
value="something pretty long goes here"
style="width:100px;cursor: text;border:1px solid pink">
</select>""",
)
assert output.exit_code == 1
print(output.text)
assert (
output.text
== """<select multiple
class="selectpicker show-tick"
id="device-select"
title=""
value="something pretty long goes here"
style="width:100px;cursor: text;border:1px solid pink">
</select>
"""
)
# boolean attributes after tag are accepted
output = reformat(
tmp_file,
runner,
b"""<input readonly
class="form-control"
type="text"
name="driver_id"
value="{{ id|default(' sample_text ') }}"/>""",
)
assert output.exit_code == 0
# def test_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (