Intellij Formatter 및 checkstyle plugin 적용 방법 - f-lab-edu/let-s-meet GitHub Wiki

☑️ Intellij Formatter 적용 방법 (naver-intellij-formatter.xml)

1. Scheme 설정

  • setting (preference) -> Editer -> Code Style -> Java 메뉴로 이동

  • Scheme 항목의 오른쪽에 있는 톱니바퀴 아이콘을 클릭한다.

  • Import Scheme -> IntelliJ IDEA Code Style XML 을 선택한다.

  • config/rule-config에 위치한 naver-intellij-formatter.xml 파일 선택 및 적용.

  • 적용

    • TO 항목에는 naver-intellij-formatter.xml 안에 선언된 'Naver-Coding-Convnetion-v1.2’와 같은 이름이 디폴트로 나온다. 이 이름은 IntelliJ에서 전역적인 식별자가 되어서 다른 프로젝트에도 참조가 된다.
    • formatter를 수정하지 않았기 때문에 그대로 사용한다.

2. Save Actions 설정을 통한 자동 수정

  • Scheme 설징이 완료되었다면 Ctrl Alt L 단축키로 작성중인 파일의 formatter를 맞출 수 있다.
  • Save Actions plugin을 사용하면 매번 단축키로 포매터를 적용하지 않고 파일이 저장되는 순간 자동으로 포매터가 적용되도록 할 수 있다.
  • setting (preference) -> Tools -> Actions on Save 메뉴로 이동
  • reformat code (whole file) 와 optimize imports를 체크 해준다

☑️ checkstyle plugin 적용 방법

  • setting (preference) -> Editor -> Plugins 메뉴로 이동
  • CheckStyle-IDEA 설치하고 intelliJ 재시작
  • setting (preference) -> Tools -> Checkstyle 메뉴로 이동
  • gradle.build에 적힌 버전 선택 (현재 적용 버전 10.3.4 )
    • naver-checkstyle-rules.xml을 적용하려면 최소 8.24 이상 버전을 사용해야함
  • treat Checkstyle erros as warnings 체크
  • Configuration File에 ➕ 버튼 클릭
  • browse 버튼 클릭하여 naver-checkstyle-rules.xml 파일 선택
  • Description은 식별할 수 있는 이름으로 설정
    • 공식문서에는 Naver Checkstyle Rules [버전] 를 권장하고 있음
    • 프로젝트별로 커스터마이징 했다면 프로젝트 명을 앞에 붙인다.

  • suppressionsFile value에 naver-checkstyle-suppressions.xml을 입력해준다
    • 원래는 suppressionFile의 경로를 입력해주는 것이 맞다.
    • naver-checkstyle-rules.xml과 같은 경로에 있으므로 파일명만 적어준다.
  • 생성한 checkstyle을 선택하고 apply 버튼을 눌러 적용한다.

checkstyle 사용 방법

  • 하단 bar에 CheckStyle tab을 클릭한다.
  • Rules에 checkstyle을 적용할 Configuration을 지정한다.
  • 왼쪽의 버튼들로 단일 파일, 단일 모듈, 전체 프로젝트의 범위로 스캔할 수 있다.

  • 발견된 warning들은 공식 문서를 확인하여 수정한다.
⚠️ **GitHub.com Fallback** ⚠️