Merge pull request #347 from Riverside-Healthcare/dev

This commit is contained in:
sur.la.route 2022-08-22 12:23:09 -05:00 committed by GitHub
commit fc68a5118f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 404 additions and 325 deletions

620
docs/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "djlint_docs",
"version": "1.0.24",
"version": "1.0.25",
"description": "",
"main": "index.js",
"scripts": {
@ -25,7 +25,7 @@
"md5": "^2.3.0"
},
"devDependencies": {
"@11ty/eleventy": "1.0.1",
"@11ty/eleventy": "1.0.2",
"@11ty/eleventy-img": "2.0.1",
"@11ty/eleventy-plugin-syntaxhighlight": "4.1.0",
"@fontsource/inter": "4.5.12",
@ -40,7 +40,7 @@
"cz-conventional-changelog": "3.3.0",
"eleventy-plugin-edit-on-github": "1.1.0",
"eleventy-plugin-metagen": "1.7.11",
"esbuild": "0.15.3",
"esbuild": "0.15.5",
"eslint": "8.22.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
@ -55,7 +55,7 @@
"postcss-nested": "5.0.6",
"prettier": "2.7.1",
"prismjs": "1.28.0",
"sass": "1.54.4",
"sass": "1.54.5",
"slugify": "1.6.5"
},
"config": {

View file

@ -9,7 +9,7 @@ cssbeautifier==1.14.4
dill==0.3.5.1; python_full_version >= "3.7.2"
editorconfig==0.12.3
execnet==1.9.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
flake8==4.0.1; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0"
flake8==3.9.2; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0"
html-tag-names==0.1.2; python_version >= "3.7" and python_version < "4.0"
html-void-elements==0.1.0; python_version >= "3.7" and python_version < "4.0"
importlib-metadata==4.11.0; python_version >= "3.7"

View file

@ -61,13 +61,13 @@ def expand_html(html: str, config: Config) -> str:
if inside_ignored_block(config, html, match):
return match.group(1)
if not re.findall(
r"\<(?:"
+ str(config.indent_html_tags)
+ r")\b(?:[^>]|{%[^(?:%}]*?%}|{{[^(?:}}]*?}})*?"
+ re.escape(match.group(1))
+ "$",
+ r")\b(?:\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{\#[^\#]*\#}|[^>{}])*?"
# original
# + r")\b(?:[^>]|{%[^(?:%}]*?%}|{{[^(?:}}]*?}})*?"
+ re.escape(match.group(1)) + "$",
html[: match.end()],
re.MULTILINE | re.VERBOSE,
):

View file

@ -107,6 +107,36 @@ def inside_ignored_block(config: Config, html: str, match: re.Match) -> bool:
)
def overlaps_ignored_block(config: Config, html: str, match: re.Match) -> bool:
"""Do not add whitespace if the tag is in a non indent block."""
return any(
# don't require the match to be fully inside the ignored block.
# poorly build html will probably span ignored blocks and should be ignored.
(
ignored_match.start(0) <= match.start()
and match.start() <= ignored_match.end()
)
or (
ignored_match.start(0) <= match.end() and match.end() <= ignored_match.end()
)
for ignored_match in list(
re.finditer(
re.compile(
config.ignored_blocks,
re.DOTALL | re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL,
),
html,
)
)
+ list(
re.finditer(
re.compile(config.ignored_inline_blocks, re.IGNORECASE | re.VERBOSE),
html,
)
)
)
def inside_ignored_rule(config: Config, html: str, match: re.Match, rule: str) -> bool:
"""Check if match is inside an ignored pattern."""
for rule_regex in config.ignored_rules:

View file

@ -5,7 +5,7 @@ from typing import Dict, List
import regex as re
from .helpers import inside_ignored_block, inside_ignored_rule
from .helpers import inside_ignored_rule, overlaps_ignored_block
from .settings import Config
flags = {
@ -99,7 +99,7 @@ def lint_file(config: Config, this_file: Path) -> Dict:
for match in open_tags:
if (
inside_ignored_block(config, html, match) is False
overlaps_ignored_block(config, html, match) is False
and inside_ignored_rule(config, html, match, rule["name"])
is False
):
@ -119,7 +119,7 @@ def lint_file(config: Config, this_file: Path) -> Dict:
html,
):
if (
inside_ignored_block(config, html, match) is False
overlaps_ignored_block(config, html, match) is False
and inside_ignored_rule(config, html, match, rule["name"])
is False
):

