added fix for #151

This commit is contained in:
Christopher Pickering 2021-11-29 09:26:36 +01:00
parent 65dffd7b3e
commit 8ff71789be
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 8 additions and 7 deletions

View file

@ -68,8 +68,9 @@ def print_output(
def build_relative_path(url: str, project_root: Path) -> str:
"""Get path relative to project."""
if project_root != url:
return str(Path(url).relative_to(project_root.resolve()))
url_path = Path(url)
if project_root != url_path and project_root in url_path.parents:
return str(url_path.relative_to(project_root.resolve()))
return url
@ -85,7 +86,7 @@ def build_output(error: dict, config: Config) -> int:
return 0
echo(
f"{Fore.GREEN}{Style.BRIGHT}\n{build_relative_path(list(error.keys())[0],config.project_root)}\n{Style.DIM}"
f"{Fore.GREEN}{Style.BRIGHT}\n{build_relative_path(list(error.keys())[0],config.project_root.resolve())}\n{Style.DIM}"
+ "".join(["" for x in range(1, width)])
+ Style.RESET_ALL
)
@ -121,7 +122,7 @@ def build_check_output(errors: dict, config: Config) -> int:
echo(
Fore.GREEN
+ Style.BRIGHT
+ build_relative_path(list(errors.keys())[0], config.project_root)
+ build_relative_path(list(errors.keys())[0], config.project_root.resolve())
+ str(list(errors.keys())[0])
+ Style.DIM
+ Style.RESET_ALL
@ -132,7 +133,7 @@ def build_check_output(errors: dict, config: Config) -> int:
Fore.GREEN
+ Style.BRIGHT
+ "\n"
+ build_relative_path(list(errors.keys())[0], config.project_root)
+ build_relative_path(list(errors.keys())[0], config.project_root.resolve())
+ "\n"
+ Style.DIM
+ "".join(["" for x in range(1, width)])

View file

@ -7,7 +7,7 @@ run::
for a single test, run::
pytest tests/test_config.py::test_exclude --cov=src/djlint \
pytest tests/test_config.py::test_indent --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
@ -50,7 +50,7 @@ def test_ignores(runner: CliRunner) -> None:
def test_indent(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["tests/config_indent", "--check"])
print(result.output)
assert (
"""-<section><p><div><span></span></div></p></section>
+<section>