Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usability "upgrades" #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
50 changes: 32 additions & 18 deletions plugin/rubocop.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ if !exists('g:vimrubocop_keymap')
let g:vimrubocop_keymap = 1
endif

let s:rubocop_switches = ['-l', '--lint', '-R', '--rails', '-a', '--auto-correct']
let s:rubocop_switches = ['-D', '--display-cop-names', '-l', '--lint', '-R', '--rails', '-a', '--auto-correct']

function! s:RuboCopSwitches(...)
return join(s:rubocop_switches, "\n")
endfunction

function! s:RuboCop(current_args)
if &modified
echohl WarningMsg
echo 'RuboCop: Buffer has unsaved changes'
echohl None
return
endif

let l:extra_args = g:vimrubocop_extra_args
let l:filename = @%
let l:rubocop_cmd = g:vimrubocop_rubocop_cmd
Expand All @@ -48,27 +55,34 @@ function! s:RuboCop(current_args)
endif

let l:rubocop_output = system(l:rubocop_cmd.l:rubocop_opts.' '.l:filename)
if !empty(matchstr(l:rubocop_opts, '--auto-correct\|-\<a\>'))
"Reload file if using auto correct
edit
endif
let l:auto_corrected = !empty(matchstr(l:rubocop_opts, '--auto-correct\|-\<a\>'))
let l:rubocop_output = substitute(l:rubocop_output, '\\"', "'", 'g')
let l:rubocop_results = split(l:rubocop_output, "\n")
cexpr l:rubocop_results
copen
" Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git
exec "nnoremap <silent> <buffer> q :ccl<CR>"
exec "nnoremap <silent> <buffer> t <C-W><CR><C-W>T"
exec "nnoremap <silent> <buffer> T <C-W><CR><C-W>TgT<C-W><C-W>"
exec "nnoremap <silent> <buffer> o <CR>"
exec "nnoremap <silent> <buffer> go <CR><C-W><C-W>"
exec "nnoremap <silent> <buffer> h <C-W><CR><C-W>K"
exec "nnoremap <silent> <buffer> H <C-W><CR><C-W>K<C-W>b"
exec "nnoremap <silent> <buffer> v <C-W><CR><C-W>H<C-W>b<C-W>J<C-W>t"
exec "nnoremap <silent> <buffer> gv <C-W><CR><C-W>H<C-W>b<C-W>J"
if len(l:rubocop_results) && !l:auto_corrected
cexpr l:rubocop_results
botright copen
" Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git
exec "nnoremap <silent> <buffer> q :ccl<CR>"
exec "nnoremap <silent> <buffer> t <C-W><CR><C-W>T"
exec "nnoremap <silent> <buffer> T <C-W><CR><C-W>TgT<C-W><C-W>"
exec "nnoremap <silent> <buffer> o <CR>"
exec "nnoremap <silent> <buffer> go <CR><C-W><C-W>"
exec "nnoremap <silent> <buffer> h <C-W><CR><C-W>K"
exec "nnoremap <silent> <buffer> H <C-W><CR><C-W>K<C-W>b"
exec "nnoremap <silent> <buffer> v <C-W><CR><C-W>H<C-W>b<C-W>J<C-W>t"
exec "nnoremap <silent> <buffer> gv <C-W><CR><C-W>H<C-W>b<C-W>J"
elseif l:auto_corrected " Reload file if using auto correct
silent edit
echo 'RuboCop: Auto-corrected!'
else
echo 'RuboCop: No violations!'
endif
endfunction

command! -complete=custom,s:RuboCopSwitches -nargs=? RuboCop :call <SID>RuboCop(<q-args>)
augroup RuboCop
autocmd!
autocmd FileType ruby command! -buffer -complete=custom,s:RuboCopSwitches -nargs=? RuboCop :call <SID>RuboCop(<q-args>)
augroup END

" Shortcuts for RuboCop
if g:vimrubocop_keymap == 1
Expand Down