fix(check): fixed issue where check was reformatting files that contained a hyphen in the name

closes #494
This commit is contained in:
Christopher Pickering 2022-12-26 10:30:41 -06:00
parent 57e1eecedb
commit 9812f601e9
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
5 changed files with 13 additions and 4 deletions

View file

@ -172,11 +172,12 @@ def main(
temp_file = None
if "-" in src:
if set("-").intersection(set(src)):
if config.files:
file_list = get_src([Path(x) for x in config.files], config)
else:
config.stdin = True
stdin_stream = click.get_text_stream("stdin", encoding="utf8")
stdin_text = stdin_stream.read()

View file

@ -30,7 +30,6 @@ def print_output(
lint_success_message = ""
lint_error_count = 0
format_error_count = 0
print_blanks = config.stdin is False and config.quiet is False
if print_blanks:
@ -99,6 +98,7 @@ def build_output(error: dict, config: Config) -> int:
errors = sorted(
list(error.values())[0], key=lambda x: tuple(map(int, x["line"].split(":")))
)
width, _ = shutil.get_terminal_size()
if len(errors) == 0:

View file

@ -272,7 +272,7 @@ class Config:
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
self.files: Optional[List[str]] = djlint_settings.get("files", None)
self.stdin = "-" in src and self.files is None
self.stdin = False
# codes to exclude
profile_dict: Dict[str, List[str]] = {

1
tests/test_djlint/-.html Normal file
View file

@ -0,0 +1 @@
<img>

View file

@ -5,7 +5,7 @@ run::
pytest tests/test_djlint/test_djlint.py --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_djlint/test_djlint.py::test_stdin
pytest tests/test_djlint/test_djlint.py::test_hyphen_file
or::
@ -61,6 +61,13 @@ def test_existing_file(runner: CliRunner) -> None:
assert str(Path("tests/test_djlint/bad.html")) in result.output
def test_hyphen_file(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["tests/test_djlint/-.html"])
assert result.exit_code == 1
print(result.output)
assert str(Path("tests/test_djlint/-.html")) in result.output
def test_multiple_files(runner: CliRunner) -> None:
result = runner.invoke(
djlint,