How to configure Syntastic with JSHint?

自古美人都是妖i 提交于 2019-12-03 04:54:14

问题


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

Environment:

  • Ubuntu 11.04
  • VIM - Vi IMproved 7.3

What I have installed, following the solution at VIM + JSLint?:

  • 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: 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 errors

$ 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

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


回答1:


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']

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



回答2:


I just had this same problem. Turns out, Syntastic looks for jsl (JSLint) before it looks for jshint. If you have both installed, you'll likely be misled. I moved jsl somewhere not in my PATH, and jshint was detected just fine.

Source:
https://github.com/scrooloose/syntastic/pull/47




回答3:


I struggled with this issue for days and SyntasticInfo would not recognize jshint as an available checker even after i added let g:syntastic_javascript_checkers['jshint'] to my .vimrc. I am using Ubuntu 15.04 and I followed this tutorial to install nvm, nodejs, and jshint on Ubuntu. After I did that I discovered that if I removed the line filetype plugin indent on from my .vimrc then opened a .js file everything worked perfectly! To summarize...

  1. follow the tutorial linked above
  2. add ~/.nvm/<version_number>/bin to path in .bashrc
  3. remove filetype plugin indent on from .vimrc
  4. add let g:syntastic_javascript_checkers['jshint'] to .vimrc
  5. :so % inside vim
  6. open a .js file
  7. add filetype plugin indent on back to your .vimrc
  8. everything magically works now


来源:https://stackoverflow.com/questions/7233005/how-to-configure-syntastic-with-jshint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!