我试图让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)
Run Code Online (Sandbox Code Playgroud)
我基本上想要匹配行号,列和错误,并使用当前文件作为文件名.有人知道怎么做吗?
要清楚,我正在寻找errorformat来使这个命令工作.目前我的.vimrc文件有
augroup js
set makeprg=jslint\ %
set errorformat=%E%>%l,%c:%m,%Z
augroup END
Run Code Online (Sandbox Code Playgroud)
只是不工作(jslint工作正常,但错误格式错误)...
一个旧线程,但对于遇到它的任何人,像我一样:
对于通过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
Run Code Online (Sandbox Code Playgroud)
我正在使用以下efm来解析错误:
autocmd FileType javascript set efm=%-P%f,
\%E%>\ #%n\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
\%-G%f\ is\ OK.,%-Q
Run Code Online (Sandbox Code Playgroud)
一个非常古老的线程,但这是@dule的优秀答案的后续.这真的只是一个调整,但它也可能对其他人有用(花了我一些时间用TFM来解决它,所以为什么不分享?):
setlocal makeprg=jslint\ %
setlocal errorformat=%-P%f,
\%A%>%\\s%\\?#%*\\d\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
\%-G%f\ is\ OK.,%-Q
Run Code Online (Sandbox Code Playgroud)
第三行有两个不同之处.首先,我将单个空间的初始硬编码匹配替换为匹配零个或一个空格的模式(即,使空间可选).我必须这样做,因为以下输出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
Run Code Online (Sandbox Code Playgroud)
仔细看,你会看到它.对于错误1-9,在行的开头有一个空格.对于10 ... n,没有空间.一个小小的东西,但这意味着quickfix窗口无法正常处理错误10及以上.啊.(顺便说一下,我确实考虑过这样的答案:"在任何给定的JS文件中不要超过9个错误,但这似乎有点"尾巴摇尾巴".而且,现在我知道的比我几个小时前做的更多scanf.)
第二个区别是,我取代%E与%A和匹配器%n与一个图案,以忽略该号码.这主要是出于审美原因.这样做@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.
Run Code Online (Sandbox Code Playgroud)
我不想在那里计算错误,我不需要提醒他们都是错误 - 我知道.所以使用%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.
Run Code Online (Sandbox Code Playgroud)
makeprg实际上,我今天早些时候刚刚将 JSLint 插入到我的程序中,自然地我需要一些快速修复支持。
我创建了一个node-jslint分支,它以类似 GCC 的格式输出 JSLint 的错误。是efm:%f:%l:%c:%m。如果您可以使用node.js,我建议使用node-jslint(特别是如果您正在开发node.js/CommonJS项目)。
至于你原来的问题:我认为没有%>必要。如果删除它没有帮助,请尝试以下操作:
set efm=%l,%c: %m
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1312 次 |
| 最近记录: |