在 Notepad++ 运行 Closure Linter 来校验JS代码
时间:2010-11-27 来源:George Wing
Closure Linter是在Python上运行的,所以先在系统中配置安装Python的运行环境:
- 安装 Python。本人安装的版本为 Python 2.5.4
- 安装 Easy Install 模块。也就是要安装 setuptools windows下本人安装的为: setuptools-0.6c11.win32-py2.5.exe
- 确保 Easy Install 配置到Path环境变量。
然后,在命令行中执行如下命令:
easy_install E:\closure_linter\closure_linter-2-1.2.6.tar.gz
如果出现啪啦啪啦如下的截图画面:
则说明Closure Linter 安装成功!OK,在Notepad++ 的NppExec执行如下命令:
gjslint –strict $(FULL_CURRENT_PATH)
可以将这个命令保存为 Closure Linter。点击“OK”试试,如果在控制台窗口输出如下结果:
gjslint –strict D:\work\js\WOYO\event.js Process started >>> ----- FILE : D:\work\js\WOYO\event.js ----- Line 3, E:0217: Missing @return JsDoc in function with non-trivial return Line 4, E:0002: Missing space before "{" Line 5, E:0005: Illegal tab in whitespace before "if" Line 5, E:0002: Missing space before "(" Line 6, E:0005: Illegal tab in whitespace before "return" Line 7, E:0005: Illegal tab in whitespace before "}" Line 8, E:0005: Illegal tab in whitespace before "else" Line 8, E:0002: Missing space before "(" Line 9, E:0005: Illegal tab in whitespace before "var" Line 9, E:0002: Missing space before "=" Line 9, E:0002: Missing space before "[" Line 9, E:0131: Single-quoted string preferred over double-quoted string. Line 9, E:0131: Single-quoted string preferred over double-quoted string. Line 9, E:0131: Single-quoted string preferred over double-quoted string. Line 10, E:0005: Illegal tab in whitespace before " " Line 10, E:0001: Extra space at end of line Line 11, E:0005: Illegal tab in whitespace before "for" Line 11, E:0002: Missing space before "(" Line 11, E:0002: Missing space before "=" Line 11, E:0002: Missing space after "=" Line 11, E:0002: Missing space before "
则说明JS代码已经被 Closure Linter工具校验。居然这么多 bug!不过,修复 bug 也可以利用工具来完成,哈哈!执行如下的命令即可:
fixjsstyle –strict $(FULL_CURRENT_PATH)
在Console窗口中显示的结果:
fixjsstyle –strict D:\work\js\WOYO\event.js Process started >>> Fixed 44 errors in D:\work\js\WOYO\event.js
(完)
相关阅读 更多 +