vim, syntastic, .jshintrc

10 Dec 2013 14:21 vim

I’ve been using Syntastic for a while now. It’s awesome.

One thing it’s missing, however, is the ability to automatically find an appropriate .jshintrc file for the file you’re editing.

Fixed. Put this lot in your .vimrc file:

function s:find_jshintrc(dir)
    let l:found = globpath(a:dir, '.jshintrc')
    if filereadable(l:found)
        return l:found

    let l:parent = fnamemodify(a:dir, ':h')
    if l:parent != a:dir
        return s:find_jshintrc(l:parent)

    return "~/.jshintrc"

function UpdateJsHintConf()
    let l:dir = expand('%:p:h')
    let l:jshintrc = s:find_jshintrc(l:dir)
    let g:syntastic_javascript_jshint_conf = l:jshintrc

au BufEnter * call UpdateJsHintConf()