Small edits can leave uneven spacing in a source file. In IntelliJ IDEA on the Linux desktop, the Reformat code action formats modified files when the IDE saves them.
The setting applies to the current project. The formatter uses the project's code style, with any applicable .editorconfig rules taking precedence.
Whole-file formatting can change lines outside your edit. A disposable Java source file lets you try the setting before saving work you intend to commit.
Steps to enable format on save in a JetBrains IDE:
Start with a disposable Java source file open inside the current project, using a project you created with the default Java code style. The file must contain int count = 1; inside a method. The example uses Main.java in ~/IdeaProjects/hello.
If Trust and Open Project appears while opening your project, choose Trust Project only if you trust its source. The Junie or air invitation in the empty editor area is optional. Start at step 1 when the Java file is open and project analysis has finished.
- Press
Ctrl+Alt+Sto open Settings.
- Expand Tools in the Settings sidebar if it is collapsed.

- Select Actions on Save under Tools.

- Enable Reformat code if its checkbox is clear.
If formatting and functional changes land in separate Git hunks, you can stage them separately.
Related: How to stage part of a file in Git - Click OK to save the setting.

- Place the caret immediately before
1in the assignment in the editor.
- Type six spaces at the caret.

- Press
Ctrl+Sto save the file with the extra spaces.
- Verify that the assignment reads
int count = 1;again, with one space after=.