Fix #260 automatically set .csslintrc files from ancestor directories

This commit is contained in:
w0rp 2017-03-29 00:56:39 +01:00
parent 8e71f233da
commit 2a88b60ff1
5 changed files with 46 additions and 1 deletions

View File

@ -1,9 +1,18 @@
" Author: w0rp <devw0rp@gmail.com> " Author: w0rp <devw0rp@gmail.com>
" Description: This file adds support for checking CSS code with csslint. " Description: This file adds support for checking CSS code with csslint.
function! ale_linters#css#csslint#GetCommand(buffer) abort
let l:csslintrc = ale#util#FindNearestFile(a:buffer, '.csslintrc')
let l:config_option = !empty(l:csslintrc)
\ ? '--config=' . fnameescape(l:csslintrc)
\ : ''
return 'csslint --format=compact ' . l:config_option . ' %t'
endfunction
call ale#linter#Define('css', { call ale#linter#Define('css', {
\ 'name': 'csslint', \ 'name': 'csslint',
\ 'executable': 'csslint', \ 'executable': 'csslint',
\ 'command': 'csslint --format=compact %t', \ 'command_callback': 'ale_linters#css#csslint#GetCommand',
\ 'callback': 'ale#handlers#HandleCSSLintFormat', \ 'callback': 'ale#handlers#HandleCSSLintFormat',
\}) \})

View File

@ -0,0 +1,36 @@
Before:
silent! cd /testplugin/test
let g:dir = getcwd()
runtime ale_linters/css/csslint.vim
After:
silent execute 'cd ' . g:dir
unlet! g:dir
call ale#linter#Reset()
Execute(--config should be set when the .csslintrc file is found):
new csslint-test-files/some-app/subdir/testfile.js
AssertEqual
\ (
\ 'csslint --format=compact '
\ . '--config=' . fnameescape(g:dir . '/csslint-test-files/some-app/.csslintrc')
\ . ' %t'
\ ),
\ ale_linters#css#csslint#GetCommand(bufnr(''))
:q
Execute(--config should not be used when no .csslintrc file exists):
new csslint-test-files/other-app/testfile.css
AssertEqual
\ (
\ 'csslint --format=compact '
\ . ' %t'
\ ),
\ ale_linters#css#csslint#GetCommand(bufnr(''))
:q