Skip to content

Commit

Permalink
chore: Address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
JCWasmx86 committed Nov 7, 2024
1 parent c2b7514 commit be8e236
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
10 changes: 4 additions & 6 deletions djlint/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ def child_of_unformatted_block(
unformatted_blocks=config.unformatted_blocks,
unformatted_blocks_coarse=config.unformatted_blocks_coarse,
):
if ignored_match_start > match_start:
break
if ignored_match_start < match_start and match_end <= ignored_match_end:
return True
return False
Expand Down Expand Up @@ -391,11 +389,11 @@ def overlaps_ignored_block(
) -> bool:
"""Do not add whitespace if the tag is in a non indent block."""
match_start, match_end = match.span()
for ignored_match_start, ignored_match_end in _overlaps_ignored_block(
html,
ignored_blocks=config.ignored_blocks,
ignored_inline_blocks=config.ignored_inline_blocks,
for ignored_match in itertools.chain(
re.finditer(config.ignored_blocks, html, flags=RE_FLAGS_IMSX),
re.finditer(config.ignored_inline_blocks, html, flags=RE_FLAGS_IX),
):
ignored_match_start, ignored_match_end = ignored_match.span()
# don't require the match to be fully inside the ignored block.
# poorly build html will probably span ignored blocks and should be ignored.
if (ignored_match_start <= match_start <= ignored_match_end) or (
Expand Down
30 changes: 2 additions & 28 deletions djlint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import importlib
import itertools
from collections.abc import Sequence
from functools import cache
from typing import TYPE_CHECKING
Expand All @@ -12,10 +11,9 @@

from . import regex_utils
from .helpers import (
RE_FLAGS_IMSX,
RE_FLAGS_IX,
inside_ignored_linter_block,
inside_ignored_rule,
overlaps_ignored_block,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -61,19 +59,6 @@ def get_line(start: int, line_ends: Sequence[Mapping[str, int]]) -> str:
return "{}:{}".format(line_ends.index(line) + 1, start - line["start"])


def overlaps_ignored(
blocks: list[tuple[int, int, int]], match: re.Match[str]
) -> bool:
match_start = match.start()
match_end = match.end()
for block in blocks:
if (block[0] <= match_start <= block[2]) or (
block[1] <= match_end <= block[2]
):
return True
return False


def linter(
config: Config, html: str, filename: str, filepath: str
) -> dict[str, list[LintError]]:
Expand All @@ -92,17 +77,6 @@ def linter(
if regex_utils.search(pattern, filepath, flags=re.X):
ignored_rules.update(x.strip() for x in rules.split(","))

ignored_blocks = [
(x.start(0), x.start(), x.end())
for x in itertools.chain(
regex_utils.finditer(
config.ignored_blocks, html, flags=RE_FLAGS_IMSX
),
regex_utils.finditer(
config.ignored_inline_blocks, html, flags=RE_FLAGS_IX
),
)
]
for rule in config.linter_rules:
rule = rule["rule"] # noqa: PLW2901

Expand Down Expand Up @@ -135,7 +109,7 @@ def linter(
pattern, html, flags=build_flags(rule.get("flags", "re.S"))
):
if (
not overlaps_ignored(ignored_blocks, match)
not overlaps_ignored_block(config, html, match)
and not inside_ignored_rule(
config, html, match, rule["name"]
)
Expand Down

0 comments on commit be8e236

Please sign in to comment.