1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 00:20:05 +08:00

option to use local eslint rather than global eslint

This commit is contained in:
zhujinxuan 2018-01-08 14:10:35 -05:00
parent a33a1e5775
commit ea9d832789

View File

@ -24,9 +24,27 @@ function! SpaceVim#layers#lang#javascript#plugins() abort
endfunction
let s:auto_fix = 0
let s:use_local_eslint = 0
function! SpaceVim#layers#lang#javascript#set_variable(var) abort
let s:auto_fix = get(a:var, 'auto_fix', 0)
let s:use_local_eslint = get(a:var, 'use_local_eslint', 0)
endfunction
function! s:preferLocalEslint()
let dir = expand('%:p:h')
while finddir('node_modules' ,dir ) is ''
let next_dir = fnamemodify(dir, ':h')
if dir == next_dir
break
endif
let dir = next_dir
endwhile
let node_modules_path = dir . '/node_modules'
let eslint_bin = node_modules_path . '/.bin/eslint'
if (executable(eslint_bin))
let b:neomake_javascript_eslint_exe = eslint_bin
endif
endfunction
function! SpaceVim#layers#lang#javascript#config() abort
@ -62,6 +80,13 @@ function! SpaceVim#layers#lang#javascript#config() abort
autocmd FocusGained * checktime
augroup END
endif
if s:use_local_eslint
augroup Spacevim_lang_javascript
autocmd BufNewFile,BufRead *.js call s:preferLocalEslint()
augroup END
endif
endfunction
function! s:on_ft() abort