Closure Linter 알아보기

ITWeb/개발일반 2011. 11. 9. 17:06
원래는 javascript 의 정적분석을 위해서 closure inspector 를 사용하려 했으나.. firefox 버전과 firebug 버전을 좀 타서.. 그냥.. 안하기로 했다.
걍.. checkstyle 이나 적용해 봅시다.

Windows 버전임돠!! (cygwin 설치 하셔서 하시면 더 편하실거예요.. )

[참고사이트]
http://code.google.com/intl/ko/closure/utilities/docs/linter_howto.html 
http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml


[다운로드]
http://www.python.org/download/releases/ : version 호환성때문에 2.7 설치함.
http://pypi.python.org/pypi/setuptools#windows (다운로드) : 2.7 설치함. (easy_install)


[설치]
- python 과 setuptools 모두 exe 파일 이므로 실행 시켜서 설치 하시면 됩니다.


[Closure Linter 설치]
- python 이 설치된 폴더로 이동
- Python27\Scripts 로 이동
- cmd 창에서 easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz
- 다운로드가 잘안되거나 에러 발생할 경우 수동으로 다운로드 받아서 아래 처럼 설치
-  
easy_install closure_linter-latest.tar.gz


[gjslint 실행]
- 역시 Python27\Scripts 로 이동
- cmd 창에서 실행
- gjslint D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

C:\Python27\Scripts>gjslint D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

----- FILE  :  D:\Workspace\jee\jsunit_prototype\UnitTC\index.js -----

Line 2, E:0005: Illegal tab in whitespace before "var"

Line 4, E:0005: Illegal tab in whitespace before "if"

Line 5, E:0005: Illegal tab in whitespace before "div.innerHTML"

Line 6, E:0005: Illegal tab in whitespace before "}"

Found 4 errors, including 0 new errors, in 1 files (0 files OK).


Some of the errors reported by GJsLint may be auto-fixable using the script

fixjsstyle. Please double check any changes it makes and report any bugs. The

script can be run by executing:


fixjsstyle D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

- fixjsstyle 을 실행 시켜면 이넘이 수정해 줄수 있는건 자동으로 수정을 해줍니다.
- 위에 보이는 에러는 tab 을 space 4 로 바꾸지 않고 그냥 tab 문자로 사용을 해서 발생한 오류 입니다.
- eclipse 에서 editor 설정과 fomatter 변경 하시면 됩니다.


[compiler 수동실행]

D:\Development>java -jar closure-compiler\compiler.jar --js D:\Workspace\jee\jsunit_prototype\UnitTC\index.js --create_source_map D:\Workspace\jee\jsunit_prototype\UnitTC\index-map --js_output_file D:\Workspace\jee\jsunit_prototype\UnitTC\index-compiled.js

- 이렇게 하면 compiled 된 js 파일이 D:\Workspace\jee\jsunit_prototype\UnitTC\ 경로에 생성 됩니다.

: