Disable HTML file reference inspection in JS string

I have a .js file in which I have the code below. The IDE gives me a warning "Cannot resolve file 'me'" (which is expected, this is a dynamically handled URI).  However, when I get similar warnings in PHP code I have the option to "Disable inspection ... for statement" which adds a comment like: /** @NoInspection NAMEOFINSPECTION */

Is there anything similar that can be done in .js files to temporarily disable an inspection?  And if so how can I find the name of the inspection?

Code causing the warning:

return "Try <a href='/me'>/me</a>";
0

Hi there,

Kind of "Yes" and "No" at the same time.

The issue here is -- You have Language Injection fragment (HTML injected inside the string). Even if you will be able to disable it for that line alone (which should not be a problem) ... such suppression comment will be placed in the same context .. which in your case means **inside the string** ... which I do not think you want this (have IDE-specific HTML comment in your final HTML output).

As for inspection: place caret on the problematic space, hit Alt+Enter (or click on light bulb icon); once popup menu appears -- find the appropriate entry there and expand it (use "Right Arrow" key on keyboard -- mouse click can be quite problematic sometimes) -- choose "Edit inspection profile settings" -- you will be taken directly to that Inspection in the small settings screen where you can disable it completely etc.

P.S. I believe it will be the same inspection as this one: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000778050/comments/115000633964 -- it has screenshots so it's better to understand my words.

0
Avatar
Permanently deleted user

A simple way I to get around this is by breaking up '<' and '>' with a call to JavaScript string's concat() function.

Refactor things like this:

var a = "<blah bla bla>";

into something like:

var a = "<blah bla".concat(" bla>");

And, boom, highlighting gone!!

BTW, WebStorm/PhpStorm will see through this trickery if you try to use the '+' operator to concatenate strings:

var a = "<blah bla" + " bla>"; // Still sees HTML/XML tag. Trickery failed. 

May I suggest adding a explanatory comment wherever you use this trick, because the next developer that comes along may question your sanity.

0

请先登录再写评论。