Skip to content

Instantly share code, notes, and snippets.

@vanwagonet
Created October 5, 2017 03:04
Show Gist options
  • Save vanwagonet/c6797d2a3efb3a759b3667fb4510d20d to your computer and use it in GitHub Desktop.
Save vanwagonet/c6797d2a3efb3a759b3667fb4510d20d to your computer and use it in GitHub Desktop.
Use the locally installed node modules for eslint and flow checking
" return full path with the trailing slash or empty string
fun! s:GetNodeModulesAbsPath ()
let lcd_saved = fnameescape(getcwd())
silent! exec "lcd" expand('%:p:h')
let path = finddir('node_modules', '.;')
exec "lcd" lcd_saved
" fnamemodify will return full path with trailing slash;
" if no node_modules found, we're safe
return path is '' ? '' : fnamemodify(path, ':p')
endfun
" return full path of local bin or empty string
fun! s:GetNodeModuleBin (node_modules, bin)
let guess = a:node_modules is '' ? '' : a:node_modules . '.bin/' . a:bin
return exepath(guess)
endfun
fun! s:main ()
let node_modules = s:GetNodeModulesAbsPath()
let eslint_exec = s:GetNodeModuleBin(node_modules, 'eslint')
if a:eslint_exec isnot ''
let b:syntastic_javascript_eslint_exec = a:eslint_exec
endif
let flowtype_exec = s:GetNodeModuleBin(node_modules, 'flow')
if a:flowtype_exec isnot ''
let b:syntastic_javascript_flowtype_exe = a:flowtype_exec
endif
endfun
call s:main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment