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?
Please sign in to leave a comment.
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")
Here's a screeny.

This is a Resig microtemplate. Commonly these are filled with asp-like js-injections. Can be variables or javascript code.
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.
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:
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:
As I said - I would never expect phpstorm to support such. There are so many that it would lead to bloat and bugs.
Thank you very much. This one is very helpful in many cases.
To bad it only works for one line. Something like :
Would have been perfect.
Thank you for your time.
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.
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.
+1, it would be great.
It is extremely useful when using polyfills.
For example, I have MyScript.prototype.polyfills object and I do not want to see any warnings from there. Jan Roald Haugland's suggestion is what we really need.
Is there any issue or ticket for that?
Could you please share some code examples+file extensions? We need something to work with and googling Resig's microtemplates or MyScript.prototype.polyfills examples doesn't return any code that's incorrectly parsed by IDE.
I created a very simplified example of code with polyfills: https://codepen.io/mcmimik/pen/vYGQVWX?editors=0010
File extension is ".js".
The problem is that I can't always unminify and fix warnings in polyfills' code. So I need the ability to disable all warnings in a specific part of code.
Much appreciated.
This is a purely JS-managed inspections and currently you can't suppress them for a file/region.
Here are corresponding feature requests that you can vote for:
- suppress for file: https://youtrack.jetbrains.com/issue/WEB-10308
- suppress for region: https://youtrack.jetbrains.com/issue/WEB-24722
I'm a bit surprised you can't do that already for JS. And it's a bit unexpected how little votes they have: 13 votes since 2013.
Currently I could only suggest a workaround mentioned in of the tickets: use scopes for inspections to exclude such files from being inspected.
Dmitry, thank you for the links to feature requests. I think, it's hard to find them in Google, that's why there are so little votes there.
I think, someday I'll refactor this file adding webpack to separate that "warning polyfill" part of code into another file. Just one more reason now, uh.