Vim errorformat and jslint

痞子三分冷 提交于 2019-12-09 18:31:57

问题


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:

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. Currently my .vimrc file has

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)...


回答1:


I actually just stuck JSLint into my makeprg earlier today, and naturally I needed some quickfix support.

I created a branch of node-jslint which outputs JSLint's errors in a GCC-like format. The efm is: %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).

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



回答2:


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:

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:

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



回答3:


A very old thread, but this is a follow-up to @dule's excellent answer. 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?):

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:

... 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. For 10...n, no space. A tiny thing, but it means that the quickfix window doesn't work properly for errors 10 and up. 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.)

The second difference is that I replaced %E with %A and the matcher %n with a pattern to ignore that number. This is essentially for aesthetic reasons. Doing it @dule's way, you get this output in the quickfix window:

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:

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.



回答4:


I'm not 100% sure on that version. I used one I downloaded and I just changed the jslint.js source to output it right for me. 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.




回答5:


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:

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. Perhaps this would work:

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


来源:https://stackoverflow.com/questions/3713015/vim-errorformat-and-jslint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!