diff options
author | Mahmoud Mostafa <mah@moud.info> | 2017-07-31 02:51:08 +0200 |
---|---|---|
committer | Mahmoud Mostafa <mah@moud.info> | 2017-07-31 02:54:59 +0200 |
commit | eaeb71993f259c5014e22291f6cf08e623c1047b (patch) | |
tree | b6ebe25e40d04e726122f0e5a75b59c8504144c1 /autoload | |
parent | 79d4935ccf95166838dff4feaf78467bc5f86096 (diff) | |
download | ale-eaeb71993f259c5014e22291f6cf08e623c1047b.zip |
Add stylelint fixer
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/stylelint.vim | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 6568a477..ce30c36e 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -67,6 +67,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['javascript'], \ 'description': 'Fix JavaScript files using standard --fix', \ }, +\ 'stylelint': { +\ 'function': 'ale#fixers#stylelint#Fix', +\ 'suggested_filetypes': ['css', 'sass', 'scss', 'stylus'], +\ 'description': 'Fix stylesheet files using stylelint --fix.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/stylelint.vim b/autoload/ale/fixers/stylelint.vim new file mode 100644 index 00000000..7d5abb73 --- /dev/null +++ b/autoload/ale/fixers/stylelint.vim @@ -0,0 +1,31 @@ +" Author: Mahmoud Mostafa <mah@moud.info> +" Description: Fixing files with stylelint. + +call ale#Set('stylelint_executable', 'stylelint') +call ale#Set('stylelint_use_global', 0) + +function! ale#fixers#stylelint#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'stylelint', [ + \ 'node_modules/stylelint/bin/stylelint.js', + \ 'node_modules/.bin/stylelint', + \]) +endfunction + + +function! ale#fixers#stylelint#Fix(buffer) abort + let l:executable = ale#fixers#stylelint#GetExecutable(a:buffer) + + if ale#Has('win32') && l:executable =~? 'stylelint\.js$' + " For Windows, if we detect an stylelint.js script, we need to execute + " it with node, or the file can be opened with a text editor. + let l:head = 'node ' . ale#Escape(l:executable) + else + let l:head = ale#Escape(l:executable) + endif + + return { + \ 'command': l:head + \ . ' --fix %t', + \ 'read_temporary_file': 1, + \} +endfunction |