Question

Is there a way to create a custom inspection for Python code in Intellij? I need to blacklist a Python function so it throws a warning whenever somebody imports it or types it in.

Was it helpful?

Solution

I only have experience with JavaScript plugins for IntelliJ, but it should work the same for Python.

You can write a plugin that provides an inspection. There's a learning curve of course, but once you get the environment setup it's pretty smooth.

First, you will need to check out the plugin development page from JetBrains. Here are the steps I would take:

When you finish that, you can start writing your plugin. For an inspection, there are a few classes you will be concerned about:

  • LocalInspectionTool is the actual inspection that will search a file and flag problems. You extend this class
  • InspectionToolProvider is the interface you implement to determine if a file will run a particular inspection.
  • ProblemDescriptor is the class that will represent your error message. You can optionally provide a fix to remove the elements in question.

You will get a PsiFile that represents your source file. Using this, you can search for the function in question and flag it as an error.

One last fantastic resource is the plugin development forum. Usually one of the developers will respond if someone else doesn't answer your question, so don't hesitate to post there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top