如何用JSHint配置Syntastic? [英] How to configure Syntastic with JSHint?

查看:111
本文介绍了如何用JSHint配置Syntastic?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Syntastic Vim插件与JSHint一起使用以验证JavaScript代码?

How to use the Syntastic Vim plugin with JSHint to validate JavaScript code?

环境:

  • Ubuntu 11.04
  • VIM-Vi改进版7.3

按照 VIM + JSLint的解决方案,我已经安装了什么?:

  • Vundle
  • node.js
  • 节点包管理器
  • jshint,全局
  • 通过Vundle安装Syntastic(在Vim中使用了:BundleInstall命令来确保已安装Syntastic.)
  • Vundle
  • node.js
  • Node Package Manager
  • jshint, globally
  • Syntastic installed through Vundle (Used the :BundleInstall command inside Vim to make sure Syntastic was installed.)

.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+=%*

寻找已安装的可执行文件:

looking for installed executables:

$ 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行,应为'===',而是看到了'=='.

test.js: line 3, col 1, 'blbla' is not defined.
test.js: line 4, col 1, 'x' is not defined.
test.js: line 4, col 5, 'nonono' is not defined.
test.js: line 6, col 1, 'a' is not defined.
test.js: line 7, col 1, 'b' is not defined.
test.js: line 8, col 5, 'a' is not defined.
test.js: line 8, col 10, 'b' is not defined.
test.js: line 8, col 7, Expected '===' and instead saw '=='.

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似乎都已安装,但可能缺少某些东西.会是什么?

Both jshint and Syntastic seem to be installed, but something is probably missing. What would it be?

推荐答案

这是更新的信息,这里有将文件扩展名与检查器相关联的配置,
在您的.vimrc

Here is a more updated info, there is a configuration to associate a file extension to a checker,
in your .vimrc

let g:syntastic_javascript_checkers = ['jshint']

还要获取有关正在发生的情况的信息,请在vim中运行此命令

Also to get info about what's going on run this command in vim

:SyntasticInfo

您将获得类似于以下的输出:

And you'll get an output similar to this:

Syntastic info for filetype: javascript  
Available checkers: gjslint jshint  
Currently active checker(s): gjslint  
Press ENTER or type command to continue

这篇关于如何用JSHint配置Syntastic?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