Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Last active July 7, 2021 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gosukiwi/3d4f57a8a39048370ad85218befd595d to your computer and use it in GitHub Desktop.
Save gosukiwi/3d4f57a8a39048370ad85218befd595d to your computer and use it in GitHub Desktop.
" 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