vim ale 添加 eslint-ignore 提示的快捷方式

标签 vim eslint vim-ale

我已经使用 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/

相关文章:

jenkins - 如何整合 Jenkins 和 Eslint XML 文件?

javascript - esLint如何检测哪个方法 'should be placed after'另一个方法?

javascript - Vim + ALE + eslintrc。在子目录中

vim - 导出变量或注册到文件

VIM 禁用插件的插入映射

vim 颜色方案无法正常显示

python - Vim 和 python - 跳转到定义键绑定(bind)

javascript - React JS - ESLint - 忽略具有 UNSAFE_componentWillMount、UNSAFE_componentWillUpdate 和 UNSAFE_componentWillReceiveProps 的组件的规则