mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-10 06:34:42 +00:00
fix(check): fixed issue where check was reformatting files that contained a hyphen in the name
closes #494
This commit is contained in:
parent
57e1eecedb
commit
9812f601e9
5 changed files with 13 additions and 4 deletions
|
|
@ -172,11 +172,12 @@ def main(
|
||||||
|
|
||||||
temp_file = None
|
temp_file = None
|
||||||
|
|
||||||
if "-" in src:
|
if set("-").intersection(set(src)):
|
||||||
if config.files:
|
if config.files:
|
||||||
file_list = get_src([Path(x) for x in config.files], config)
|
file_list = get_src([Path(x) for x in config.files], config)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
config.stdin = True
|
||||||
stdin_stream = click.get_text_stream("stdin", encoding="utf8")
|
stdin_stream = click.get_text_stream("stdin", encoding="utf8")
|
||||||
stdin_text = stdin_stream.read()
|
stdin_text = stdin_stream.read()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ def print_output(
|
||||||
lint_success_message = ""
|
lint_success_message = ""
|
||||||
lint_error_count = 0
|
lint_error_count = 0
|
||||||
format_error_count = 0
|
format_error_count = 0
|
||||||
|
|
||||||
print_blanks = config.stdin is False and config.quiet is False
|
print_blanks = config.stdin is False and config.quiet is False
|
||||||
|
|
||||||
if print_blanks:
|
if print_blanks:
|
||||||
|
|
@ -99,6 +98,7 @@ def build_output(error: dict, config: Config) -> int:
|
||||||
errors = sorted(
|
errors = sorted(
|
||||||
list(error.values())[0], key=lambda x: tuple(map(int, x["line"].split(":")))
|
list(error.values())[0], key=lambda x: tuple(map(int, x["line"].split(":")))
|
||||||
)
|
)
|
||||||
|
|
||||||
width, _ = shutil.get_terminal_size()
|
width, _ = shutil.get_terminal_size()
|
||||||
|
|
||||||
if len(errors) == 0:
|
if len(errors) == 0:
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ class Config:
|
||||||
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
|
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
|
||||||
|
|
||||||
self.files: Optional[List[str]] = djlint_settings.get("files", None)
|
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
|
# codes to exclude
|
||||||
profile_dict: Dict[str, List[str]] = {
|
profile_dict: Dict[str, List[str]] = {
|
||||||
|
|
|
||||||
1
tests/test_djlint/-.html
Normal file
1
tests/test_djlint/-.html
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<img>
|
||||||
|
|
@ -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 --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::
|
or::
|
||||||
|
|
||||||
|
|
@ -61,6 +61,13 @@ def test_existing_file(runner: CliRunner) -> None:
|
||||||
assert str(Path("tests/test_djlint/bad.html")) in result.output
|
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:
|
def test_multiple_files(runner: CliRunner) -> None:
|
||||||
result = runner.invoke(
|
result = runner.invoke(
|
||||||
djlint,
|
djlint,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue