如何在 vim 中进行语法检查?

发布于 2024-12-13 01:21:05 字数 1495 浏览 1 评论 0原文

这个问题已经以这样或那样的形式被问了十几次,令我震惊的是没有一个人真正解决如何配置 syntasticjslint 这样它实际上做了它应该做的事情(它的自述文件完全没用)

请参阅此处

任何人都可以提供一些分步说明,或此类说明的链接。我尝试安装 jslint 和 Spidermonkey,但没有成功。


我设法使语法检查正常工作(感谢 romainl)。我一路上学到的一些东西可能会帮助任何遇到类似问题的人

  1. 要构建 Javascript Lint 寻找README 文件嵌套在 jsl-xxx/src/README.html
  2. 构建指令是 gmake -f Makefile.refgmakemake相同,因此发出命令 sudo ln -s /usr/bin/make /usr/bin/gmake
  3. jsl 现在可以在jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl。要使其普遍可访问,请执行以下操作:ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /home/ForestGump/bin/jsl。更多信息此处
  4. 检查 jsl 是否确实有效找到一个测试文件( 此处),然后发出命令jsl -process test.js。它应该列出所有错误。
  5. 要自定义命令行,请将其添加到 vimrc 文件 set statusline=%{SyntasticStatuslineFlag()}

This question has been asked, in one form or another, a dozen times here, and it blows my mind how not a single one actually addresses how to configure syntastic or jslint such that it actually does what it is supposed to do (its README file is completely useless)

see here

Can anyone provide some step by step instructions, or a link to such instructions. I tried to install jslint and spidermonkey, and I got nowhere.


I managed to get the syntax check to work (thanks to romainl). A few things I learned along the way that may help anyone with a similar problem

  1. To build Javascript Lint look for the README file nested in jsl-x.x.x/src/README.html
  2. The build instructions are gmake -f Makefile.ref but gmake is the same thing as make so issue the command sudo ln -s /usr/bin/make /usr/bin/gmake
  3. jsl will now be found in jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl. To make it generally accessible do something like: ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /home/ForestGump/bin/jsl. More information here
  4. To check that jsl actually works find a test file ( here) then issue the command jsl -process test.js. It should list all the errors.
  5. To customize your command line, add this to your vimrc file set statusline=%{SyntasticStatuslineFlag()}

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

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

发布评论

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

评论(2

七秒鱼° 2024-12-20 01:21:05

你做了什么?什么有效,什么无效?您收到错误消息吗?

这就是我所做的:

  1. JavaScript Lint 站点 下载 jsl 源代码。
  2. 构建 jsl 并将其移至我的 $PATH 中的某个位置。
  3. 通过对随机 .js 文件运行来检查它是否有效
  4. 下载并安装 Syntastic 作为 病原体束。
  5. 输入 :helptags /path/to/syntastic/doc 因为由于某种原因 Pathogen 的自动帮助标签生成对我不起作用。
  6. 阅读 Syntastic 的文档::help syntastic

步骤 1 到 5 花费的时间不会超过 3 或 4 分钟,甚至可能更少。

无论您尝试什么新工具,第 6 步都是强制性的。 RTFM。

除了我的 .vimrc 中的这三行之外,我不需要配置任何内容(我相信第三行是多余的):

let g:syntastic_auto_loc_list=1
let g:syntastic_disabled_filetypes=['html']
let g:syntastic_enable_signs=1

并使用以下命令自定义我的状态行:

%{SyntasticStatuslineFlag()}

编辑

这是我的状态行:

set statusline=%<\ %n:%f\ %m%r%y%{SyntasticStatuslineFlag()}%=line:\ %l\ of\ %L,\ col:\ %c%V,\ win:\ %{WindowNumber()}\ 

不要逐字复制它,否则你会由于最后的函数调用而出现一些错误。 Syntastic 的帮助中有一段关于此内容的内容。

结束编辑

毕竟,如果您算上阅读文档,需要 10 或 12 分钟,每次我保存带有语法错误的 .js 文件时,我都会弹出一个非常有用的位置列表和标志。

What did you do? What works and what doesn't? Do you get error messages?

Here is what I did:

  1. Downloaded the jsl sources from the JavaScript Lint site.
  2. Built jsl and moved it somewhere in my $PATH.
  3. Checked if it worked by running it against a random .js file
  4. Downloaded and installed Syntastic as a Pathogen bundle.
  5. Typed :helptags /path/to/syntastic/doc because for some reason Pathogen's automatic help tags generation doesn't work for me.
  6. Read Syntastic's documentation: :help syntastic.

Steps 1 to 5 didn't take more than 3 or 4 minutes, maybe less.

Step 6 is obligatory, whatever new tool you try. RTFM.

I didn't have to configure anything beside these 3 lines in my .vimrc (and I believe the third is redundant):

let g:syntastic_auto_loc_list=1
let g:syntastic_disabled_filetypes=['html']
let g:syntastic_enable_signs=1

and customizing my statusline a bit with:

%{SyntasticStatuslineFlag()}

EDIT

Here is my statusline:

set statusline=%<\ %n:%f\ %m%r%y%{SyntasticStatuslineFlag()}%=line:\ %l\ of\ %L,\ col:\ %c%V,\ win:\ %{WindowNumber()}\ 

Don't copy it verbatim or you'll get some errors due to the function call at the end. There is a paragraph about that in syntastic's help.

END EDIT

After all that, 10 or 12 minutes if you count reading the documentation, I have a very helpful location list and signs poping up each time I save a .js file with syntax errors.

堇色安年 2024-12-20 01:21:05

根据其 README 设置 vundle。

将其放入您的 .vimrc:

Bundle 'scrooloose/syntastic'

然后在 vim 中输入此命令:

:BundleInstall

就是这样。

编辑:自从我最初写这篇文章以来,Vundle 已经改变了它的语法。如今,您使用

Plugin 'scrooloose/syntastic'

然后输入

:PluginInstall

Setup vundle according to its README.

Put this into your .vimrc:

Bundle 'scrooloose/syntastic'

Then enter this command in vim:

:BundleInstall

That's it.

EDIT: Vundle has changed its syntax since I originally wrote this. Nowadays, you use

Plugin 'scrooloose/syntastic'

and then enter

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