From 2a88b60ff1ef5a4e9e73dc0d3be9f8ac51ec1309 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 29 Mar 2017 00:56:39 +0100 Subject: [PATCH] Fix #260 automatically set .csslintrc files from ancestor directories --- ale_linters/css/csslint.vim | 11 +++++- .../csslint-test-files/other-app/testfile.css | 0 test/csslint-test-files/some-app/.csslintrc | 0 .../some-app/subdir/testfile.css | 0 test/test_csslint_config_detection.vader | 36 +++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/csslint-test-files/other-app/testfile.css create mode 100644 test/csslint-test-files/some-app/.csslintrc create mode 100644 test/csslint-test-files/some-app/subdir/testfile.css create mode 100644 test/test_csslint_config_detection.vader diff --git a/ale_linters/css/csslint.vim b/ale_linters/css/csslint.vim index 39176ce3..6b0956ee 100644 --- a/ale_linters/css/csslint.vim +++ b/ale_linters/css/csslint.vim @@ -1,9 +1,18 @@ " Author: w0rp " 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', { \ 'name': 'csslint', \ 'executable': 'csslint', -\ 'command': 'csslint --format=compact %t', +\ 'command_callback': 'ale_linters#css#csslint#GetCommand', \ 'callback': 'ale#handlers#HandleCSSLintFormat', \}) diff --git a/test/csslint-test-files/other-app/testfile.css b/test/csslint-test-files/other-app/testfile.css new file mode 100644 index 00000000..e69de29b diff --git a/test/csslint-test-files/some-app/.csslintrc b/test/csslint-test-files/some-app/.csslintrc new file mode 100644 index 00000000..e69de29b diff --git a/test/csslint-test-files/some-app/subdir/testfile.css b/test/csslint-test-files/some-app/subdir/testfile.css new file mode 100644 index 00000000..e69de29b diff --git a/test/test_csslint_config_detection.vader b/test/test_csslint_config_detection.vader new file mode 100644 index 00000000..a06258ca --- /dev/null +++ b/test/test_csslint_config_detection.vader @@ -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