如何使用JSHint配置Syntastic?

时间:2011-08-29 16:33:02

标签: vim jshint syntastic

如何使用JSHint的Syntastic Vim插件验证JavaScript代码?

环境:

  • Ubuntu 11.04
  • VIM - Vi IMproved 7.3

我在VIM + JSLint?处的解决方案后安装了什么:

  • Vundle
  • 的node.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,但可能缺少某些东西。它会是什么?

3 个答案:

答案 0 :(得分:67)

这是一个更新的信息,有一个配置将文件扩展名与检查器相关联,
.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

答案 1 :(得分:6)

我刚遇到同样的问题。事实证明,Syntastic在查找jshint之前会查找jsl(JSLint)。如果你已经安装了,你可能会被误导。我把jsl移到了不在我的路径中的地方,并且检测到jshint就好了。

来源:
https://github.com/scrooloose/syntastic/pull/47

答案 2 :(得分:0)

我几天来一直在努力解决这个问题,即使我将SyntasticInfo添加到jshintlet g:syntastic_javascript_checkers['jshint']也无法将.vimrc识别为可用的检查程序。我正在使用Ubuntu 15.04,我按照this教程在Ubuntu上安装nvm,nodejs和jshint。在我这样做之后,我发现如果我从filetype plugin indent on删除了行.vimrc,那么打开一个.js文件就会完美无缺!总结一下......

  1. 按照上面链接的教程
  2. ~/.nvm/<version_number>/bin添加到.bashrc
  3. 中的路径
  4. filetype plugin indent on
  5. 中移除.vimrc
  6. let g:syntastic_javascript_checkers['jshint']添加到.vimrc
  7. :so %在vim里面
  8. 打开.js文件
  9. filetype plugin indent on添加回.vimrc
  10. 现在一切都神奇地起作用
相关问题