thibaudcolas / curlylint

Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid
https://www.curlylint.org/
MIT License
236 stars 25 forks source link

Invalid test usage in Jinja2 isn't caught by linter #153

Open miketheman opened 1 year ago

miketheman commented 1 year ago

Describe the bug

When writing a Jinja2 template, using the expression if foo is None: does not trigger a linter error, so we only find out about it during runtime, aka TemplateRuntimeError

Ref: https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.TemplateRuntimeError

Writing Python, it's common to use the if foo is None: syntax, and sadly curlylint didn't catch this before I deployed to prd and learned the hard way.

Which terms did you search for in the documentation and issue tracker?

is None

Environment

curlylint 0.13.1, running in either macOS or Linux. I don't know if prior versions detected this, as it's new code we wrote and linted with the current version.

Steps to reproduce

  1. First, create an HTML template with the following content:
    {% if foo is None: %}
    foo is None!
    {% endif %}
  2. Then, run curlylint against that file

Expected behavior

I would have expected that the linter would fail, and hopefully suggest that I use the valid lowercase none is the right way to use this comparison.

Actual behavior

Passes with no errors:

$ curlylint broken.html
All done! ✨ 🍰 ✨

Reproducible demo

See steps above for file content that demonstrates issue.

Other

I found this while using None, but the same would apply for True and False.

Some links: