如何使用JSHint的Syntastic插件来验证JavaScript代码?
环境:
我所安装的,遵循VIM + JSLint?的解决方案
.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.jstest.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 emptyjshint和Syntastic似乎都已安装,但可能缺少一些东西。那会是什么?
发布于 2013-07-04 11:43:56
下面是更新的信息,有一个将文件扩展名与检查器关联的配置,
在你的.vimrc里
let g:syntastic_javascript_checkers = ['jshint']此外,要获得有关发生了什么的信息,请在vim中运行以下命令
:SyntasticInfo您将得到一个类似于以下内容的输出:
Syntastic info for filetype: javascript
Available checkers: gjslint jshint
Currently active checker(s): gjslint
Press ENTER or type command to continue发布于 2011-12-07 06:27:25
我只是遇到了同样的问题。事实证明,Syntastic在寻找jshint之前先查找jsl (JSLint)。如果两个都安装好了,你很可能会被误导。我把jsl移到了不适合我的地方,jshint被检测到了。
来源:
发布于 2016-02-03 04:49:32
我在这个问题上挣扎了好几天,即使在我将SyntasticInfo添加到jshint中之后,let g:syntastic_javascript_checkers['jshint']也不会承认jshint是可用的检查器。我使用Ubuntu15.04,并按照这教程在Ubuntu上安装nvm、nodejs和jshint。在这样做之后,我发现如果我将行filetype plugin indent on从我的.vimrc中移除,然后打开一个.js文件,一切都很完美!总结一下..。
~/.nvm/<version_number>/bin添加到.bashrc中的路径filetype plugin indent on中删除.vimrclet g:syntastic_javascript_checkers['jshint']添加到.vimrc:so %.js文件filetype plugin indent on添加回.vimrchttps://stackoverflow.com/questions/7233005
复制相似问题