Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- command! -nargs=* JSLint call JSLint(<f-args>)
- " @param boolean interact: 1 to prompt before lint.
- " @param string options: custom options for running JSLint. in JSON string, ex: '{"onevar":false}'
- fun! JSLint(...)
- if ! executable('jslint')
- echohl WarningMsg | echoerr "jslint command not found." | echohl None
- return
- endif
- let input = expand('%')
- let interact = a:0 > 0 ? a:1 : 0
- let options = a:0 > 1 ? a:2 : ''
- if &modified
- echomsg 'No write since last change, write before lint? (y/n) '
- let ans = getchar()
- if nr2char(ans) == 'y' | w
- elseif nr2char(ans) != 'n' | redraw! | echomsg 'JSLint aborted.' | return
- endif
- endif
- if &filetype == 'javascript'
- let cmd = 'jslint ' . input . ' ' . options
- if interact
- echomsg 'JSLint ' . input . '? (y/n) ' | redraw
- let yes = getchar()
- if nr2char(yes) == 'y'
- return DoJSLint(cmd, input)
- else
- redraw!
- echomsg 'JSLint aborted.'
- return
- endif
- else
- return DoJSLint(cmd, input)
- endif
- else
- echohl WarningMsg | echomsg "Unsupported filetype." | echohl None
- endif
- endf
- fun! DoJSLint(cmd, file)
- echomsg "JSLint in progress..."
- let ret = system(a:cmd)
- if v:shell_error
- cexpr ret
- if len(getqflist()) > 0
- QFix!<CR>
- endif
- else
- redraw
- echomsg "No problems found in " . a:file
- return
- endif
- endf
Add Comment
Please, Sign In to add comment