Enable/disable inspections based on dynamic project conditions



I'm implementing some inspections for a JS test library and I would need to enable/disable them based on project specific conditions.

The trick is that the library has two versions in two different npm packages, so the inspections would need to be enabled/disabled based on which npm package is used as dependency in the project (using both is invalid). The other reason is that they changed the behaviour of the library so that certain things (and therefore inspections too) are applicable only in one or the other.

The plan is to enable/disable them in the currently used inspection profile, or even globally, so that I wouldn't have to ask the plugin's users to enable/disable them manually for each project they use.

This is what I have so far as candidate solutions or have looked into:

  • enabledByDefault property in plugin.xml is not a valid approach because it cannot evaluate dynamic conditions, simply accept boolean literals.
  • InspectionProfileEnty#isEnabledByDefault() is also not good for me, because the javadoc states that it must not be overridden, and also because I would need access to the current project's Project object.
  • Implement a StartupActivity and enable/disabled them via InspectionProfileManager and InspectionProfileImpl


Can you suggest a sophisticated approach with which this might be possible to achieve?

Thank you.


The inspections themselves should simply not run under specific conditions. There are many inspections checking such preconditions, then returning com.intellij.psi.PsiElementVisitor#EMPTY_VISITOR from buildVisitor() (or similar).

Modifying inspection profiles might be confusing and also yield unwanted modifications in shared inspection profile configuration files.


Hi Yann,

I looked into it and indeed I found many inspections with such behaviour, so I can move forward with this approach.

Thanks for the help.


Please sign in to leave a comment.