microsoft / vscode-htmlhint

VS Code integration of HTMLHint, an HTML linter.
MIT License
50 stars 35 forks source link

Enhancement: Support EJS files #77

Open LightCC opened 4 years ago

LightCC commented 4 years ago

It appears that EJS (Embedded JavaScript) files could be supported pretty easily on this extension.

EJS templates embedded javascript with <% begin tags and %> end tags, with javascript and other characters that drive various behavior inbetween the ejs start/stop tags.

Currently, htmlhint gives the following error on these tags: image

image

So, one can work around this by turning off the spec-char-escape rule, but then the rule won't catch any non-ejs issues with special character escaping.

The following should be considered for ejs files (*.ejs) by default, or allow explicit configuration by user somehow. These are considered as least support for ejs to most support (but also least amount of work to most amount of work):

  1. Just disable spec-char-escape by default on ejs files (*.ejs)
  2. Ignore the spec-char-escape rule only on <% and %>
  3. Find paired <% and %> tags and ignore both the tags and everything between them
  4. Same as above, but actually lint the ejs tags (<%, <%=, etc.)
  5. Same as above, but also lint the javascript within the ejs tags, or pass off to another linter (e.g. eslint, etc.)
ckot commented 3 years ago

alternatively, to support other types of files, (I'm using nunjucks templates with my eleventy SSG site), can the configuration for htmlhint be configured to use different htmlhint rc files for different file extensions?

in the meantime, I've just posted a feature request with the upstream htmlhint project asking if the .htmlhintrc syntax be extended to overide rules for different file extensions, and define start/end pairs like "{{", "}}" and "{%", "%}" so that stuff between them can be ignored.

aravindvnair99 commented 3 years ago

Related to: https://github.com/htmlhint/HTMLHint/issues/492

I too am facing this issue, although I feel this must be implemented in the npm package than in the VS Code extension.

Possible solution: https://github.com/htmlhint/HTMLHint/issues/492#issuecomment-808464837

Danielbright-create commented 3 years ago

please how can i disable the spec-char-escape