클로저 린터 사용 방법

참고: Closure Linter는 지원 중단되었으며 Google 내에서 더 이상 거의 사용되지 않습니다. 자세한 내용은 이 페이지를 참고하세요.

이 문서에서는 Closure Linter를 설치하고 사용하는 방법을 설명합니다.

Closure Linter 설치

Python pip 유틸리티를 사용하여 Closure Linter를 다운로드하고 설치합니다.

Linux

Linux에 Closure Linter를 설치하려면 다음 명령어를 실행하세요.

$ sudo apt-get install python-pip
$ sudo pip install https://github.com/google/closure-linter/zipball/master

Mac OS X

Mac OS X에 Closure Linter를 설치하려면 다음 명령어를 실행하세요.

$ sudo easy_install pip
$ sudo pip install https://github.com/google/closure-linter/zipball/master

Windows

Windows에 Closure Linter를 설치하려면 다음 단계를 따르세요.

  1. Windows용 Python을 다운로드하고 설치합니다.
  2. 다음 명령어를 실행합니다.
> pip install https://github.com/google/closure-linter/zipball/master

참고: Closure Linter의 Windows 지원은 실험용입니다.

스타일 문제 찾기

단일 파일에서 Closure Linter를 실행하려면 다음을 시도하세요.

$ gjslint path/to/my/file.js

다음과 같은 결과가 나타납니다.

Line 46, E:0110: Line too long (87 characters).
Line 54, E:0214: Missing description in @return tag
Line 66, E:0012: Illegal semicolon after function declaration
Line 150, E:0120: Binary operator should go on previous line "+"
Line 175, E:0011: Missing semicolon after function assigned to a variable
Line 210, E:0121: Illegal comma at end of array literal
Line 220, E:0002: Missing space before ":"

다음과 같이 전체 디렉터리를 재귀적으로 확인할 수도 있습니다.

$ gjslint -r path/to/my/directory

기본적으로 Closure Linter는 올바른 JsDoc 주석이 있는지 확인합니다. 프로젝트에서 누락된 JsDoc 주석을 확인하지 않으려면 다음과 같이 확인을 사용 중지하세요.

$ gjslint --nojsdoc -r path/to/my/directory

이 플래그는 누락된 JsDoc 주석에 대한 검사를 사용 중지하지만 린터는 기존 JsDoc 주석이 올바르게 사용되었는지 여전히 확인합니다.

--strict 플래그

Closure Linter가 공백, JsDoc 유형, 작성자 태그와 같은 스타일 규칙을 더 엄격하게 적용하도록 하려면 --strict 명령줄 플래그를 사용하세요. Closure Library에 코드를 제공하는 경우 --strict를 사용해야 합니다.

스타일 문제 수정

위 명령어에서 gjslint 대신 fixjsstyle를 사용하면 gjslint에서 확인하는 많은 오류를 자동으로 수정할 수 있습니다.

예를 들면 다음과 같습니다.

$ fixjsstyle path/to/file1.js path/to/file2.js

스크립트에서 원치 않는 변경사항이 발생할 수 있으므로 fixjsstyle를 사용하기 전에 파일을 백업하거나 소스 관리 시스템에 저장해야 합니다.