Guest User

Untitled

a guest
Jul 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. command! -nargs=* JSLint call JSLint(<f-args>)
  2. " @param boolean interact: 1 to prompt before lint.
  3. " @param string options: custom options for running JSLint. in JSON string, ex: '{"onevar":false}'
  4. fun! JSLint(...)
  5. if ! executable('jslint')
  6. echohl WarningMsg | echoerr "jslint command not found." | echohl None
  7. return
  8. endif
  9. let input = expand('%')
  10. let interact = a:0 > 0 ? a:1 : 0
  11. let options = a:0 > 1 ? a:2 : ''
  12.  
  13. if &modified
  14. echomsg 'No write since last change, write before lint? (y/n) '
  15. let ans = getchar()
  16. if nr2char(ans) == 'y' | w
  17. elseif nr2char(ans) != 'n' | redraw! | echomsg 'JSLint aborted.' | return
  18. endif
  19. endif
  20.  
  21. if &filetype == 'javascript'
  22. let cmd = 'jslint ' . input . ' ' . options
  23. if interact
  24. echomsg 'JSLint ' . input . '? (y/n) ' | redraw
  25. let yes = getchar()
  26. if nr2char(yes) == 'y'
  27. return DoJSLint(cmd, input)
  28. else
  29. redraw!
  30. echomsg 'JSLint aborted.'
  31. return
  32. endif
  33. else
  34. return DoJSLint(cmd, input)
  35. endif
  36. else
  37. echohl WarningMsg | echomsg "Unsupported filetype." | echohl None
  38. endif
  39. endf
  40.  
  41. fun! DoJSLint(cmd, file)
  42. echomsg "JSLint in progress..."
  43. let ret = system(a:cmd)
  44. if v:shell_error
  45. cexpr ret
  46. if len(getqflist()) > 0
  47. QFix!<CR>
  48. endif
  49. else
  50. redraw
  51. echomsg "No problems found in " . a:file
  52. return
  53. endif
  54. endf
Add Comment
Please, Sign In to add comment