简体   繁体   English

Syntastic不会将JSHint检测为可用的检查程序

[英]Syntastic doesn't detect JSHint as an available checker

I have installed Syntastic with Pathogen. 我已经安装了Syntastic with Pathogen。

Syntastic works for Python files but not for JavaScript files with JSHint. Syntastic适用于Python文件,但不适用于JSHint的JavaScript文件。 JSHint works via command line or with other vim plugin like https://github.com/Shutnik/jshint2.vim JSHint通过命令行或其他vim插件工作,如https://github.com/Shutnik/jshint2.vim

→ which jshint  
/usr/local/share/npm/bin/jshint

→ jshint --version
jshint v2.1.10

→ echo $PATH
/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

When I run :SyntasticInfo, it doesn't find any checkers. 当我运行:SyntasticInfo时,它没有找到任何检查器。

Syntastic info for filetype: javascript
Available checkers:
Currently active checker(s):

My vimrc 我的vimrc

set nocompatible
filetype off
call pathogen#infect()
call pathogen#helptags()
filetype plugin indent on
syntax on

let g:syntastic_check_on_open=1
let g:syntastic_javascript_checkers = ['jshint']

I don't know what I've missed, if you have any idea why Syntastic doesn't detect JSHint. 如果你知道为什么Syntastic没有检测到JSHint,我不知道我错过了什么。 Thanks 谢谢

Long story short; 长话短说; Syntastic needs the path of jshint. Syntastic需要jshint的路径。


I encountered a similar problem on Windows 8. After installing nodejs v0.10.22 and syntastic >= 3.2.0, the Vim command :SyntasticInfo would give me: 我在Windows 8上遇到了类似的问题。安装nodejs v0.10.22和syntastic > = 3.2.0后,Vim命令:SyntasticInfo会给我:

Syntastic: active mode enabled
Syntastic info for filetype: vim
Available checker(s): 
Currently enabled checker(s):

The documentation over at jshint.com/docs suggests that this is sufficient to install the module. jshint.com/docs上的文档表明这足以安装模块。

$ npm install jshint -g

This is true, apart from a somewhat surprising meaning of flag -g installs JSHint globally on your system . 这是事实,除了标志的一些令人惊讶的含义-g在您的系统上全局安装JSHint It means in your user's %AppData% folder: 这意味着在您的用户的%AppData%文件夹中:

(abbreviated output from previous command)
C:\Users\jaroslav\AppData\Roaming\npm\jshint -> \
C:\Users\jaroslav\AppData\Roaming\npm\node_modules\jshint\bin\jshint
jshint@2.3.0 C:\Users\jaroslav\AppData\Roaming\npm\node_modules\jshint
├── console-browserify@0.1.6
├── underscore@1.4.4
├── shelljs@0.1.4
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.5.0)
└── cli@0.4.5 (glob@3.2.7)

Another piece of documentation from the syntastic FAQ reads: 来自语法常见问题解答的另一篇文档如下:

Q. I installed syntastic but it isn't reporting any errors... 问:我安装了syntastic但它没有报告任何错误......

A. The most likely reason is that none of the syntax checkers that it requires is installed. :最可能的原因是它没有安装所需的语法检查程序。 For example: python requires either flake8, pyflakes or pylint to be installed and in $PATH. 例如:python需要安装flake8,pyflakes或pylint,并且需要安装在$ PATH中。 To see which executables are supported, just look in syntax_checkers//*.vim. 要查看支持哪些可执行文件,请查看syntax_checkers // * .vim。 Note that aliases do not work; 请注意,别名不起作用; the actual executable must be available in your $PATH. 必须在$ PATH中提供实际的可执行文件。 Symbolic links are okay. 符号链接没问题。 You can see syntastic's idea of available checkers by running :SyntasticInfo. 您可以通过运行SyntasticInfo来查看syntastic对可用检查器的想法。

The solution amounts to setting the path of the jshint command in ~/.vimrc: 解决方案相当于在〜/ .vimrc中设置jshint命令的路径:

 let g:syntastic_jshint_exec='C:\Users\jaroslav\AppData\Roaming\npm\jshint.cmd'

:source $HOME/_vimrc
:SyntasticInfo
Syntastic: active mode enabled
Syntastic info for filetype: javascript
Available checker(s): jshint
Currently enabled checker(s): jshint

Alternatively, one could: 或者,人们可以:

> cmd.exe
> cd C:\Users\jaroslav\AppData\Roaming\npm
> setx PATH "%cd%:%PATH%"

and let g:syntastic_jshint_exec='jshint.cmd' . 并且let g:syntastic_jshint_exec='jshint.cmd' I didn't try the last solution with %PATH% because Winders doesn't like long %PATH% variables. 我没有尝试使用%PATH%的最后一个解决方案,因为Winders不喜欢long%PATH%变量。

Hopefully this saves you some time. 希望这可以为您节省一些时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM