IntelliJ IDEA 2021.1 Help

Get results and fix problems

If an inspection has detected a problem in your code, you can quickly apply a fix in the editor. Place the caret at the highlighted piece of code and press Alt+Enter.

For some inspections, you can open a preview by pressing Ctrl+Shift+I (View | Quick Definition ).

Applying a quick-fix in the editor

If you have invoked inspections manually, you can examine the results in the Inspection Results tool window that opens automatically after the analysis is finished. All detected problems are listed in the left part of the tool window. Click a problem to display inspection details on the right.

Apply a quick-fix

  • To fix a problem, use the Intention action button (Apply a quick-fix ). You can also press Alt+Enter or select a suitable fix from the popup menu.

Inspection results tool window

Clean up your code

You can streamline the process of fixing problems in your code by running Code Cleanup. This allows you to batch-apply quick-fixes to the selected scope without examining each problem individually.

During the cleanup, the IDE applies fixes from the code cleanup inspections in the selected inspection profile. To view the list of these inspections, open the Settings/Preferences dialog by pressing Ctrl+Alt+S and go to Editor | Inspections, click the Filter Inspections button, and enable the Show only cleanup inspections option.

Batch-apply quick-fixes (Code Cleanup)

  1. From the main menu, select Analyze | Code Cleanup.

  2. In the Specify Code Cleanup Scope dialog, select the scope to which you want to apply a profile.

  3. Select the inspection profile from the Inspection profile list, or click the Browse button to configure a new profile.

    You can also click the Browse button to view all code cleanup inspections and their settings.

  4. Click OK to launch the cleanup.

    the Specify Code Cleanup Scope dialog

IntelliJ IDEA performs code analysis and applies quick-fixes from the selected inspection profile to the detected issues.

Alternatively, you can place the caret at an error in the source code that corresponds to a quick-fix, click the red bulb the quick-fix icon (suggested quick-fix) that appears on the left, and select Code Cleanup from the menu.

The Specify Code Cleanup Scope dialog

ItemDescription
Whole projectSelect this option if you want to perform code cleanup for the whole project.
Uncommitted files

This option is only available for projects under version control.

Clean up the code in the files that have not yet been committed to a version control system. You can select a changelist of fix problems in all uncommitted files.

File <file path>Select this option to perform code cleanup for the file that is open in the editor or selected in the Project tool window.
Module <module name>

Select this option to perform code cleanup for the module that is currently selected in the Project tool window.

This option is only available, when your project consists of several modules.

Directory <directory path>Clean up the code in the directory that is currently selected in the Project tool window.
Selected filesClean up the code in the files selected in the Project tool window.
Custom scopeSelect a scope custom scope. You can select one of the predefined scopes from the list, or click the Browse button and define a new scope in the Scopes dialog that opens. For instructions on how to define a scope, refer to Scope language syntax reference.
Include test sourcesApply the code cleanup to test sources.
Inspection profile

Select an inspection profile. You can use a pre-defined profile from the list, or click the Browse button and configure a new profile in the Inspections dialog that opens.

You can open the Inspections dialog to check which fixes will be applied to the selected scope when you run code cleanup.

Run Silent Cleanup

You can also run the code cleanup in the silent mode without displaying the Specify Code Cleanup Scope dialog. In this case, the IDE runs the cleanup inspections from the profile that is currently configured in the settings.

  1. Select the node in which you want to clean up your code in the Project tool window (Alt+1 ).

    Otherwise, the cleanup will run in the file that is currently opened in the editor.

  2. From the main menu, select Analyze | Silent Code Cleanup.

Clean up your code before committing it to Git

You can clean up your code in files before they are committed to Git. In this case, the current inspection profile will be applied.

  1. From the main menu, select Git | Commit (or press Ctrl+K ).

  2. In the Commit tool window, click Show Commit Options and in the Before commit area, select the Cleanup checkbox.

    Alternatively, if you're using the Commit Changes dialog, in the Before Commit area, select the Cleanup checkbox.

  3. Click Commit.

Export results

  1. In the Inspection Results tool window, click the Export button.

    The Export button in the Inspection Results tool window

  2. Select the format in which you want to save the report (HTML or XML) and the target directory, and click Save.

Last modified: 30 June 2021