Auto format in IntelliJ IDEA?

Hello Idea community

After updating to Idea Ultimate 11.1.2 a couple of my Eclipse colleagues complains about some formatting issues (white spaces) not related with the change I did made.
In Eclipse there is an option to format only the modified code. Till 11.1.2 I had the impression the IntelliJ does the same, but know I am not so sure.
I've searched for an auto-format on save preferences in IntelliJ but I didn't find them.

Questions:
- Does the IntelliJ automatically format the code on save (or I have to create a macro)?
- If so, does it only format the changed code?
- Is there an option to customize the auto-format options (1. on save, 2. only changes)?

Thank you in advance.

4 comments
Comment actions Permalink

There is no "Autoformat on save" option, since save is performed implicitly in IntelliJ IDEA, and we don't use it as a way to trigger actions. There is a "Reformat on commit" option, though.

The formatting affects the entire file; there is no option to format only the modified code.

0
Comment actions Permalink

Hi Antonel,

  • IJ doesn't perform automatic reformat on file save;
  • IJ perform automatic reformat on commit if corresponding option is set:
    commit.png
  • IJ reformats only the changed regions (in term of VCS) if corresponding option is set:
    reformat.png


Denis

1
Comment actions Permalink

Thank you Denis

IJ reformats only the changed regions (in term of VCS) if corresponding option is set:


I did follow the next steps:

  1. commited a groovy file on a Git repo and I checked out the Reformat Code option in Commit Changes. Note: The Reformat Code popup does't appear.
  2. checked through Show History that the code was reformated (OK),
  3. closed the groovy file in IntelliJ editor;
  4. unformated code at the begining of the file in gedit;
  5. commit to git;
  6. open the file in IntelliJ editor and unformat the code at the end of the file;
  7. commit with intelliJ and marked Reformat Code;
  8. checked if only the changed code is reformated using Git history, but all file is reformated  


I've search the Idea preferences to see if there is a settings about showing that reformat dialog but I found only the Editor>Show "Reformat Code Editor" dialog option which is checked, but I think this is for regular call of the Reformat Code.

Is this an issue or I am skipped smth in Commit steps?


Thank you in advance.

0
Comment actions Permalink

IJ doesn't offer to reformat only changed code on commit at the moment. I.e. the 'reformat only changed text' facility is offered only on explicit 'Reformat' action call. 'Reformat on commit' doesn't show any dialog - that is by design.

Denis

0

Please sign in to leave a comment.