From 2037d2bf1d24f036926534700c08d4c3a7686229 Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 19:51:43 -0400 Subject: [PATCH 1/8] Do not open QF window when there are no violations --- plugin/rubocop.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index 2d98d4e..78c047e 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -54,8 +54,12 @@ function! s:RuboCop(current_args) endif let l:rubocop_output = substitute(l:rubocop_output, '\\"', "'", 'g') let l:rubocop_results = split(l:rubocop_output, "\n") - cexpr l:rubocop_results - copen + if len(l:rubocop_results) + cexpr l:rubocop_results + copen + else + echo 'RuboCop: No violations!' + endif " Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git exec "nnoremap q :ccl" exec "nnoremap t T" From ee037112426e03bc71799695243dcdc2511aa312 Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 21:00:23 -0400 Subject: [PATCH 2/8] Be less noisy when auto-correcting --- plugin/rubocop.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index 78c047e..ec7fd9a 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -48,15 +48,16 @@ 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\|-\')) - "Reload file if using auto correct - edit - endif + let l:auto_corrected = !empty(matchstr(l:rubocop_opts, '--auto-correct\|-\')) let l:rubocop_output = substitute(l:rubocop_output, '\\"', "'", 'g') let l:rubocop_results = split(l:rubocop_output, "\n") - if len(l:rubocop_results) + if len(l:rubocop_results) && !l:auto_corrected cexpr l:rubocop_results copen + elseif l:auto_corrected " Reload file if using auto correct + edit + redraw + echo 'RuboCop: Auto-corrected!' else echo 'RuboCop: No violations!' endif From e051b3e912679495836fd22cc014e2f05abb61dc Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 21:17:07 -0400 Subject: [PATCH 3/8] Refuse to run if buffer is modified --- plugin/rubocop.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index ec7fd9a..447b5f9 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -39,6 +39,13 @@ function! s:RuboCopSwitches(...) 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 From 38b5dfb09ea5ff5425cd7a6fcba05ff477f668bd Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 21:31:00 -0400 Subject: [PATCH 4/8] Only define RuboCop command for ruby buffers This is a consideration that I always appreciate from plugins. If someone happens to have a command that starts with `Ru` that they use with other filetypes, they can continue to simple type `:Ru` in those buffers. --- plugin/rubocop.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index 447b5f9..bdd084a 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -80,7 +80,10 @@ function! s:RuboCop(current_args) exec "nnoremap gv HbJ" endfunction -command! -complete=custom,s:RuboCopSwitches -nargs=? RuboCop :call RuboCop() +augroup RuboCop + autocmd! + autocmd FileType ruby command! -buffer -complete=custom,s:RuboCopSwitches -nargs=? RuboCop :call RuboCop() +augroup END " Shortcuts for RuboCop if g:vimrubocop_keymap == 1 From e16337e6086f7aa1054e49e0f3fb6c86556e8cec Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 21:35:00 -0400 Subject: [PATCH 5/8] Add -D/--display-cop-names flags to completion list --- plugin/rubocop.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index bdd084a..39abb54 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -32,7 +32,7 @@ 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") From e1bc6ac835a2177de2e796e0e14e3ceaf410ea81 Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 23:00:59 -0400 Subject: [PATCH 6/8] Silence edit command --- plugin/rubocop.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index 39abb54..a2fbec3 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -62,7 +62,7 @@ function! s:RuboCop(current_args) cexpr l:rubocop_results copen elseif l:auto_corrected " Reload file if using auto correct - edit + silent edit redraw echo 'RuboCop: Auto-corrected!' else From 060356064bd4e47b501ee150c3a1359a70c96c59 Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 22 Oct 2015 23:03:54 -0400 Subject: [PATCH 7/8] Only define QF mappings if QF window is open --- plugin/rubocop.vim | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index a2fbec3..ccbff1b 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -61,23 +61,22 @@ function! s:RuboCop(current_args) if len(l:rubocop_results) && !l:auto_corrected cexpr l:rubocop_results copen + " Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git + exec "nnoremap q :ccl" + exec "nnoremap t T" + exec "nnoremap T TgT" + exec "nnoremap o " + exec "nnoremap go " + exec "nnoremap h K" + exec "nnoremap H Kb" + exec "nnoremap v HbJt" + exec "nnoremap gv HbJ" elseif l:auto_corrected " Reload file if using auto correct silent edit - redraw echo 'RuboCop: Auto-corrected!' else echo 'RuboCop: No violations!' endif - " Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git - exec "nnoremap q :ccl" - exec "nnoremap t T" - exec "nnoremap T TgT" - exec "nnoremap o " - exec "nnoremap go " - exec "nnoremap h K" - exec "nnoremap H Kb" - exec "nnoremap v HbJt" - exec "nnoremap gv HbJ" endfunction augroup RuboCop From 988b605219e0007de8ee6a2abaf9e2aefbb9a0fa Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Thu, 17 Nov 2016 22:41:06 -0500 Subject: [PATCH 8/8] Open qf window botright --- plugin/rubocop.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/rubocop.vim b/plugin/rubocop.vim index ccbff1b..284e6c8 100644 --- a/plugin/rubocop.vim +++ b/plugin/rubocop.vim @@ -60,7 +60,7 @@ function! s:RuboCop(current_args) let l:rubocop_results = split(l:rubocop_output, "\n") if len(l:rubocop_results) && !l:auto_corrected cexpr l:rubocop_results - copen + botright copen " Shortcuts taken from Ack.vim - git://github.com/mileszs/ack.vim.git exec "nnoremap q :ccl" exec "nnoremap t T"