IT 잡동사니

IntelliJ Google style fomatter를 적용해보자! + 매크로 등록

케키키케 2022. 5. 15. 22:46

코드 작성 시 가독성과 효율성을 위해 fomatter를 적용해보자!

 

아래서 intellij-java-google-style.xml 을 다운받는다.

 

https://github.com/google/styleguide

 

GitHub - google/styleguide: Style guides for Google-originated open-source projects

Style guides for Google-originated open-source projects - GitHub - google/styleguide: Style guides for Google-originated open-source projects

github.com

 

 

File>settings 에서 codestyle로 들어가보자.

톱니바퀴를 눌러서 Import Scheme - IntellJ IDE code style XML 을 눌러서 다운받은 파일을 선택하고 Apply한다.

 

이제 매크로를 생성하자

 

1. Edit - Macros - Start Macro Recording

2. Code - Reformat Code

3. Code - Optimize imports

4. Edit - Macros - Stop Macro Recording

 

 

이제 ShortCut으로 등록해서, Save(Ctrl+s) 할 때 마다 formatter가 자동 적용되도록 매크로를 등록하자.

File-Settings-Keymap-Macros에서 등록한 macro를 선택한다.

그리고 Add Keyboard Shortcut을 선택한다.

 

그리고 Ctrl+S를 눌러주고 OK.

 

기존에 Ctrl+s에 다른 액션이 할당되어 잇는데, 지울거냐고 묻는다.

Remove하고 OK 눌러주면 끝.