From bccc364269debc4c9983f12763b1e5bb3f6848bb Mon Sep 17 00:00:00 2001 From: Antoine Auger Date: Wed, 27 Nov 2024 13:43:39 +0100 Subject: [PATCH] fix(src): resolve exclude paths (#1034) --- djlint/settings.py | 4 ++++ djlint/src.py | 2 +- tests/test_config/test_excludes/pyproject.toml | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/djlint/settings.py b/djlint/settings.py index c0f98218c..9a1391f7b 100644 --- a/djlint/settings.py +++ b/djlint/settings.py @@ -1123,3 +1123,7 @@ def __init__( ) """ ) + + def get_exclude_paths(self) -> Iterator[Path]: + for p in self.exclude.split("|"): + yield Path(p.strip().replace("\\.", ".")).resolve() diff --git a/djlint/src.py b/djlint/src.py index a6a1c1fcd..2cd641cbc 100644 --- a/djlint/src.py +++ b/djlint/src.py @@ -44,7 +44,7 @@ def get_src(src: Iterable[Path], config: Config) -> list[Path]: paths.extend( x for x in normalized_item.glob(f"**/*.{extension}") - if not re.search(config.exclude, x.as_posix(), flags=re.X) + if not any(x.is_relative_to(p) for p in config.get_exclude_paths()) and no_pragma(config, x) and ( (config.use_gitignore and not config.gitignore.match_file(x)) diff --git a/tests/test_config/test_excludes/pyproject.toml b/tests/test_config/test_excludes/pyproject.toml index 469dba743..612b43ada 100644 --- a/tests/test_config/test_excludes/pyproject.toml +++ b/tests/test_config/test_excludes/pyproject.toml @@ -1,3 +1,3 @@ [tool.djlint] -exclude = "foo/excluded.html" -extend_exclude = "excluded.html" +exclude = "tests/test_config/test_excludes/foo/excluded.html" +extend_exclude = "tests/test_config/test_excludes/excluded.html"