如何使用带有 JSHint 的 Syntastic Vim 插件来验证 JavaScript 代码?
环境:
- Ubuntu 11.04
- VIM - Vi 改进版 7.3
按照VIM + JSLint的解决方案,我安装了什么?:
- 文德尔
- 节点.js
- 节点包管理器
- 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 似乎都已安装,但可能缺少一些东西。那会是什么?