简体   繁体   English

Vim errorformat和jslint

[英]Vim errorformat and jslint

I am trying to get makeprg and errorformat working with VIM and jslint, and can't seem to get the error format right for the life of me... I am using the nodejs version of jslint which produces results like: 我试图让makeprg和errorformat使用VIM和jslint,并且似乎无法获得正确的错误格式...我正在使用jslint的nodejs版本,它产生的结果如下:

1 116,9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
    for (var k in o)

I basically want to match the line number, and column and the error and use the current file for the filename. 我基本上想要匹配行号,列和错误,并使用当前文件作为文件名。 Anyone know how to do this? 有人知道怎么做吗?

To be clear, I am looking for the errorformat to get this command working. 要清楚,我正在寻找errorformat来使这个命令工作。 Currently my .vimrc file has 目前我的.vimrc文件有

augroup js
    set makeprg=jslint\ %
    set errorformat=%E%>%l,%c:%m,%Z
augroup END

which just isn't working (the jslint works fine, but the errorformat is wrong)... 只是不工作(jslint工作正常,但错误格式错误)...

An old thread, but for anyone coming across it, like myself: 一个旧线程,但对于遇到它的任何人,像我一样:

For the current version of node-jslint installed through npm (v0.1.2), the error output looks like the following: 对于通过npm(v0.1.2)安装的当前版本的node-jslint,错误输出如下所示:

filename.js
 #1 Missing 'use strict' statement.
    y = x // Line 2, Pos 3
 #2 Expected 'y' at column 5, not column 3.
    y = x // Line 2, Pos 3

I'm using the following efm to parse the errors: 我正在使用以下efm来解析错误:

autocmd FileType javascript set efm=%-P%f,
                    \%E%>\ #%n\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
                    \%-G%f\ is\ OK.,%-Q

A very old thread, but this is a follow-up to @dule's excellent answer . 一个非常古老的线程,但这是@dule的优秀答案的后续。 It's really just a tweak, but it may be useful to others also (took me some time with TFM to work it out, so why not share?): 这真的只是一个调整,但它也可能对其他人有用(花了我一些时间用TFM来解决它,所以为什么不分享?):

setlocal makeprg=jslint\ %
setlocal errorformat=%-P%f,
                    \%A%>%\\s%\\?#%*\\d\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
                    \%-G%f\ is\ OK.,%-Q

There are two differences, both in the third line. 第三行有两个不同之处。 First, I replace the initial hard-coded match of a single space with a pattern that matches zero or one space (ie, makes the space optional). 首先,我将单个空间的初始硬编码匹配替换为匹配零个或一个空格的模式(即,使空间可选)。 I had to do this, because of the following output from jslint : 我必须这样做,因为jslint的以下输出:

... First 8 errors trimmed
 #9 Expected '$' at column 9, not column 7.
    $('img#placeholder').attr('src', pic); // Line 15, Pos 7
#10 Expected '$' at column 9, not column 7.
    $('img#placeholder').attr('alt', desc) // Line 16, Pos 7

Look very closely, and you'll see it. 仔细看,你会看到它。 For errors 1-9, there is a space at the start of the line. 对于错误1-9,在行的开头有一个空格。 For 10...n, no space. 对于10 ... n,没有空间。 A tiny thing, but it means that the quickfix window doesn't work properly for errors 10 and up. 一个小小的东西,但这意味着quickfix窗口无法正常处理错误10及以上。 Ugh. 啊。 (Btw, I did consider the answer "Don't make more than 9 errors in any given JS file, but that seemed a little too "tail wagging the dog". Also, now I know more than I did a few hours ago about scanf .) (顺便说一下,我确实考虑过这样的答案:“在任何给定的JS文件中不要超过9个错误,但这似乎有点”尾巴摇尾巴“。而且,现在我知道的比我几个小时前做的更多scanf 。)

The second difference is that I replaced %E with %A and the matcher %n with a pattern to ignore that number. 第二个区别是我将%E替换为%A ,将匹配器%n替换为忽略该数字的模式。 This is essentially for aesthetic reasons. 这主要是出于审美原因。 Doing it @dule's way, you get this output in the quickfix window: 这样做@dule的方式,你在quickfix窗口中得到这个输出:

showPic.js|5 col 7 error   1| Expected 'event' at column 9, not column 7.
showPic.js|9 col 7 error   2| Expected 'var' at column 9, not column 7.

I don't want a count of errors there, and I don't need the reminder that they're all errors - I know that. 我不想在那里计算错误,我不需要提醒他们都是错误 - 我知道。 So using %A , you get this simpler output: 因此,使用%A ,您可以获得更简单的输出:

showPic.js|5 col 7| Expected 'event' at column 9, not column 7.
showPic.js|9 col 7| Expected 'var' at column 9, not column 7.

I actually just stuck JSLint into my makeprg earlier today, and naturally I needed some quickfix support. 我实际上今天早些时候刚刚将JSLint卡入我的makeprg ,自然我需要一些quickfix支持。

I created a branch of node-jslint which outputs JSLint's errors in a GCC-like format. 我创建了一个node-jslint的分支,它以类似GCC的格式输出JSLint的错误。 The efm is: %f:%l:%c:%m . efm为: %f:%l:%c:%m If you can use node.js, I recommend using node-jslint (especially if you're working on a node.js/CommonJS project). 如果你可以使用node.js,我建议使用node-jslint(特别是如果你正在使用node.js / CommonJS项目)。

As for your original problem: I don't think %> is necessary. 至于你原来的问题:我不认为%>是必要的。 If removing that doesn't help, try simply the following: 如果删除无效,请尝试以下操作:

set efm=%l,%c: %m

I'm not 100% sure on that version. 我不是100%肯定该版本。 I used one I downloaded and I just changed the jslint.js source to output it right for me. 我使用了我下载的一个,我刚刚更改了jslint.js源代码以便为我输出。 My line looks something like. 我的行看起来像。

var i=0;i<JSLINT.errors.length;i+=1){var e=JSLINT.errors[i];if(e){print(a[0]+':'+e.line+':'+e.reason);

Hope that can help get you close to getting a format working. 希望这可以帮助您接近使格式正常工作。

I've never used this option before, but the examples in help seem to indicate there should be an extra %m at the end of your pattern, or maybe you just need to escape the comma: 我以前从未使用过这个选项,但是帮助中的示例似乎表明模式末尾应该有一个额外的%m ,或者你只需​​要转义逗号:

set errorformat=%E%>%l\\,%c:%m,%Z%m

Update: Actually there seems to be two numbers in your error string, 1 followed by a space, then 116 . 更新:实际上你的错误字符串中似乎有两个数字, 1后跟一个空格,然后是116 Perhaps this would work: 也许这会奏效:

set errorformat=%E%>%n\\ %l\\,%c:%m,%Z%m

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

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