[enhancement] add node_modules support for stylelint & htmlhint (#226)
* Add node_modules support for stylelint * add node_modules support for htmlhint * fix stdin * update doc about stylelint & htmlhint
This commit is contained in:
parent
cd6d8f2ab6
commit
6c0996eb9c
6 changed files with 195 additions and 12 deletions
|
@ -1,8 +1,31 @@
|
|||
" Author: diartyz <diartyz@gmail.com>
|
||||
|
||||
let g:ale_css_stylelint_executable =
|
||||
\ get(g:, 'ale_css_stylelint_executable', 'stylelint')
|
||||
|
||||
let g:ale_css_stylelint_use_global =
|
||||
\ get(g:, 'ale_css_stylelint_use_global', 0)
|
||||
|
||||
function! ale_linters#css#stylelint#GetExecutable(buffer) abort
|
||||
if g:ale_css_stylelint_use_global
|
||||
return g:ale_css_stylelint_executable
|
||||
endif
|
||||
|
||||
return ale#util#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/.bin/stylelint',
|
||||
\ g:ale_css_stylelint_executable
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#css#stylelint#GetCommand(buffer) abort
|
||||
return ale_linters#css#stylelint#GetExecutable(a:buffer)
|
||||
\ . ' --stdin-filename %s'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('css', {
|
||||
\ 'name': 'stylelint',
|
||||
\ 'executable': 'stylelint',
|
||||
\ 'command': g:ale#util#stdin_wrapper . ' .css stylelint',
|
||||
\ 'executable_callback': 'ale_linters#css#stylelint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#css#stylelint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
|
||||
\})
|
||||
|
|
|
@ -1,12 +1,36 @@
|
|||
" Author: KabbAmine <amine.kabb@gmail.com>, deathmaz <00maz1987@gmail.com>
|
||||
" Author: KabbAmine <amine.kabb@gmail.com>, deathmaz <00maz1987@gmail.com>, diartyz <diartyz@gmail.com>
|
||||
" Description: HTMLHint for checking html files
|
||||
|
||||
" CLI options
|
||||
let g:ale_html_htmlhint_options = get(g:, 'ale_html_htmlhint_options', '--format=unix')
|
||||
|
||||
let g:ale_html_htmlhint_executable =
|
||||
\ get(g:, 'ale_html_htmlhint_executable', 'htmlhint')
|
||||
|
||||
let g:ale_html_htmlhint_use_global =
|
||||
\ get(g:, 'ale_html_htmlhint_use_global', 0)
|
||||
|
||||
function! ale_linters#html#htmlhint#GetExecutable(buffer) abort
|
||||
if g:ale_html_htmlhint_use_global
|
||||
return g:ale_html_htmlhint_executable
|
||||
endif
|
||||
|
||||
return ale#util#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/.bin/htmlhint',
|
||||
\ g:ale_html_htmlhint_executable
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#html#htmlhint#GetCommand(buffer) abort
|
||||
return g:ale#util#stdin_wrapper . ' .html '
|
||||
\ . ale_linters#html#htmlhint#GetExecutable(a:buffer)
|
||||
\ . ' ' . g:ale_html_htmlhint_options
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('html', {
|
||||
\ 'name': 'htmlhint',
|
||||
\ 'executable': 'htmlhint',
|
||||
\ 'command': 'htmlhint ' . g:ale_html_htmlhint_options . ' stdin',
|
||||
\ 'executable_callback': 'ale_linters#html#htmlhint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#html#htmlhint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
|
||||
\})
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
" Author: diartyz <diartyz@gmail.com>
|
||||
|
||||
let g:ale_sass_stylelint_executable =
|
||||
\ get(g:, 'ale_sass_stylelint_executable', 'stylelint')
|
||||
|
||||
let g:ale_sass_stylelint_use_global =
|
||||
\ get(g:, 'ale_sass_stylelint_use_global', 0)
|
||||
|
||||
function! ale_linters#sass#stylelint#GetExecutable(buffer) abort
|
||||
if g:ale_sass_stylelint_use_global
|
||||
return g:ale_sass_stylelint_executable
|
||||
endif
|
||||
|
||||
return ale#util#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/.bin/stylelint',
|
||||
\ g:ale_sass_stylelint_executable
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sass#stylelint#GetCommand(buffer) abort
|
||||
return ale_linters#sass#stylelint#GetExecutable(a:buffer)
|
||||
\ . ' --stdin-filename %s'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('sass', {
|
||||
\ 'name': 'stylelint',
|
||||
\ 'executable': 'stylelint',
|
||||
\ 'command': g:ale#util#stdin_wrapper . ' .sass stylelint',
|
||||
\ 'executable_callback': 'ale_linters#sass#stylelint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#sass#stylelint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
|
||||
\})
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
" Author: diartyz <diartyz@gmail.com>
|
||||
|
||||
let g:ale_scss_stylelint_executable =
|
||||
\ get(g:, 'ale_scss_stylelint_executable', 'stylelint')
|
||||
|
||||
let g:ale_scss_stylelint_use_global =
|
||||
\ get(g:, 'ale_scss_stylelint_use_global', 0)
|
||||
|
||||
function! ale_linters#scss#stylelint#GetExecutable(buffer) abort
|
||||
if g:ale_scss_stylelint_use_global
|
||||
return g:ale_scss_stylelint_executable
|
||||
endif
|
||||
|
||||
return ale#util#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
\ 'node_modules/.bin/stylelint',
|
||||
\ g:ale_scss_stylelint_executable
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#scss#stylelint#GetCommand(buffer) abort
|
||||
return ale_linters#scss#stylelint#GetExecutable(a:buffer)
|
||||
\ . ' --stdin-filename %s'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('scss', {
|
||||
\ 'name': 'stylelint',
|
||||
\ 'executable': 'stylelint',
|
||||
\ 'command': g:ale#util#stdin_wrapper . ' .scss stylelint',
|
||||
\ 'executable_callback': 'ale_linters#scss#stylelint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#scss#stylelint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
|
||||
\})
|
||||
|
|
|
@ -203,8 +203,8 @@ function! ale#handlers#HandleStyleLintFormat(buffer, lines) abort
|
|||
continue
|
||||
endif
|
||||
|
||||
let l:text = l:match[4]
|
||||
let l:type = l:match[3]
|
||||
let l:type = l:match[3] ==# '✖' ? 'E' : 'W'
|
||||
let l:text = l:match[4] . '[' . l:match[5] . ']'
|
||||
|
||||
" vcol is Needed to indicate that the column is a character.
|
||||
call add(l:output, {
|
||||
|
@ -213,7 +213,7 @@ function! ale#handlers#HandleStyleLintFormat(buffer, lines) abort
|
|||
\ 'vcol': 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'text': l:text,
|
||||
\ 'type': l:type ==# '✖' ? 'E' : 'W',
|
||||
\ 'type': l:type,
|
||||
\ 'nr': -1,
|
||||
\})
|
||||
endfor
|
||||
|
|
90
doc/ale.txt
90
doc/ale.txt
|
@ -600,6 +600,27 @@ g:ale_html_htmlhint_options *g:ale_html_htmlhint_options*
|
|||
|
||||
This variable can be changed to modify flags given to HTMLHint.
|
||||
|
||||
g:ale_html_htmlhint_executable *g:ale_html_htmlhint_executable*
|
||||
|
||||
Type: |String|
|
||||
Default: `'htmlhint'`
|
||||
|
||||
ALE will first discover the htmlhint path in an ancestor node_modules
|
||||
directory. If no such path exists, this variable will be used instead.
|
||||
|
||||
If you wish to use only a globally installed version of htmlhint, set
|
||||
|g:ale_html_htmlhint_use_global| to `1`.
|
||||
|
||||
|
||||
g:ale_html_htmlhint_use_global *g:ale_html_htmlhint_use_global*
|
||||
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
This variable controls whether or not ALE will search for a local path for
|
||||
htmlhint first. If this variable is set to `1`, then ALE will always use the
|
||||
global version of htmlhint, in preference to locally installed versions of
|
||||
htmlhint in node_modules.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
4.16. c-clang *ale-linter-options-c-clang*
|
||||
|
@ -676,6 +697,75 @@ g:ale_lacheck_executable *g:ale_lacheck_executable*
|
|||
|
||||
This variable can be changed to change the path to lacheck.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
4.21. stylelint *ale-linter-options-stylelint*
|
||||
|
||||
g:ale_css_stylelint_executable *g:ale_css_stylelint_executable*
|
||||
|
||||
Type: |String|
|
||||
Default: `'stylelint'`
|
||||
|
||||
ALE will first discover the stylelint path in an ancestor node_modules
|
||||
directory. If no such path exists, this variable will be used instead.
|
||||
|
||||
If you wish to use only a globally installed version of stylelint, set
|
||||
|g:ale_css_stylelint_use_global| to `1`.
|
||||
|
||||
|
||||
g:ale_css_stylelint_use_global *g:ale_css_stylelint_use_global*
|
||||
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
This variable controls whether or not ALE will search for a local path for
|
||||
stylelint first. If this variable is set to `1`, then ALE will always use the
|
||||
global version of stylelint, in preference to locally installed versions of
|
||||
stylelint in node_modules.
|
||||
|
||||
g:ale_scss_stylelint_executable *g:ale_scss_stylelint_executable*
|
||||
|
||||
Type: |String|
|
||||
Default: `'stylelint'`
|
||||
|
||||
ALE will first discover the stylelint path in an ancestor node_modules
|
||||
directory. If no such path exists, this variable will be used instead.
|
||||
|
||||
If you wish to use only a globally installed version of stylelint, set
|
||||
|g:ale_scss_stylelint_use_global| to `1`.
|
||||
|
||||
|
||||
g:ale_scss_stylelint_use_global *g:ale_scss_stylelint_use_global*
|
||||
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
This variable controls whether or not ALE will search for a local path for
|
||||
stylelint first. If this variable is set to `1`, then ALE will always use the
|
||||
global version of stylelint, in preference to locally installed versions of
|
||||
stylelint in node_modules.
|
||||
|
||||
g:ale_scss_stylelint_executable *g:ale_scss_stylelint_executable*
|
||||
|
||||
Type: |String|
|
||||
Default: `'stylelint'`
|
||||
|
||||
ALE will first discover the stylelint path in an ancestor node_modules
|
||||
directory. If no such path exists, this variable will be used instead.
|
||||
|
||||
If you wish to use only a globally installed version of stylelint, set
|
||||
|g:ale_scss_stylelint_use_global| to `1`.
|
||||
|
||||
|
||||
g:ale_scss_stylelint_use_global *g:ale_scss_stylelint_use_global*
|
||||
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
This variable controls whether or not ALE will search for a local path for
|
||||
stylelint first. If this variable is set to `1`, then ALE will always use the
|
||||
global version of stylelint, in preference to locally installed versions of
|
||||
stylelint in node_modules.
|
||||
|
||||
===============================================================================
|
||||
5. Linter Integration Notes *ale-linter-integration*
|
||||
|
||||
|
|
Reference in a new issue