Syntastic: checker eslint is not available

Created on 4 Nov 2017  Â·  6Comments  Â·  Source: vim-syntastic/syntastic

I know this problem has come repeatedly, most notably in #1692, but I still can't make it work. Here is what is happening:

  • I have eslint installed locally.
  • There is a npm run lint script using it (in package.json, I wrote "lint": "eslint src tests")
  • When I open a file (here, src/Timer.js) from the root folder (the one where package.json is), and I run echo system('npm run lint --'), I get this:
> [email protected] lint /Users/l/Software/react-analog-clock                                   
> eslint src tests                                                                                     


/Users/l/Software/react-analog-clock/src/Timer.js                                                      
   2:8   error  'PropTypes' is defined but never used     no-unused-vars                               
   6:17  error  'props' is defined but never used         no-unused-vars                               
   6:23  error  Missing space before opening brace        space-before-blocks                          
  11:9   error  Unexpected var, use let or const instead  no-var                                       
  11:13  error  'x' is defined but never used             no-unused-vars                               
  14:13  error  Missing space before opening brace        space-before-blocks                          

✖ 6 problems (6 errors, 0 warnings)                                                                    

npm ERR! code ELIFECYCLE                                                                               
npm ERR! errno 1                                                                                       
npm ERR! [email protected] lint: `eslint src tests`                                             
npm ERR! Exit status 1                                                                                 
npm ERR!                                                                                               
npm ERR! Failed at the [email protected] lint script.                                           
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.     

npm ERR! A complete log of this run can be found in:                                                   
npm ERR!     /Users/l/.npm/_logs/2017-11-04T16_00_05_746Z-debug.log                                    
  • (The result is the same with echo syntastic#util#system('npm run lint --').)
  • My .vimrc references eslint as the checker, and the script I just mentioned as the thing to execute:
let g:syntastic_javascript_checkers = ['eslint']                                                       
let g:syntastic_javascript_eslint_exe = 'npm run lint --'                                              
  • However, when I run :SyntasticCheck eslint, syntastic tells me that eslint is not available.
  • Here is what I get when I disable all the other plugins, and then combine :let g:syntastic_debug=3, :SyntasticCheck eslint, and :mes:
"src/Timer.js" 19L, 312C                                                                               
/Users/l/Software/react-analog-clock                                                                   
syntastic: 302.432844: g:syntastic_version = '3.8.0-90 (Vim 704, Neovim, Darwin)'                      
syntastic: 302.433215: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquot
e = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote = '', &autochdir = 0, &shellxescape = ''
syntastic: 302.434680: UpdateErrors: eslint                                                            
syntastic: 302.435250: CacheErrors: eslint                                                             
syntastic: 302.436529: g:syntastic_aggregate_errors = 0                                                
syntastic: 302.436867: getcwd() = '/Users/l/Software/react-analog-clock'                               
syntastic: 302.437682: CacheErrors: Checker javascript/eslint is not available                         
syntastic: warning: checker eslint is not available                                                    
syntastic: 302.438151: aggregated: {'_sorted': 0, '_name': '', '_owner': 1, '_columns': 1, '_rawLoclist
': []}                                                                                                 
  • I use NeoVim on macOS 10.13, but I have seen the same behavior with Vim.
  • Here is my .vimrc:
syntax enable                                                                                          
colorscheme monokai                                                                                    

" Specify a directory for plugins                                                                      
" - For Neovim: ~/.local/share/nvim/plugged                                                            
" - Avoid using standard Vim directory names like 'plugin'                                             
call plug#begin('~/.vim/plugged')                                                                      

"Plug 'pangloss/vim-javascript'                                                                        
"Plug 'mxw/vim-jsx'                                                                                    
"Plug 'Yggdroot/indentLine'                                                                            
Plug 'vim-syntastic/syntastic'                                                                         

call plug#end()                                                                                        

let g:jsx_ext_required = 0                                                                             
let g:indentLine_color_term = 239                                                                      
let g:indentLine_char = '┆'                                                                            

set number                                                                                             
set ruler                                                                                              
" Change tabs to 4 spaces                                                                              
set tabstop=4 shiftwidth=4 expandtab                                                                   

" Show tabs and trailing spaces                                                                        
set listchars=eol:↩,tab:→=,trail:·                                                                     
set list                                                                                               

" Params for Syntastic                                                                                 
set statusline+=%#warningmsg#                                                                          
set statusline+=%{SyntasticStatuslineFlag()}                                                           
set statusline+=%*                                                                                     

let g:syntastic_always_populate_loc_list = 1                                                           
let g:syntastic_auto_loc_list = 1                                                                      
let g:syntastic_check_on_open = 1                                                                      
let g:syntastic_check_on_wq = 0                                                                        
let g:syntastic_javascript_checkers = ['eslint']                                                       
let g:syntastic_javascript_eslint_exe = 'npm run lint --'                                              

Thanks!

Most helpful comment

@lemeb Can you explain how to refer to the bash script exactly?
let g:syntastic_javascript_eslint_exe = '<path/to/bash_script> <-- like this?

All 6 comments

Here is what I did: I wrote a one-line bash script:

npx eslint "$@"

and defined that bash script as g:syntastic_javascript_eslint_exec

It works, so I'm closing the issue, but I'm wondering if there is a more kosher way of doing it...

I'm wondering if there is a more kosher way of doing it...

I'm afraid there isn't. Local modules and the way they are implemented in node make things really complicated for third-party programs trying to do something useful with them while still staying environment-agnostic. Syntastic is a framework for "normal" linters.

Looking at your first attempt, that didn't work because syntastic needs to know the versions of eslint. And to do that it needs syntastic_javascript_eslint_exec to point to an executable that takes --version as an option (and reacts to it accordingly). That's why a wrapper script is almost always the easier approach.

@lemeb Can you explain how to refer to the bash script exactly?
let g:syntastic_javascript_eslint_exe = '<path/to/bash_script> <-- like this?

@lemeb Can you explain how to refer to the bash script exactly?
let g:syntastic_javascript_eslint_exe = '<path/to/bash_script> <-- like this?

I second that, can we get an example of what that looks like?

@nickhallph Please read the second post.

yes. here's an extract of my .vimrc, for the record. (thanks @lcd047)

let g:syntastic_javascript_eslint_exec = './script.sh'
    " Works only if there is a script sh enabling eslint in the folder
    " though...
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vjsingh picture vjsingh  Â·  6Comments

cookiengineer picture cookiengineer  Â·  7Comments

noprompt picture noprompt  Â·  5Comments

zoecarver picture zoecarver  Â·  8Comments

dunatotatos picture dunatotatos  Â·  6Comments