Fix eslint configuration file search

`fnamemodify` called on a null/empty result of `findfile` results in a
non-empty value. `fnamemodify` was being called in this way prior to the
evaluation of the `if empty(l:tcfg)` rule, meaning Autoformat never
picked up on the fact that there was no configuration file, and instead
tried to call `eslint -c /path/to/project/` (with the folder path
instead of the .eslintrc path).
This commit is contained in:
Mahmoud Al-Qudsi 2018-01-31 13:11:28 -06:00
parent 298e7d5fa8
commit 4de2e93753

View File

@ -189,42 +189,38 @@ if !exists('g:formatdef_eslint_local')
if empty(l:prog) if empty(l:prog)
let l:prog = findfile('~/.npm-global/bin/eslint') let l:prog = findfile('~/.npm-global/bin/eslint')
endif endif
"initial "initial
let l:cfg = fnamemodify(findfile('.eslintrc.js', l:path.";"),':p') let l:cfg = findfile('.eslintrc.js', l:path.";")
let l:tcfg = fnamemodify(findfile('.eslintrc.yaml', l:path.";"),':p') if empty(l:cfg)
if len(l:tcfg) > len(l:cfg) let l:cfg_fallbacks = [
let l:cfg = l:tcfg \'.eslintrc.yaml',
endif \'.eslintrc.yml',
let l:tcfg = fnamemodify(findfile('.eslintrc.yml', l:path.";"),':p') \'.eslintrc.json',
if len(l:tcfg) > len(l:cfg) \'.eslintrc',
let l:cfg = l:tcfg \]
endif
let l:tcfg = fnamemodify(findfile('.eslintrc.json', l:path.";"),':p') for i in l:cfg_fallbacks
if len(l:tcfg) > len(l:cfg) let l:tcfg = findfile(i, l:path.";")
let l:cfg = l:tcfg if !empty(l:tcfg)
endif break
let l:tcfg = fnamemodify(findfile('.eslintrc', l:path.";"),':p') endif
if len(l:tcfg) > len(l:cfg) endfor
let l:cfg = l:tcfg
if !empty(l:tcfg)
let l:cfg = fnamemodify(l:tcfg, ":p")
else
let l:cfg = findfile('~/.eslintrc.js')
for i in l:cfg_fallbacks
if !empty(l:cfg)
break
endif
let l:cfg = findfile("~/".i)
endfor
endif
endif endif
" This is in case we are outside home folder
if empty(l:cfg)
let l:cfg = findfile('~/.eslintrc.js')
endif
if empty(l:cfg)
let l:cfg = findfile('~/.eslintrc.yaml')
endif
if empty(l:cfg)
let l:cfg = findfile('~/.eslintrc.yml')
endif
if empty(l:cfg)
let l:cfg = findfile('~/.eslintrc.json')
endif
if empty(l:cfg)
let l:cfg = findfile('~/.eslintrc')
endif
if (empty(l:cfg) || empty(l:prog)) if (empty(l:cfg) || empty(l:prog))
if verbose if verbose
return "(>&2 echo 'No local or global ESLint program and/or config found')" return "(>&2 echo 'No local or global ESLint program and/or config found')"