walm/jshint.vim

Close quickfix when no errors

Closed this issue · 2 comments

Hi Andreas, thanks for making this plugin. It works like a charm!

Is there a way to have the quickfix window close automatically when no errors are found? I have JSHint set to run each time a file is saved, via the following autocmd:

  autocmd BufWritePost,FileWritePost *.js JSHint

Unfortunately this means the quickfix window appears every time I save, even if no errors are found, which is less than desirable behavior. It'd be nice if the quickfix window was automatically closed (or not opened) in this case.

FWIW, I've fixed this issue by adding the following in my vimrc file. Would it make sense to instead have this logic as part of your plugin?

" Wrap JSHint to ensure quickfix window is closed when there's no errors
function s:do_jshint()
  JSHint
  if (len(getqflist()) <= 1)
    echo "JSHint: No errors (whee!)"
    cclose
  endif
endfunction
" Run jshint on save
autocmd BufWritePost,FileWritePost *.js call s:do_jshint()
walm commented

Great solution, thanks Robert!