Syntastic: Point syntastic checker at local npm module

Created on 8 Oct 2015  ยท  15Comments  ยท  Source: vim-syntastic/syntastic

We use nvm for node project which means switching node versions frequently so we avoid globally installed modules (with npm install -g ...) and install them locally.

Is there anyway to point syntastic at the projects local eslint module instead of a global path?

Most helpful comment

The following seems to be working for me:

" after/ftplugin/javascript.vim

" JavaScript Standard Style (standardjs.com)
let b:syntastic_checkers = ['standard']

" Point syntastic checker at locally installed `standard` if it exists.
if executable('node_modules/.bin/standard')
  let b:syntastic_javascript_standard_exec = 'node_modules/.bin/standard'
endif

All 15 comments

+1

Normally something like this should work:

let g:syntastic_javascript_eslint_exec = $HOME . '/bin/eslint'

However, there have been reports in the past of it not working on Mac OS-X, and there are persistent rumours out there that you can only run global mode modules from Vim, at least on some systems. As far as syntastic is concerned checkers are just executables, it doesn't know (nor cares) about what happens under the hood. Syntastic doesn't do anything special, it just runs checkers with system(). If there is anything that prevents local node modules from running this way, it's between Vim, node, and your shell. _shrug_

I believe parent meant ./node_modules/.bin/eslint (as installed with npm install --save-dev eslint for example).

Whatever the exact path is, my point still stands.

The following seems to be working for me:

" after/ftplugin/javascript.vim

" JavaScript Standard Style (standardjs.com)
let b:syntastic_checkers = ['standard']

" Point syntastic checker at locally installed `standard` if it exists.
if executable('node_modules/.bin/standard')
  let b:syntastic_javascript_standard_exec = 'node_modules/.bin/standard'
endif

@wilmoore Are you doing that on Mac OS-X? And that's a less than great way to do it, anyway.

Hi @lcd047

Are you doing that on Mac OS-X?

Yes.

And that's a less than great way to do it, anyway.

What would be a better way to do it? I'm open to working alternatives for sure.

What would be a better way to do it? I'm open to working alternatives for sure.

Err, perhaps try using full paths and autocmds?

I'm using autocmd FileType javascript let b:syntastic_checkers = findfile('node_modules/.bin/standard', '.;') != '' ? [ 'standard' ] : [ 'eslint' ]

Neither @wilmoore or @olalonde suggestions seemed to work for me, as soon as I uninstalled the global package it stopped working. I think syntastic requires the full path to the executable which has to be on your path?

Err, perhaps try using full paths ...

Ideally, what I'm after is to find an executable that is installed relative to the project. If there is a better way to achieve what I am after, would you mind providing an example?

... and autocmds?

I could be mistaken (still trying to grasp the ins and out of vimscript) but aren't autocmds redundant if I am in a ftplugin file?

@willmcclellan

(Updated: 2016-07-07)

Neither @wilmoore or @olalonde suggestions seemed to work for me, as soon as I uninstalled the global package it stopped working.

I am not sure what to tell you there, but I was able to test it will the globally installed one existing and not existing and it worked in both cases.

FWIW, here are some links to my dotfiles in case you spot something that may help you:

SyntasticInfo
:SyntasticInfo
Syntastic version: 3.6.0-92 (Vim 704, Darwin)
Info for filetype:
Global mode: active
Filetype  is active
The current file will be checked automatically
Available checkers: -
Currently enabled checkers: -
The current file will not be checked (file not readable / not local)
Vim Info
โฏ vim --version
NVIM 0.1.2
Build type: RelWithDebInfo
Compilation: /Users/wilmoore/.homebrew/Library/ENV/4.3/clang -Wconversion -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/build/config -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/src -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include/luajit-2.0 -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/deps-build/usr/include -I/Users/wilmoore/.homebrew/opt/gettext/include -I/usr/include -I/usr/include -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/build/src/nvim/auto -I/tmp/neovim20160330-53723-18c3i2h/neovim-0.1.2/build/include
Compiled by wilmoore@Wils-MBP

Optional features included (+) or not (-): +acl   +iconv    +jemalloc 
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/Users/wilmoore/.homebrew/Cellar/neovim/0.1.2/share/nvim
"

Ideally, what I'm after is to find an executable that is installed relative to the project.

How should Vim distinguish the root directory of your project from other directories?

I could be mistaken (still trying to grasp the ins and out of vimscript) but aren't autocmds redundant if I am in a ftplugin file?

Some autocmds are redundant, others aren't. ftplugin files are loaded at the wrong time for this, you want something that gets run each time you switch buffers, so that you could, in principle, load files from different projects and check each of them with the appropriate eslint (not that you'd need to do that in practice, but it's much cleaner to approach it that way).

ftplugin files are loaded at the wrong time for this, you want something that gets run each time you switch buffers

Ah...good point.

Anyone else getting Undefined variable: g:syntastic_javascript_eslint_exec?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitc picture bitc  ยท  3Comments

dunatotatos picture dunatotatos  ยท  6Comments

symbolix picture symbolix  ยท  8Comments

PROgram52bc picture PROgram52bc  ยท  6Comments

albasili picture albasili  ยท  6Comments