vim - 添加 eslint-ignore 提示的 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
推荐阅读
- java - Spring Boot POST 请求对象几乎具有 Avro 类的所有空字段
- php - 从 php 7.4 迁移到 8(DSO 和实时刷新回显)
- selenium-chromedriver - 使用 Chromedriver (Codeception) 自动关闭离开页面对话框
- javascript - 在位置 0 的 JSON 中条纹意外标记 <
- swiftui - MapKit 使用 SwiftUI 2 显示当前位置(不使用 UIRepresentable)
- java - 理解异常的麻烦:“无法从 START_OBJECT 令牌中反序列化 `java.lang.String` 的实例”在 Jackson 中使用 ObjectMapper
- assembly - 分支和跳转中的地址
- c - C 中的自定义 shell:重定向 I/O
- google-cloud-platform - 将第三方 VPC 与现有 VPC 网络对等互连设置 - GCP
- python - python - 如何在Python中按一列的最大值和另一列的最小值之间的差异按列分组?