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

Looking for double quotes inside Jinja tags #585

Open
christopherpickering opened this issue Dec 28, 2020 · 13 comments
Open

Looking for double quotes inside Jinja tags #585

christopherpickering opened this issue Dec 28, 2020 · 13 comments
Labels
keep-unstale The issue will not be marked as stale by the stale-bot

Comments

@christopherpickering
Copy link
Contributor

Hi, thanks for the excellent tool! When running on Jinja2 templates it generally works pretty well. However, when there is an if statement inside a tag this error comes up -

image

The html is:

<!DOCTYPE HTML>
<option value="{{ t.id }}" {% if t.id == s.type_id %}selected{% endif %}>{{ t.name }}</option>

and run htmlhint:

npx htmlhint test.html

Is there a way that at htmlhint can ignore what is inside a {% ... %} and {{ ... }} ?

@christopherpickering
Copy link
Contributor Author

I'm going to pin on a few other items related to jinja2 templates - maybe they are related. If not, I can open separate issues.

Tag Pair & Spec Char Escape

image

Having an {% if %} ... {% endif %} inside an option tag, and any where inside the contents of a section tag seem to throw the "Tag Pair" errors.

Having a > after %} or }} seems to cause the Spec Char Escape error.

You can see that when I remove the if statement there are no errors on the line.

HTML:

<!DOCTYPE HTML>
<option value="w" {% if p.type == "w" %}selected{% endif %}>week(s)</option>
<option value="w" selected>week(s)</option>

@christopherpickering
Copy link
Contributor Author

Attr Lowercase

When None is inside an if, inside a tag htmlhint expects it to be lowercase.
image

If contents of {% ... %} and {{ ... }} are ignored this error would go away.

HTML:

<!DOCTYPE HTML>
<option {% if t.type == None %}disabled{% endif %}>Other</option>
<option disabled>Other</option>

@christopherpickering
Copy link
Contributor Author

christopherpickering commented Dec 28, 2020

Attr No Duplication & Attr Must Have A Value

This error is thrown whenever a {% ... %} or {{ ... }} occurs inside a tag. For example:

<option value="{{ t.id }}" {% if t.id == s.id %} selected {% endif %}>

Expected:
{%, {{, %}, }} should not be considered attribute names.

Attr No Unnecessary Whitespace

This seems too be through when there is whitespace around the connects of an if statement -
%} selected {%

@christopherpickering
Copy link
Contributor Author

I'm not experienced in TS, but I created pull request #586 that seems to correct all these issues by stripping the tags from the attributes.

Any thoughts or ways this could potentially go wrong?

Thanks!

@christopherpickering
Copy link
Contributor Author

I think my fix causes issues w/ items like this:

<link href="{{ my_href_var }}" rel="shortcut icon" />

will now trigger the src-not-empty error.

I'll tweak the pr to only trip tags that have a leading white space and see how that helps.

@christopherpickering
Copy link
Contributor Author

christopherpickering commented Dec 28, 2020

Maybe you can give a tip - most of the tests seem to be passing now, when I have valid template tags, except this one is still triggering the tag-pair and the spec-char-escape which go hand in hand in this. Do you have any ideas what is causing it?

<option value="w" {% if p.type == "w" %} selected="selected" {% endif %}>week(s)</option>

output:

test.html: line 2, col 81, error - Tag must be paired, no start tag: [ </option> ] (tag-pair)
test.html: line 2, col 1, error - Special characters must be escaped : [ < ]. (spec-char-escape)
test.html: line 2, col 73, error - Special characters must be escaped : [ > ]. (spec-char-escape)

@ckot
Copy link

ckot commented Feb 9, 2021

Great tool, and ditto on a request for this feature. I'm using nunjucks templates, which is basically the same syntax as jinja. Although I'm wondering if it might be better to add to the rc file definition some sort of way to express file-extension-specific overrides, for example something like:

fileTypeOverrides: {
    fileExtension: ".njk",
    ignoreBetween: [{
        start: "{%", 
        end: "%"
    }, {
       start: "{{",
       end: "}}"
    }],
    extraRules: [] // for example in templates I might want do disable missing doctype tag as these are merely html snippets....
  }

anyway, just my two cents. I figure that might make it easier to support all sorts of html template syntaxes.

@stale
Copy link

stale bot commented Apr 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the bot:stale Issue marked as stale because there was no activity label Apr 10, 2021
@christopherpickering
Copy link
Contributor Author

Not stale... can any of the devs chip in?

@stale stale bot removed the bot:stale Issue marked as stale because there was no activity label Apr 19, 2021
@stale
Copy link

stale bot commented Jun 18, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the bot:stale Issue marked as stale because there was no activity label Jun 18, 2021
@christopherpickering
Copy link
Contributor Author

asdf

@stale stale bot removed the bot:stale Issue marked as stale because there was no activity label Jun 18, 2021
@thedaviddias thedaviddias added the keep-unstale The issue will not be marked as stale by the stale-bot label Jun 19, 2021
@thedaviddias
Copy link
Member

@christopherpickering I "unstale" it, it should not go to stale anymore 😉

@christopherpickering
Copy link
Contributor Author

Thanks 😁 Is this something you can consider investigating?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-unstale The issue will not be marked as stale by the stale-bot
Projects
None yet
Development

No branches or pull requests

3 participants