PyCharm 2020.1 Help

Creating Custom Inspections

In PyCharm, you can create new inspections using Structural Search Inspection. To create a custom inspection, you have to configure a search template and set a severity level. The IDE will search for code that matches the template and will highlight it in the editor according to the specified severity.

If you want your inspection to suggest fixes, you have to configure the replace template as well.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Editor | Inspections.

  2. Select the profile in which you want to create a new inspection.

  3. Select Structural search inspection under the General inspections in the list, and select the checkbox to enable it (the inspection is disabled by default).

    adding a custom inspection

  4. Click the Add button and select Add Search Template if you want your inspection only to highlight code, or Add Replace Template if you want your inspection to highlight code strings and suggest fixes.

  5. Configure the templates.

    You can use a sample template and configure it according to your needs. To do so, click Existing Templates and then select the suitable one.

    For more information on how to configure search and replace templates, refer to Structural search and replace.

  6. When finished, click Save Template and name the new template.

  7. Select inspection severity and scope. If the new inspection is not associated with a scope, it applies to all source files of the current project.

  8. Apply the changes and close the dialog.

Last modified: 21 July 2020