Skip to content

Commit

Permalink
fix: Remove number of repeated, pure function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JCWasmx86 committed Oct 31, 2024
1 parent 3062496 commit 40c6271
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions djlint/formatter/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ def fix_handlebars_template_tags(
ignored_level = 0

for item in rawcode_flat_list:
is_safe_closing_tag_ = is_safe_closing_tag(config, item)
is_ignored_block_opening_ = is_ignored_block_opening(config, item)

# if a raw tag first line
if not is_block_raw and is_ignored_block_opening(config, item):
if not is_block_raw and is_ignored_block_opening_:
is_raw_first_line = True

# if a raw tag then start ignoring
if is_ignored_block_opening(config, item):
if is_ignored_block_opening_:
is_block_raw = True
ignored_level += 1

if is_script_style_block_opening(config, item):
in_script_style_tag = True

if is_safe_closing_tag(config, item):
if is_safe_closing_tag_:
ignored_level -= 1
ignored_level = max(ignored_level, 0)
if is_block_raw and ignored_level == 0:
Expand Down Expand Up @@ -183,7 +186,7 @@ def fix_handlebars_template_tags(
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
)
and not is_block_raw
and not is_safe_closing_tag(config, item)
and not is_safe_closing_tag_
# and not ending in a slt like <span><strong></strong>.
and not re.findall(
rf"(<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
Expand Down Expand Up @@ -262,7 +265,7 @@ def fix_handlebars_template_tags(
indent_level += 1

elif is_raw_first_line or (
is_safe_closing_tag(config, item) and not is_block_raw
is_safe_closing_tag_ and not is_block_raw
):
tmp = (indent * indent_level) + item + "\n"

Expand All @@ -279,7 +282,7 @@ def fix_handlebars_template_tags(

# if a opening raw tag then start ignoring.. only if there is no closing tag
# on the same line
if is_ignored_block_opening(config, item):
if is_ignored_block_opening_:
is_block_raw = True
is_raw_first_line = False

Expand All @@ -302,7 +305,7 @@ def fix_handlebars_template_tags(
or is_script_style_block_closing(config, item)
):
in_script_style_tag = False
if not is_safe_closing_tag(config, item):
if not is_safe_closing_tag_:
ignored_level -= 1
ignored_level = max(ignored_level, 0)
if ignored_level == 0:
Expand Down

0 comments on commit 40c6271

Please sign in to comment.