From eaeb71993f259c5014e22291f6cf08e623c1047b Mon Sep 17 00:00:00 2001 From: Mahmoud Mostafa Date: Mon, 31 Jul 2017 02:51:08 +0200 Subject: Add stylelint fixer --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/stylelint.vim | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 autoload/ale/fixers/stylelint.vim (limited to 'autoload') 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 +" 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 -- cgit v1.2.3