Is there a way to enable/disable inspections for project?
Hi there,
I have written a number of inspections that I like to enable/disable for the project that is currently opened (so from my project component). Is there a way to do this, or is this not possible?
Kind regards,
Martijn
请先登录再写评论。
Look at the various methods of getting a profile with InspectionProfileManager.getInstance()
You can check if the profile can be modified, and if so enable/disable inspections by their id:
if (profile instanceof ModifiableModel)
{
// disable "First parameter is usually called self" inspection from profile
((ModifiableModel) profile).disableTool("PyMethodParametersInspection");
}
You might want to create a custom inspection profile on a project basis:
Profile profile = inspectionProfileManager.createProfile();
profile.copyFrom(inspectionProfileManager.getProfile("Default", true));
profile.setName("My profile");
// add to list of profiles
inspectionProfileManager.addProfile(profile);
// set as root profile
inspectionProfileManager.setRootProfile("My profile")
Remember that InspectionProfileManager works on application level rather than project so you might want to restore things when project is closed.
Ah I see, I was already afraid of that... so inspections apply only to application level.
I am currently enabling inspections in InspectionToolProvider based on some application settings, however I preferred having them on project level.
Your solution of creating profiles on the fly might work, but I'm pretty sure it will give problems when opening multiple projects with different settings so I'd rather not go that way.
So I guess the answer would be: no this is not (normally) possible.
But I will still wait for a definitive answer from JetBrains.
As a related question: does anyone know if it is possible to reload my InspectionToolProvider when I change my application settings?