summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Johnson <mail@cbjohnson.info>2019-10-28 08:23:02 -0500
committerw0rp <w0rp@users.noreply.github.com>2019-10-28 13:23:02 +0000
commitaf8c8516d1d9ce75df40fa457debaedcb11a7592 (patch)
treea51c91e9024cc3d1c5949cca78f2c009a2157d1e
parent0d4dfb61dc2bcb82612ae7407e9a6cbc7b020576 (diff)
downloadale-af8c8516d1d9ce75df40fa457debaedcb11a7592.zip
fixers/stylelint: enhance `stylelint` fixer (#2745)
* Refactor stylelint fixer test * Support additional stylelint fixer options * Support changing working directory for stylelint fixer * Force css syntax for stylelint fixer
-rw-r--r--autoload/ale/fixers/stylelint.vim9
-rw-r--r--test/fixers/test_stylelint_fixer_callback.vader32
2 files changed, 31 insertions, 10 deletions
diff --git a/autoload/ale/fixers/stylelint.vim b/autoload/ale/fixers/stylelint.vim
index 6bfb2fde..6f4cf177 100644
--- a/autoload/ale/fixers/stylelint.vim
+++ b/autoload/ale/fixers/stylelint.vim
@@ -3,6 +3,7 @@
call ale#Set('stylelint_executable', 'stylelint')
call ale#Set('stylelint_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('stylelint_options', '')
function! ale#fixers#stylelint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'stylelint', [
@@ -13,10 +14,14 @@ endfunction
function! ale#fixers#stylelint#Fix(buffer) abort
let l:executable = ale#fixers#stylelint#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'stylelint_options')
return {
- \ 'command': ale#node#Executable(a:buffer, l:executable)
- \ . ' --fix %t',
+ \ 'command': ale#path#BufferCdString(a:buffer)
+ \ . ale#node#Executable(a:buffer, l:executable)
+ \ . ' %t'
+ \ . ale#Pad(l:options)
+ \ . ' --fix',
\ 'read_temporary_file': 1,
\}
endfunction
diff --git a/test/fixers/test_stylelint_fixer_callback.vader b/test/fixers/test_stylelint_fixer_callback.vader
index 90a9dc1f..f677cdf7 100644
--- a/test/fixers/test_stylelint_fixer_callback.vader
+++ b/test/fixers/test_stylelint_fixer_callback.vader
@@ -1,17 +1,33 @@
Before:
- call ale#test#SetDirectory('/testplugin/test/fixers')
+ call ale#assert#SetUpFixerTest('css', 'stylelint')
After:
- call ale#test#RestoreDirectory()
+ call ale#assert#TearDownFixerTest()
-Execute(The executable path should be correct):
+Execute(The stylelint callback should return the correct default values):
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.css')
- AssertEqual
+ AssertFixer
\ {
\ 'read_temporary_file': 1,
- \ 'command': (has('win32') ? 'node.exe ' : '')
+ \ 'command': ale#path#CdString(expand('%:p:h'))
+ \ . (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js'))
- \ . ' --fix %t',
- \ },
- \ ale#fixers#stylelint#Fix(bufnr(''))
+ \ . ' %t'
+ \ . ' --fix',
+ \ }
+
+Execute(The stylelint callback should include custom stylelint options):
+ let g:ale_stylelint_options = '--cache'
+ call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.css')
+
+ AssertFixer
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#path#CdString(expand('%:p:h'))
+ \ . (has('win32') ? 'node.exe ' : '')
+ \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js'))
+ \ . ' %t'
+ \ . ' --cache'
+ \ . ' --fix',
+ \ }