View file

@ -70,7 +70,7 @@
message: Attributes should be double quoted.
flags: re.DOTALL|re.I
patterns:
- (?:class|id|src|width|height|alt|style|lang|title|srcset|media)=\'[^\']*'
- <(?:\w+)\b(\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}])*(?:class|id|src|width|height|alt|style|lang|title|srcset|media)=\'[^\']*'
- rule:
name: H009
message: Tag names should be lowercase.
@ -106,7 +106,7 @@
- <img\s(?:(?!(?:alt)=).)*/?>
- rule:
name: H014
message: More than 2 blank lines.
message: Found extra blank lines.
flags: re.DOTALL
patterns:
- "[^\n]{,10}\n{3,}"
@ -185,7 +185,7 @@
message: Tag seems to be an orphan.
flags: re.I|re.DOTALL
patterns:
- <((/?(\w+))\b(\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{#[^%]*#}|[^'\">{}])*)(?<!/)>
- <((/?(\w+))\b(\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{#[^#]*#}|[^'\">{}])*)(?<!/)>
- rule:
name: H026
message: Empty id and class tags can be removed.
@ -242,8 +242,8 @@
name: T032
message: Extra whitespace found in template tags.
patterns:
- "{%(([\"|'](?:(?!'|\"|%}).)*?[\"|'])|[^(?:%}|'|\")])*?\\s{2,}"
- "{{(([\"|'](?:(?!'|\"|}}).)*?[\"|'])|[^(?:}}|'|\")])*?\\s{2,}"
- "{%(([\"|'](?:(?!'|\"|%}).)*?[\"|'])|[^(?:%}|'|\"|\n)])*?[ \t]{2,}"
- "{{(([\"|'](?:(?!'|\"|}}).)*?[\"|'])|[^(?:}}|'|\"|\n)])*?[ \t]{2,}"
- rule:
name: H033
message: Extra whitespace found in form action.

View file

@ -91,6 +91,18 @@ def test_H006(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H006 1:" in result.output
assert "found 1 error" in result.output
# check that we don't partial match in an ignored block
write_to_file(
tmp_file.name,
b"""{# [INFO][JINJA] I use syntax "{% if <img alt=\""",
if I want that something happened solely if "img" exists in the content of my articles #}
<script src="KiraJS.js" defer></script>
""",
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H006" not in result.output
def test_H007(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b'<html lang="en">')
@ -105,6 +117,21 @@ def test_H008(runner: CliRunner, tmp_file: TextIO) -> None:
assert result.exit_code == 1
assert "H008 1:" in result.output
write_to_file(
tmp_file.name,
b"""<link rel="stylesheet" href="KiraCSS.css" media="print" onload="this.media='all'" media=''/>""",
)
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "H008 1:" in result.output
write_to_file(
tmp_file.name,
b"""<link rel="stylesheet" href="KiraCSS.css" media="print" onload="this.media='all'"/>""",
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H008 1:" not in result.output
def test_H009(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<H1>")
@ -715,6 +742,24 @@ def test_T032(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert "T032" not in result.output
write_to_file(
tmp_file.name,
b"""{# [INFO] Simple example #}
{% set kira = [
'Goddess', 'Genius'
] %}
{# [INFO] Real example #}
{% set kira_online_scaners = [
('https://quttera.com/sitescan/', 'SashaButtonLightSkyBlue', 'Quttera'),
('https://sitecheck.sucuri.net/results/', 'SashaButtonLimeGreen', 'Sucuri'),
('https://www.isithacked.com/check/', 'SashaButtonPlum', 'Is It Hacked?'),
] %}
""",
)
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert "T032" not in result.output
def test_H033(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(