mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-05 20:34:42 +00:00
Merge pull request #24 from matthiask/mk/exclude
Fixed #22: Added configuration options to define excluded paths
This commit is contained in:
commit
229c9c7317
8 changed files with 38 additions and 15 deletions
|
|
@ -1,6 +1,9 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
- Added support for overriding or extending the list of excluded paths in
|
||||
``pyproject.toml``
|
||||
|
||||
0.3.9
|
||||
-----
|
||||
- Updated attribute handling
|
||||
|
|
|
|||
|
|
@ -25,3 +25,5 @@ Configuration options can also be added to your projects `pyproject.toml` file.
|
|||
extension = "html.dj"
|
||||
custom_blocks = "toc,example" # custom code blocks {% toc %}...{% endtoc %}
|
||||
indent = " " # change indentation level
|
||||
exclude = ".venv,venv,.tox,.eggs,..." # override the default set of excluded paths
|
||||
extend_exclude = ".custom" # add paths to exclude
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ def get_src(src: Path, config: Config) -> List[Path]:
|
|||
|
||||
paths = list(
|
||||
filter(
|
||||
lambda x: not re.search(config.ignored_paths, str(x), re.VERBOSE),
|
||||
lambda x: not re.search(config.exclude, str(x), re.VERBOSE),
|
||||
list(src.glob(f"**/*.{extension}")),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
## get pyproject.toml settings
|
||||
from pathlib import Path
|
||||
|
|
@ -61,7 +62,20 @@ class Config:
|
|||
quiet: Optional[bool] = False,
|
||||
):
|
||||
|
||||
self.ignored_paths: str = r"""
|
||||
djlint_settings = load_pyproject_settings(Path(src))
|
||||
|
||||
# custom configuration options
|
||||
self.extension: str = str(extension or djlint_settings.get("extension", "html"))
|
||||
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
|
||||
self.quiet: str = str(quiet or djlint_settings.get("quiet", ""))
|
||||
self.custom_blocks: str = str(
|
||||
build_custom_blocks(djlint_settings.get("custom_blocks")) or ""
|
||||
)
|
||||
|
||||
# base options
|
||||
self.indent: str = djlint_settings.get("indent", " ")
|
||||
|
||||
default_exclude: str = r"""
|
||||
\.venv
|
||||
| venv
|
||||
| \.tox
|
||||
|
|
@ -81,19 +95,12 @@ class Config:
|
|||
| node_modules
|
||||
| __pypackages__
|
||||
"""
|
||||
|
||||
djlint_settings = load_pyproject_settings(Path(src))
|
||||
|
||||
# custom configuration options
|
||||
self.extension: str = str(extension or djlint_settings.get("extension", "html"))
|
||||
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
|
||||
self.quiet: str = str(quiet or djlint_settings.get("quiet", ""))
|
||||
self.custom_blocks: str = str(
|
||||
build_custom_blocks(djlint_settings.get("custom_blocks")) or ""
|
||||
)
|
||||
|
||||
# base options
|
||||
self.indent: str = djlint_settings.get("indent", " ")
|
||||
self.exclude: str = djlint_settings.get("exclude", default_exclude)
|
||||
extend_exclude: str = djlint_settings.get("extend_exclude", "")
|
||||
if extend_exclude:
|
||||
self.exclude += r" | " + r" | ".join(
|
||||
re.escape(x.strip()) for x in extend_exclude.split(",")
|
||||
)
|
||||
|
||||
# contents of tags will not be formatted, but tags will be formatted
|
||||
self.ignored_block_opening: str = r"""
|
||||
|
|
|
|||
1
tests/config_excludes/excluded.html
Normal file
1
tests/config_excludes/excluded.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{missing_space}}
|
||||
1
tests/config_excludes/html.html
Normal file
1
tests/config_excludes/html.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{missing_space}}
|
||||
2
tests/config_excludes/pyproject.toml
Normal file
2
tests/config_excludes/pyproject.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[tool.djlint]
|
||||
extend_exclude = "excluded.html"
|
||||
|
|
@ -63,3 +63,10 @@ def test_indent(runner: CliRunner) -> None:
|
|||
in result.output
|
||||
)
|
||||
assert result.exit_code == 1
|
||||
|
||||
|
||||
def test_exclude(runner: CliRunner) -> None:
|
||||
result = runner.invoke(djlint, ["tests/config_excludes"])
|
||||
assert """html.html""" in result.output
|
||||
assert """excluded.html""" not in result.output
|
||||
assert result.exit_code == 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue