user3787031
user3787031

Reputation: 177

Ignore javascript error in HTML file (VS Code)

I have an HTML file which is a Django template. For the most part, it's pretty boring, there's a bit of HTML and some Javascript code inside script tags.

The problem is that I've inserted a single line of Django template language (with the double curly braces), and it cascades into a thousand different errors on every line. How do I ignore this? All I can find is // @ts-ignore on Google which doesn't seem to work with HTML files.

I don't even know where to begin. Is this a linting issue? What linter am I using, which documentation should I look at, etc. I assume I should be using the default tools for javascript. Please help!

The line in question is:

var achievementFlag = {{ achievement_flag|yesno:"true,false" }};

Naturally, the double curly braces is bad, as is the | and the :. And now the javascript just has squiggles all over it.

Upvotes: 1

Views: 5938

Answers (2)

jacbmelo
jacbmelo

Reputation: 371

Another workaround I usually use is to use JSON.parse:

var achievementFlag = JSON.parse('{{ achievement_flag|yesno:"true,false" }}');

Upvotes: 0

Kyriakos M.
Kyriakos M.

Reputation: 96

Add this line to settings.json

"html.validate.scripts": false,

this line will make vscode ignores javascript validation in HTML files

credits: https://github.com/Microsoft/vscode/issues/17433#issuecomment-273870328

Upvotes: 7

Related Questions