如何使用 JSHint 配置 Syntastic?

发布于 2024-12-02 02:51:55 字数 2030 浏览 2 评论 0原文

如何使用 Syntastic Vim 插件和 JSHint 来验证 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 似乎都已安装,但可能缺少某些内容。会是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

昔日梦未散 2024-12-09 02:51: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

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
夏の忆 2024-12-09 02:51:56

我刚刚遇到了同样的问题。事实证明,Syntastic 在查找 jshint 之前先查找 jsl (JSLint)。如果两者都安装了,您可能会被误导。我将 jsl 移动到不在我的 PATH 中的某个位置,并且 jshint 被检测到很好。

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

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

原谅过去的我 2024-12-09 02:51:56

我为这个问题苦苦挣扎了好几天,即使在我添加了 let g:syntastic_javascript_checkers['jshint']SyntasticInfo 也无法将 jshint 识别为可用的检查器> 到我的 .vimrc。我使用的是 Ubuntu 15.04,我按照这个教程安装 nvm, Ubuntu 上的 Nodejs 和 jshint。这样做之后,我发现如果我从 .vimrc 中删除 filetype plugin indent on 行,然后打开 .js 文件,一切都会完美运行!总结一下...

  1. 按照上面链接的教程
  2. ~/.nvm//bin 添加到 .bashrc 中的路径
  3. 删除文件类型插件缩进< /code> 从 .vimrc
  4. 添加 let g:syntastic_javascript_checkers['jshint'].vimrc
  5. :so %在 vim 里面
  6. 打开 .js 文件,
  7. filetype 插件缩进 添加回您的 .vimrc
  8. 现在一切都神奇地起作用了

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文