我已经使用 vim 多年了,但我刚刚开始集成 eslint(通过 ALE )。我发现有时我希望能够快速添加 /* eslint-ignore-next-line */
。例如:
...
❌ if (m = /^-l(\d+)$/.exec(args[i])) t.len = m[1];
...
~/some/dir/file.js [+]
cond-assign: Expected a conditional expression and instead saw an assignment.
ALE 在窗口底部为您提供代码确实很方便,但由于懒惰,我想自动添加注释/提示:
/* eslint-ignore-next-line cond-assign */
有没有办法在 vim 脚本/函数中访问屏幕底部的信息?
最佳答案
尽管没有记录,ALE 将 lint 信息存储在 b:ale_highlight_items
变量中。
David784 的解决方案对我不起作用,因为我使用 ALE 的 g:ale_echo_msg_format
配置选项自定义了位置列表文本。因此我对其进行了修改,直接从 b:ale_highlight_items
获取信息,而不是从位置列表中解析它。
这里是:
command! ALEIgnoreEslint call AleIgnoreEslint()
function! AleIgnoreEslint()
" https://stackoverflow.com/questions/54961318/vim-ale-shortcut-to-add-eslint-ignore-hint
let l:codes = []
if (!exists('b:ale_highlight_items'))
echo 'cannot ignore eslint rule without b:ale_highlight_items'
return
endif
for l:item in b:ale_highlight_items
if (l:item['lnum']==line('.') && l:item['linter_name']=='eslint')
let l:code = l:item['code']
call add(l:codes, l:code)
endif
endfor
if len(l:codes)
exec 'normal O/* eslint-disable-next-line ' . join(l:codes, ', ') . ' */'
endif
endfunction
关于vim ale 添加 eslint-ignore 提示的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54961318/