Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Linter] Error on empty html elements #275

Closed
3 tasks done
lhuhmann opened this issue Jul 1, 2022 · 15 comments
Closed
3 tasks done

[BUG] [Linter] Error on empty html elements #275

lhuhmann opened this issue Jul 1, 2022 · 15 comments
Labels
🔍 linter 🦠 bug Something isn't working released

Comments

@lhuhmann
Copy link

lhuhmann commented Jul 1, 2022

System Info

  • OS: Windows 10 Pro, Windows Server 2019 Standard
  • Python Version: 3.10.4, 3.8.8
  • djLint Version: 1.3.0
  • template language: html

Issue

Error on many html elements with no content, such as <br>, <p></p>, <h1></h1>, etc..

Traceback:

Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Kyanite\.virtualenvs\temp-Bh3UMC1v\Scripts\djlint.exe\__main__.py", line 7, in <module>
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Python310\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\djlint\__init__.py", line 251, in main
    if bool(print_output(config, file_errors, len(file_list))) and config.warn is False:
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\djlint\output.py", line 34, in print_output
    lint_error_count += build_output(error["lint_message"], config)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\djlint\output.py", line 91, in build_output
    echo(
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\click\utils.py", line 299, in echo
    file.write(out)  # type: ignore
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\colorama\ansitowin32.py", line 170, in write
    self.write_and_convert(text)
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\colorama\ansitowin32.py", line 198, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "c:\users\kyanite\.virtualenvs\temp-bh3umc1v\lib\site-packages\colorama\ansitowin32.py", line 203, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Python310\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 39-117: character maps to <undefined>

How To Reproduce

A couple of examples where the error occurs:

  1. <p></p> error_example_1.txt
  2. <br> error_example_2.txt

A couple of examples where the error does not occur:

  1. <p>a</p> success_example_1.txt
  2. <br/> success_example_2.txt
@lhuhmann lhuhmann added 🔍 linter 🦠 bug Something isn't working labels Jul 1, 2022
@christopherpickering
Copy link
Contributor

Thanks, it seems like it is the unicode encodings on windows. We had a problem like this before, I'll take a look into it.

@christopherpickering
Copy link
Contributor

From the output you posted, it seems to be crashing on the text color. What language is the computer? I tried it on one of mine without issue, but it was a different windows version.

Does this help:
"Beta: Use Unicode UTF-8 with worldwide language support" in the system locale setting of windows, you can do it without any problem.

Do you have another windows pc you have tested on? Thanks!

@lhuhmann
Copy link
Author

lhuhmann commented Jul 5, 2022

Thanks for the quick response! The machine we're trying to run the linter on is a shared development environment for which I'm not an administrator, so let me talk with the server admin to see if it's reasonable for us to make that change. I'll keep you posted about how it works!

@christopherpickering
Copy link
Contributor

I rounded up a windows server, but not the same version as your, and didn't get the same error.

  • How are you calling djlint? in a subprocess/visual studio, etc?
  • What language is the server?
  • Can you test this script? From your error, it seems like it was coming from the red text, but working on blue.
from colorama import Fore, Style
from click import echo

lint_success_color = (
    Fore.RED + Style.BRIGHT
)
echo(f"{lint_success_color}test{Style.RESET_ALL}")

Here's a pic from my server. Its a 2012 R2. It doesn't have (or at least I can't find lol) the settings for unicode worldwide support, so I'm wondering if that is just the newer versions.
image

@lhuhmann
Copy link
Author

lhuhmann commented Jul 6, 2022

Changing the locale settings on my personal computer (Windows 10 Pro) did fix the issue on that machine. The machine I'm trying to get djlint to run on is my group's development environment at work, and due to permissions I was not able to get deep enough into the settings to check whether the option is available on that machine (Windows Server 2019 Standard), plus the administrator nixed the idea of changing the locale settings globally even if it is an option. However, I was told there might be a way to change the locale settings locally just for running the linting process, so I can look into that further. I'll also get back to you on your other questions as well, hopefully tomorrow.

@christopherpickering
Copy link
Contributor

Keep me posted on the test script, if it fails Maybe I can get help from colorama.

@lhuhmann
Copy link
Author

lhuhmann commented Jul 7, 2022

I tried the script (saved as temp.py) on our development machine (Windows Server 2019 Standard), and it ran fine.

image

I haven't yet looked into the possibility of changing the locale settings locally, like I mentioned in my last comment, but I can try that next.

@lhuhmann
Copy link
Author

lhuhmann commented Jul 7, 2022

Locally changing locale settings didn't seem super promising (as in, I'm not sure how/whether it can be done), but per your question about how we're calling djlint, I tried it in cmd (rather than git bash), and preliminary testing suggests that the issue may not occur there.

@christopherpickering
Copy link
Contributor

ok nice, thanks, yeah, in the screen shot you sent, I was either expecting an error, or that the text "test" would be read.

I was testing in cmd, I'll try in git bash on my side to see if I can get it. There is an open issue in colorama to support git bash better, but I think we can get around it by setting an env variable.

@christopherpickering
Copy link
Contributor

I'm able to reproduce it in git bash 👍🏽 I'll play around with it to see if we can get it fixed. Thanks!

@christopherpickering
Copy link
Contributor

I pushed an update on the dev branch that tis working on my server now. Do you want to test it out?

 python -m pip install git+https://github.com/Riverside-Healthcare/djlint.git@dev

I'll make a new release soon if this is ok to you.

@lhuhmann
Copy link
Author

lhuhmann commented Jul 7, 2022

I'm seeing one potential additional weirdness related to this bug that I'd like to check on today or tomorrow, and I can also try your update and see how that works. I'll let you know!

@christopherpickering
Copy link
Contributor

I opened #286 to review the progress bar format on windows.

christopherpickering pushed a commit that referenced this issue Jul 8, 2022
# [1.7.0](v1.6.0...v1.7.0) (2022-07-08)

### Bug Fixes

* **git bash:** fixes char encoding on windows git bash ([3ef7c16](3ef7c16)), closes [#275](#275)

### Features

* **linter:** added per-file-ignores as a config option for linter rules ([c709efd](c709efd)), closes [#107](#107)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lhuhmann
Copy link
Author

lhuhmann commented Jul 8, 2022

Looks great, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 linter 🦠 bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants