diff --git a/src/djlint/__init__.py b/src/djlint/__init__.py index 5c3dc5a..978401c 100644 --- a/src/djlint/__init__.py +++ b/src/djlint/__init__.py @@ -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() diff --git a/src/djlint/output.py b/src/djlint/output.py index c1bd201..0edebc6 100644 --- a/src/djlint/output.py +++ b/src/djlint/output.py @@ -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: diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 92e133a..49ff0dd 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -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]] = { diff --git a/tests/test_djlint/-.html b/tests/test_djlint/-.html new file mode 100644 index 0000000..4740ec9 --- /dev/null +++ b/tests/test_djlint/-.html @@ -0,0 +1 @@ + diff --git a/tests/test_djlint/test_djlint.py b/tests/test_djlint/test_djlint.py index 1a02120..2bb5f5a 100644 --- a/tests/test_djlint/test_djlint.py +++ b/tests/test_djlint/test_djlint.py @@ -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,