How to use the Syntastic Vim plugin with JSHint to validate JavaScript code?
如何使用JSHint的Syntastic Vim插件来验证JavaScript代码?
Environment:
环境:
- Ubuntu 11.04
- Ubuntu 11.04
- VIM - Vi IMproved 7.3
- VIM - Vi改进了7.3。
What I have installed, following the solution at VIM + JSLint?:
我在VIM + JSLint的解决方案下安装了什么?
- Vundle
- Vundle
- node.js
- node . js
- Node Package Manager
- 节点包管理器
- jshint, globally
- jshint,全球
- Syntastic installed through Vundle (Used the :BundleInstall command inside Vim to make sure Syntastic was installed.)
- 通过Vundle安装Syntastic(使用:Vim内的BundleInstall命令以确保安装了Syntastic)。
.vimrc:
. 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 '=='.测试。第3行,第1行,“blbla”没有定义。测试。第4行,第1行,'x'没有定义。测试。第4行,第5行,“nonono”没有定义。测试。第6行,第1行,'a'没有定义。测试。第7行,第1行,'b'没有定义。测试。第8行,第5行,“a”没有定义。测试。第8行,第10行,'b'没有定义。测试。js:第8行,第7行,预期'==',改为'= '。
8 errors
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
Both jshint and Syntastic seem to be installed, but something is probably missing. What would it be?
jshint和Syntastic似乎都安装了,但可能缺少了一些东西。那会是什么?
3 个解决方案
#1
65
Here is a more updated info, there is a configuration to associate a file extension to a checker,
in your .vimrc
这里有一个更新的信息,有一个配置,可以将文件扩展名关联到一个检查器,在您的.vimrc中。
let g:syntastic_javascript_checkers = ['jshint']
Also to get info about what's going on run this command in vim
还要了解在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
6
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.
我也有同样的问题。原来,jsl (JSLint)在寻找jshint之前,要寻找Syntastic。如果你都安装了,你可能会被误导。我移动了jsl,而不是在我的路径中,jshint被检测到很好。
Source:
https://github.com/scrooloose/syntastic/pull/47
来源:https://github.com/scrooloose/syntastic/pull/47
#3
0
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...
我在这个问题上花了好几天的时间,而SyntasticInfo甚至在我添加了让g:syntastic_javascript_checkers['jshint']到my .vimrc之后,也不承认jshint是一个可用的检查器。我使用Ubuntu 15.04,我跟随本教程安装了nvm、nodejs和jshint。在我做了这个之后,我发现如果我从我的.vimrc上删除了line filetype插件,那么打开一个.js文件,一切都很顺利!总结……
- follow the tutorial linked above
- 遵循上面的教程链接。
- add
~/.nvm/<version_number>/bin
to path in.bashrc
-
添加~ /。nvm/
/bin to path in .bashrc。 - remove
filetype plugin indent on
from.vimrc
- 从.vimrc删除文件类型插件。
- add
let g:syntastic_javascript_checkers['jshint']
to.vimrc
- 添加让g:syntastic_javascript_checkers['jshint']到.vimrc。
-
:so %
inside vim - 所以在vim %
- open a
.js
file - 打开一个. js文件
- add
filetype plugin indent on
back to your.vimrc
- 在你的。vimrc上添加文件类型插件。
- everything magically works now
- 现在一切都神奇地工作
#1
65
Here is a more updated info, there is a configuration to associate a file extension to a checker,
in your .vimrc
这里有一个更新的信息,有一个配置,可以将文件扩展名关联到一个检查器,在您的.vimrc中。
let g:syntastic_javascript_checkers = ['jshint']
Also to get info about what's going on run this command in vim
还要了解在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
6
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.
我也有同样的问题。原来,jsl (JSLint)在寻找jshint之前,要寻找Syntastic。如果你都安装了,你可能会被误导。我移动了jsl,而不是在我的路径中,jshint被检测到很好。
Source:
https://github.com/scrooloose/syntastic/pull/47
来源:https://github.com/scrooloose/syntastic/pull/47
#3
0
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...
我在这个问题上花了好几天的时间,而SyntasticInfo甚至在我添加了让g:syntastic_javascript_checkers['jshint']到my .vimrc之后,也不承认jshint是一个可用的检查器。我使用Ubuntu 15.04,我跟随本教程安装了nvm、nodejs和jshint。在我做了这个之后,我发现如果我从我的.vimrc上删除了line filetype插件,那么打开一个.js文件,一切都很顺利!总结……
- follow the tutorial linked above
- 遵循上面的教程链接。
- add
~/.nvm/<version_number>/bin
to path in.bashrc
-
添加~ /。nvm/
/bin to path in .bashrc。 - remove
filetype plugin indent on
from.vimrc
- 从.vimrc删除文件类型插件。
- add
let g:syntastic_javascript_checkers['jshint']
to.vimrc
- 添加让g:syntastic_javascript_checkers['jshint']到.vimrc。
-
:so %
inside vim - 所以在vim %
- open a
.js
file - 打开一个. js文件
- add
filetype plugin indent on
back to your.vimrc
- 在你的。vimrc上添加文件类型插件。
- everything magically works now
- 现在一切都神奇地工作