mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
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
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
call ale#Set('stylelint_executable', 'stylelint')
|
call ale#Set('stylelint_executable', 'stylelint')
|
||||||
call ale#Set('stylelint_use_global', get(g:, 'ale_use_global_executables', 0))
|
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
|
function! ale#fixers#stylelint#GetExecutable(buffer) abort
|
||||||
return ale#node#FindExecutable(a:buffer, 'stylelint', [
|
return ale#node#FindExecutable(a:buffer, 'stylelint', [
|
||||||
@@ -13,10 +14,14 @@ endfunction
|
|||||||
|
|
||||||
function! ale#fixers#stylelint#Fix(buffer) abort
|
function! ale#fixers#stylelint#Fix(buffer) abort
|
||||||
let l:executable = ale#fixers#stylelint#GetExecutable(a:buffer)
|
let l:executable = ale#fixers#stylelint#GetExecutable(a:buffer)
|
||||||
|
let l:options = ale#Var(a:buffer, 'stylelint_options')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#node#Executable(a:buffer, l:executable)
|
\ 'command': ale#path#BufferCdString(a:buffer)
|
||||||
\ . ' --fix %t',
|
\ . ale#node#Executable(a:buffer, l:executable)
|
||||||
|
\ . ' %t'
|
||||||
|
\ . ale#Pad(l:options)
|
||||||
|
\ . ' --fix',
|
||||||
\ 'read_temporary_file': 1,
|
\ 'read_temporary_file': 1,
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -1,17 +1,33 @@
|
|||||||
Before:
|
Before:
|
||||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
call ale#assert#SetUpFixerTest('css', 'stylelint')
|
||||||
|
|
||||||
After:
|
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')
|
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.css')
|
||||||
|
|
||||||
AssertEqual
|
AssertFixer
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
\ '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'))
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/stylelint/bin/stylelint.js'))
|
||||||
\ . ' --fix %t',
|
\ . ' %t'
|
||||||
\ },
|
\ . ' --fix',
|
||||||
\ ale#fixers#stylelint#Fix(bufnr(''))
|
\ }
|
||||||
|
|
||||||
|
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',
|
||||||
|
\ }
|
||||||
|
|||||||
Reference in New Issue
Block a user