Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Last active Jul 7, 2021
Embed
What would you like to do?
" Use |:RubocopAutocorrect[!]| to autocorrect the current file using Rubocop.
" Note that this will save the file before running the autocorrects. If ! is
" given, it will use unsafe autocorrects.
augroup ruby
autocmd!
autocmd FileType ruby command! -bang RubocopAutocorrect silent! call RubyRubocopAutocorrect(expand('<bang>') == '!')<CR>
augroup END
function! RubyRubocopAutocorrect(unsafe) abort
let flag = a:unsafe ? '-A' : '-a'
write | call system('rubocop ' . flag . ' ' . expand('%:p')) | edit
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment