Disabling code inspection for sections of a file

Hi,

is there a way, by a phpdoc-comment or similar, to disable the code inspection for sections of code?
It can be very annoying and give unnecessary noise when the IDE doesn't understand whats going on.
I don't want to disable the inspection that causes it, just tell the IDE that it doesn't need to inspect/understand this section.

One concrete example is usage of pseudo-markup, like Resig's microtemplates. PHPStorm needs to be told that it should just ignore it.

Is my intent clear?

7 comments

Hi there,

Please provide an example (source code to copy-paste and screenshot with error/warning messages).

1) Not every inspection can be muted (via inline comments)
2) If it can be muted -- it cannot be done for a block of code -- only for next single line or whole file.

I'm pretty sure that it will not work for custom templating languages.

You can turn off ANY inspection completely for specific file(s)/folder(s) -- just create custom scope (Settings | Scopes) and then specify how it needs to behave in "Settings | Inspections" (right click on particular inspection and choose "Add Scope")

0

Here's a screeny.
This is a Resig microtemplate. Commonly these are filled with asp-like js-injections. Can be variables or javascript code.
undefined.png
Of course I would never expect phpstorm to understand this or similar pseudocode constructs, but it would be very nice with a way to disable the inspections for such blocks.
This is a .php -file (view), so I would not want to turn off the undefined constant-inspection :-)

I strive to make the inspections and all intelli-features work for me. I do whatever I can to tell the IDE what's going on at all times. This way, when it complains about something - its actually worth looking in to.
Quite often, however, it's completely impossible for the IDE to understand a line/block of valid php/js.

Like a php object that implements a magic __set() -method. You don't want the IDE to complain about numerous "undefined property"-problems, but you don't want to disable the entire inspection.

It's more of a general solution to a general problem with the inspections I'm looking for.
A /** @mute  */ -like solution.

Take a project code analysis report for instance. You tweak it until you have the most relevant results, but still there is a load of results that you are aware of and cannot remove from the report.
If I could mute blocks or lines I could make the reports return completely blank. If next time it's not blank - there is a genuine problem. This would make it truly more valuable.

0

PhpStorm does not have support for custom template engine/syntax yet, unfortunately. I guess you are after this ticket: http://youtrack.jetbrains.com/issue/WEB-1173

With regard to suppressing -- I have tried your example:

<script type="text/html" id="foo">
    <input name="bar[baz]" value="<%=obj_key%>" type="hidden" />
    

Since it is in PHP file and <%= %> is PHP ASP-like syntax (should be supported by PhpStorm -- have never tried it myself), you can suppress individual inspection (at very least in this particular case). I just do not know if it will do anything good in the end (how it will be parsed by template engine).

For this -- Alt+Enter on error, select desired entry and press Right-arrow key (or click on triangle-arrow icon on very right) -- then choose "Suppress for statement". The result:

<script type="text/html" id="foo">
    <input name="bar[baz]" value="<%=/** @noinspection PhpUndefinedConstantInspection */obj_key%>" type="hidden" />

0

PhpStorm does not have support for custom template engine/syntax yet, unfortunately. I guess you are after this ticket: http://youtrack.jetbrains.com/issue/WEB-1173


As I said - I would never expect phpstorm to support such. There are so many that it would lead to bloat and bugs.

For this -- Alt+Enter on error, select desired entry and press Right-arrow key (or click on triangle-arrow icon on very right) -- then choose "Suppress for statement". The result:


Thank you very much. This one is very helpful in many cases.
To bad it only works for one line. Something like :

/** @noinspection SomeInspection[,SomeOtherInspection] start */
...
...
...
/** @noinspection end */

Would have been perfect.

Thank you for your time.

1

To bad it only works for one line. Something like :

/** @noinspection SomeInspection[,SomeOtherInspection] start */
...
...
...
/** @noinspection end */

Would have been perfect.

This is not current planned (AFAIK). Currently suppression may work for single statement or whole file only.

In your particular case it's much better to have generic/customisable template language supported (at very least it should not treat anything inside custom tags as errors) than manually suppress (sometimes invalid) inspections. Problem is -- only God knows when it will be implemented (does not look like it will be in v6 ...)

0

There are so many different js-templating languages and versions/tweaks that I would not hold my breath while waiting. Any generic solution there is likely to be mediocre/lacking.
Some solutions, like dust.js are based on compiling templates with node.js as well, so for those both compiled/raw templates would have to be supported.
Still the intellij wouldnt know much about the variables inside the templates without loads of jsdoc-help. Then comes the context where all templates will be used...

I predict the generic support would be limited to templating systems that have defined blocks of pure js or are compiled into pure js. And then only simple syntax-checking.

An improved @noinspection functionality could be useful in blocks of php or entire php-files as well, where you for some reason would like to turn off some inspections without fiddling with custom inspection scopes.
@noinspection would follow the code as well and not require a lot of configurations in the IDE that all developers on a project woud have to bother with.

0

Please sign in to leave a comment.