Skip to content

Commit

Permalink
Merge pull request #296 from Riverside-Healthcare/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sur.la.route committed Jul 22, 2022
2 parents d940fa8 + 3ce1b1e commit 56a8933
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 24 deletions.
2 changes: 2 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const process = require('process');
const { PythonShell } = require('python-shell');

Expand Down
18 changes: 9 additions & 9 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "djlint_docs",
"version": "1.0.18",
"version": "1.0.19",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -41,7 +41,7 @@
"eleventy-plugin-edit-on-github": "1.1.0",
"eleventy-plugin-metagen": "1.7.1",
"esbuild": "0.14.38",
"eslint": "8.19.0",
"eslint": "8.20.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"fontawesome-subset": "4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ignore_missing_imports = True

[flake8]
ignore = D103, F401, E501, W503, SIM114, D403, RST219, RST299
ignore = D103, F401, E501, W503, SIM114, D403, RST219, RST299, E999
per-file-ignores =
tests/*: S404,S101,E800,S607,N802,T201,S603,B001,E722
**/__init__.py: D104
**/__init__.py: D104
15 changes: 10 additions & 5 deletions src/djlint/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def is_ignored_block_opening(config: Config, item: str) -> bool:
"""
last_index = 0
inline = list(
re.finditer(config.ignored_blocks, item, flags=re.IGNORECASE | re.VERBOSE)
re.finditer(
config.ignored_blocks,
item,
flags=re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL,
)
)

if inline:
Expand All @@ -29,9 +33,9 @@ def is_ignored_block_opening(config: Config, item: str) -> bool:


def is_ignored_block_closing(config: Config, item: str) -> bool:
"""Find ignored group opening.
"""Find ignored group closing.
A valid ignored group opening tag will not be part of a
A valid ignored group closing tag will not be part of a
single line block.
"""
last_index = 0
Expand Down Expand Up @@ -64,7 +68,7 @@ def is_safe_closing_tag(config: Config, item: str) -> bool:
re.finditer(
re.compile(
config.ignored_inline_blocks + r" | " + config.ignored_blocks,
flags=re.IGNORECASE | re.VERBOSE,
flags=re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL,
),
item,
)
Expand All @@ -88,7 +92,8 @@ def inside_ignored_block(config: Config, html: str, match: re.Match) -> bool:
for ignored_match in list(
re.finditer(
re.compile(
config.ignored_blocks, re.DOTALL | re.IGNORECASE | re.VERBOSE
config.ignored_blocks,
re.DOTALL | re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL,
),
html,
)
Expand Down
1 change: 0 additions & 1 deletion src/djlint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def lint_file(config: Config, this_file: Path) -> Dict:
}
)
else:

for match in re.finditer(
re.compile(
pattern, flags=build_flags(rule.get("flags", "re.DOTALL"))
Expand Down
3 changes: 3 additions & 0 deletions src/djlint/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def reformat_file(config: Config, this_file: Path) -> dict:
rawcode = this_file.read_text(encoding="utf8")

compressed = compress_html(rawcode, config)

expanded = expand_html(compressed, config)

condensed = condense_html(expanded, config)

indented = indent_html(condensed, config)

beautified_code = indented
Expand Down
5 changes: 3 additions & 2 deletions src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
- '{%-[^\s]+'
- '{%[^\s|\-]+'
# handlebars
- '[^{]{#[^\s]+|^{#[^\s]+'
- '[^{]{#[^\s-]+|^{#[^\s-]+'
- '[^{]{#-[^\s]+|^{#-[^\s]+'
- '[^{]{\/[^\s]+|^{\/[^\s]+'
- '[^{]{\@[^\s]+|^{\@[^\s]+'
# close
- '[^(\s|^|\-)]+[}|%|#]}'
- '[^(\s|^)]+\-[}|%|#]}'
- \s{2,}[}|%|#]}
- '{[{|%|#]\s{2,}'
- '{[{|%|#]-?\s{2,}'
- rule:
name: T002
message: Double quotes should be used in tags.
Expand Down
5 changes: 3 additions & 2 deletions src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def __init__(
| <\?php
| <script
| <!--
| [^\{]{\#
| [^\{]{\#(?!\s*djlint\:\s*on)
| ^{\#(?!\s*djlint\:\s*on)
| <pre
| <textarea
| {%[ ]*?blocktrans(?:late)?[^(?:%})]*?%}
Expand All @@ -357,7 +358,7 @@ def __init__(
| \?>
| </script
| -->
# | \#}
| ^(?:(?!{\#).)*\#} # lines that have a #}, but not a {#
| </pre
| </textarea
| {\#\s*djlint\:\s*on\s*\#}
Expand Down
19 changes: 18 additions & 1 deletion tests/test_linter/test_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# for a single test
pytest tests/test_linter/test_linter.py::test_DJ018
pytest tests/test_linter/test_linter.py::test_T001
"""
# pylint: disable=C0116,C0103
Expand Down Expand Up @@ -41,6 +41,15 @@ def test_T001(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name, "--profile", "nunjucks"])
assert result.exit_code == 0

# this test will pass, because the jinja comment is an ignored block
write_to_file(tmp_file.name, b"{#-test -#}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert result.exit_code == 0

write_to_file(tmp_file.name, b"{#- test -#}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert result.exit_code == 0


def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"{% extends 'this' %}")
Expand Down Expand Up @@ -527,6 +536,14 @@ def test_H025(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name])
assert "H025" not in result.output

# check closing tag inside a comment
write_to_file(
tmp_file.name,
b'<input {# value="{{ driverId|default(\' asdf \') }}" /> #} value="this">',
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H025" not in result.output


def test_H026(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b'<asdf id="" >')
Expand Down
Empty file added tests/test_twig/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions tests/test_twig/test_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Djlint tests specific to twig.
run::
pytest tests/test_twig/test_comments.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_twig/test_comments.py::test_nested --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
"""
# pylint: disable=C0116

from typing import TextIO

from click.testing import CliRunner

from tests.conftest import reformat


def test_macro(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""{% if %}
{#
line
#}
{% endif %}
""",
)
assert output.exit_code == 0

output = reformat(
tmp_file,
runner,
b"""<div>
{#
multi
line
comment
#}
</div>
<div>
<p></p>
</div>
""",
)
assert output.exit_code == 0

0 comments on commit 56a8933

Please sign in to comment.