How to get current coding style & apply to new changes ?

Answered

Some formatting style has been applied to the existing code and there's no clear documentation of the style followed. Is it possible that we could export the current code formatting style and use it for any new changes ? 

0
5 comments

Hi - yes, you can export the current code style and then import it back as needed:

0

Hello ! Thank you for the feedback. This would only export the current settings from the IDE I believe ?

When I re-format the existing code which I checked out from git, the whole formatting changes. What I want to do is to make intellij generate an XML from the existing code format, which is checked out. 

For example :

My current code checked out from git has a method formatted like below. I want to pick this setting and store it as default format setting in intellij.

<Two tabs> public void temp()
                  {

                   }

Currently, when I apply code formatting in intellij, it formats like below, which is very different from the way the code was formatted before. 

<Different spacing> public void temp(){

}

I understand that intellij formats with the settings chosen but what I'm looking for is reverse, to generate a code format setting for intellij from existing code. Is that something , which is possible ?

Thank you

0

This would only export the current settings from the IDE I believe ?

Yes.

You can configure IntelliJ IDEA to automatically detect indents in the current file and use them instead of indents specified in the code style settings.

0

Sorry to come back late on this thread ! 

My intellij is currently set to automatically detect indents as mentioned. All my code blocks in current file is like below,

<Two tabs> public void temp()
                  {

                   }


However, when I create a new method or apply code formatting, it still auto-formats to different format, like below,

<Different spacing> public void temp(){

}

It also changes the formatting of the existing code as well. Can you please help ?

Version : IntelliJ IDEA 2022.3.2 (Ultimate Edition)

0

IntelliJ doesn't support automatic generation of code formatting xml file - from existing source files.
You can use the EditorConfig plugin and its' .editorconfig file to specify custom code formatting for specific project or project folders.
You can create the .editorconfig file in the project root directory and upload it to the VCS. Then, once the project is cloned/checked out, IntelliJ will use the code formatting from the .editorconfig file rather than the one specified in code style settings.
However, you would still need to generate the .editorconfig file and make the needed changes to it, manually.
For more information about EditorConfig check: https://editorconfig.org/

1

Please sign in to leave a comment.