如何使用Syntastic Vim插件和JSHint验证JavaScript代码?
环境:
- Ubuntu 11.04
- VIM - Vi IMproved 7.3
我按照 VIM + JSLint? 中的解决方案安装了以下内容:
- Vundle
- node.js
- Node Package Manager
- 全局安装jshint
- 通过Vundle安装Syntastic(在Vim中使用:BundleInstall命令确保已安装Syntastic。)
.vimrc:
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" My Bundles here:
Bundle 'scrooloose/syntastic'
filetype plugin indent on " required!
let g:syntastic_enable_signs=1
let g:syntastic_auto_jump=1
let g:syntastic_stl_format = '[%E{Err: %fe #%e}%B{, }%W{Warn: %fw #%w}]'
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
查找已安装的可执行文件:
$ which gjslint
$ which jslint
$ which jsl
$ which jshint
/home/fernando/local/node/bin/jshint
$
$ echo $PATH
>/home/fernando/local/bin:/home/fernando/local/node/bin:/home/fernando/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ jshint test.js
test.js: 第3行,第1列,“blbla”未定义。
test.js: 第4行,第1列,“x”未定义。
test.js: 第4行,第5列,“nonono”未定义。
test.js: 第6行,第1列,“a”未定义。
test.js: 第7行,第1列,“b”未定义。
test.js: 第8行,第5列,“a”未定义。
test.js: 第8行,第10列,“b”未定义。
test.js: 第8行,第7列,预期为“===”,实际为“==”。共8个错误
$ vi test.js -- no error message shown
:SyntasticEnable -- Vim exits and restarts, opening the same file, but still no message
:w -- still no error message
:Errors -- the location list opens but it is empty
jshint和Syntastic都已安装,但可能缺少某些东西。那是什么呢?