changeset 454:fa5e2182e69a

Added jshint
author unexist
date Tue, 14 Jan 2014 15:24:07 +0100
parents f59da7734c99
children c0c3a6f8add4
files .vim/doc/jshint.txt .vim/plugin/jshint.vim
diffstat 2 files changed, 100 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.vim/doc/jshint.txt	Tue Jan 14 15:24:07 2014 +0100
@@ -0,0 +1,35 @@
+*jshint.vim*  A plugin that integrates JSHint with Vim
+
+==============================================================================
+Author:  Andreas Wålm <andreas+jshintvim@walm.net>             *jshint-author*
+License: See *LICENSE* file
+
+==============================================================================
+INTRODUCTION                                                          *jshint*
+
+This plugin is a front for JSHint.
+
+This plugin will allow you to run JSHint from vim, and shows the results in 
+a split window.
+
+:JSHint {file}                                                       *:JSHint*
+
+    Test {file} with jshint.
+    If {file} not provided it uses current file.
+
+    Behaves just like the |:grep| command, but will open the |Quickfix| 
+    window for you. 
+
+Hints found in file will be listed in the split window, along with the 
+line and column number. 
+
+<Enter> on a line in this window will open the file, and place the cursor on 
+the matching line.
+
+Press 'o' in a line in |Quickfix| will open the file in a new window and place
+the cursor on the matching line.
+
+Pressing 'go' will do a preview (open but maintain focus on jshint results)
+
+Press 'q' to close |Quickfix| window.
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.vim/plugin/jshint.vim	Tue Jan 14 15:24:07 2014 +0100
@@ -0,0 +1,65 @@
+" NOTE: You must have jshint in your path.
+"
+" Install:
+"
+" On system with npm:
+"   npm install jshint
+"
+
+" Location of jshint utility, change in vimrc i different
+if !exists("g:jshintprg")
+  let g:jshintprg="jshint"
+endif
+
+function! s:JSHint(cmd, args)
+  redraw
+  " If no file is provided, use current file
+  if empty(a:args)
+    let l:fileargs = expand("%")
+  else
+    let l:fileargs = a:args
+  end
+
+  let grepprg_bak=&grepprg
+  let grepformat_bak=&grepformat
+  try
+    let &grepprg=g:jshintprg
+    let &grepformat="%f: line %l\\,\ col %c\\, %m,%-G,%-G%s error,%-G%s errors"
+    let cmdline = [a:cmd]
+    if exists("g:jshintconfig")
+      call add(cmdline, '--config')
+      call add(cmdline, g:jshintconfig)
+    end
+    call add(cmdline, l:fileargs)
+    silent execute join(cmdline)
+  finally
+    let &grepprg=grepprg_bak
+    let &grepformat=grepformat_bak
+  endtry
+
+  if len(getqflist()) > 0
+
+    " has errors display quickfix win
+    botright copen
+
+    " close quickfix
+    exec "nnoremap <silent> <buffer> q :ccl<CR>"
+
+    " open in a new window
+    exec "nnoremap <silent> <buffer> o <C-W><CR>"
+
+    " preview
+    exec "nnoremap <silent> <buffer> go <CR><C-W><C-W>"
+
+    redraw!
+  else
+
+    " no error, sweet!
+    cclose
+    redraw!
+    echo "JSHint: Lint Free"
+
+  end
+endfunction
+
+command! -bang -nargs=* -complete=file JSHint call s:JSHint('grep<bang>',<q-args>)