mirror of https://github.com/dense-analysis/ale
refactor sasslint linter (#2077)
Previous implementation required one to have sass-lint globally. This allows you to have it locally, override the executable and add options.
This commit is contained in:
parent
dc61d46e28
commit
2760cf7018
|
@ -1,9 +1,28 @@
|
|||
" Author: KabbAmine - https://github.com/KabbAmine,
|
||||
" Ben Falconer <ben@falconers.me.uk>
|
||||
" Author: sQVe - https://github.com/sQVe
|
||||
|
||||
call ale#Set('sass_sasslint_executable', 'sass-lint')
|
||||
call ale#Set('sass_sasslint_options', '')
|
||||
call ale#Set('sass_sasslint_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
|
||||
function! ale_linters#sass#sasslint#GetExecutable(buffer) abort
|
||||
return ale#node#FindExecutable(a:buffer, 'sass_sasslint', [
|
||||
\ 'node_modules/sass-lint/bin/sass-lint.js',
|
||||
\ 'node_modules/.bin/sass-lint',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sass#sasslint#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#sass#sasslint#GetExecutable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'sass_sasslint_options')
|
||||
|
||||
return ale#node#Executable(a:buffer, l:executable)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' -v -q -f compact %t'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('sass', {
|
||||
\ 'name': 'sasslint',
|
||||
\ 'executable': 'sass-lint',
|
||||
\ 'command_callback': 'ale#handlers#sasslint#GetCommand',
|
||||
\ 'executable_callback': 'ale_linters#sass#sasslint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#sass#sasslint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
|
||||
\})
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
" Author: KabbAmine - https://github.com/KabbAmine, Ben Falconer
|
||||
" <ben@falconers.me.uk>
|
||||
" Author: sQVe - https://github.com/sQVe
|
||||
|
||||
call ale#Set('scss_sasslint_executable', 'sass-lint')
|
||||
call ale#Set('scss_sasslint_options', '')
|
||||
call ale#Set('scss_sasslint_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
|
||||
function! ale_linters#scss#sasslint#GetExecutable(buffer) abort
|
||||
return ale#node#FindExecutable(a:buffer, 'scss_sasslint', [
|
||||
\ 'node_modules/sass-lint/bin/sass-lint.js',
|
||||
\ 'node_modules/.bin/sass-lint',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#scss#sasslint#GetCommand(buffer) abort
|
||||
return ale#path#BufferCdString(a:buffer)
|
||||
\ . ale#Escape('sass-lint')
|
||||
\ . ' -v'
|
||||
\ . ' -q'
|
||||
\ . ' -f compact'
|
||||
\ . ' %t'
|
||||
let l:executable = ale_linters#scss#sasslint#GetExecutable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'scss_sasslint_options')
|
||||
|
||||
return ale#node#Executable(a:buffer, l:executable)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' -v -q -f compact %t'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('scss', {
|
||||
\ 'name': 'sasslint',
|
||||
\ 'executable': 'sass-lint',
|
||||
\ 'executable_callback': 'ale_linters#scss#sasslint#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#scss#sasslint#GetCommand',
|
||||
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
|
||||
\})
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
" Author: KabbAmine - https://github.com/KabbAmine,
|
||||
" Ben Falconer <ben@falconers.me.uk>
|
||||
|
||||
function! ale#handlers#sasslint#GetCommand(buffer) abort
|
||||
return ale#path#BufferCdString(a:buffer)
|
||||
\ . ale#Escape('sass-lint')
|
||||
\ . ' -v -q -f compact %t'
|
||||
endfunction
|
|
@ -2,6 +2,12 @@
|
|||
ALE SASS Integration *ale-sass-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
sasslint *ale-sass-sasslint*
|
||||
|
||||
See |ale-scss-sasslint| for information about the available options.
|
||||
|
||||
|
||||
===============================================================================
|
||||
stylelint *ale-sass-stylelint*
|
||||
|
||||
|
|
|
@ -8,6 +8,33 @@ prettier *ale-scss-prettier*
|
|||
See |ale-javascript-prettier| for information about the available options.
|
||||
|
||||
|
||||
===============================================================================
|
||||
sasslint *ale-scss-sasslint*
|
||||
|
||||
g:ale_scss_sasslint_executable *g:ale_scss_sasslint_executable*
|
||||
*b:ale_scss_sasslint_executable*
|
||||
Type: |String|
|
||||
Default: `'sass-lint'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
g:ale_scss_sasslint_options *g:ale_scss_sasslint_options*
|
||||
*b:ale_scss_sasslint_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to sass-lint.
|
||||
|
||||
|
||||
g:ale_scss_sasslint_use_global *g:ale_scss_sasslint_use_global*
|
||||
*b:ale_scss_sasslint_use_global*
|
||||
Type: |Number|
|
||||
Default: `get(g:, 'ale_use_global_executables', 0)`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
===============================================================================
|
||||
stylelint *ale-scss-stylelint*
|
||||
|
||||
|
|
|
@ -288,6 +288,7 @@ CONTENTS *ale-contents*
|
|||
rustc...............................|ale-rust-rustc|
|
||||
rustfmt.............................|ale-rust-rustfmt|
|
||||
sass..................................|ale-sass-options|
|
||||
sasslint............................|ale-sass-sasslint|
|
||||
stylelint...........................|ale-sass-stylelint|
|
||||
scala.................................|ale-scala-options|
|
||||
sbtserver...........................|ale-scala-sbtserver|
|
||||
|
@ -295,6 +296,7 @@ CONTENTS *ale-contents*
|
|||
scalastyle..........................|ale-scala-scalastyle|
|
||||
scss..................................|ale-scss-options|
|
||||
prettier............................|ale-scss-prettier|
|
||||
sasslint............................|ale-scss-sasslint|
|
||||
stylelint...........................|ale-scss-stylelint|
|
||||
sh....................................|ale-sh-options|
|
||||
sh-language-server..................|ale-sh-language-server|
|
||||
|
|
0
test/command_callback/sasslint-test-files/with-bin/node_modules/.bin/sass-lint
generated
vendored
Executable file
0
test/command_callback/sasslint-test-files/with-bin/node_modules/.bin/sass-lint
generated
vendored
Executable file
0
test/command_callback/sasslint-test-files/with-source/node_modules/sass-lint/bin/sass-lint.js
generated
vendored
Executable file
0
test/command_callback/sasslint-test-files/with-source/node_modules/sass-lint/bin/sass-lint.js
generated
vendored
Executable file
|
@ -0,0 +1,43 @@
|
|||
Before:
|
||||
call ale#assert#SetUpLinterTest('sass', 'sasslint')
|
||||
call ale#test#SetFilename('test.sass')
|
||||
unlet! b:executable
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(should default to source, bin/sass-lint.js):
|
||||
call ale#test#SetFilename('sasslint-test-files/with-source/test.sass')
|
||||
|
||||
let b:executable = ale#path#Simplify(
|
||||
\ g:dir
|
||||
\ . '/sasslint-test-files/with-source/node_modules/sass-lint/bin/sass-lint.js'
|
||||
\)
|
||||
|
||||
AssertLinter b:executable,
|
||||
\ (has('win32') ? 'node.exe ' : '')
|
||||
\ . ale#Escape(b:executable)
|
||||
\ . ' -v -q -f compact %t'
|
||||
|
||||
Execute(should fallback to bin, .bin/sass-lint):
|
||||
call ale#test#SetFilename('sasslint-test-files/with-bin/test.sass')
|
||||
|
||||
let b:executable = ale#path#Simplify(
|
||||
\ g:dir
|
||||
\ . '/sasslint-test-files/with-bin/node_modules/.bin/sass-lint'
|
||||
\)
|
||||
|
||||
AssertLinter b:executable, ale#Escape(b:executable) . ' -v -q -f compact %t'
|
||||
|
||||
Execute(should fallback to global bin):
|
||||
AssertLinter 'sass-lint', ale#Escape('sass-lint') . ' -v -q -f compact %t'
|
||||
|
||||
Execute(The global executable should be configurable):
|
||||
let b:ale_sass_sasslint_executable = 'foo'
|
||||
|
||||
AssertLinter 'foo', ale#Escape('foo') . ' -v -q -f compact %t'
|
||||
|
||||
Execute(The options should be configurable):
|
||||
let b:ale_sass_sasslint_options = '--bar'
|
||||
|
||||
AssertLinter 'sass-lint', ale#Escape('sass-lint') . ' --bar -v -q -f compact %t'
|
|
@ -1,11 +0,0 @@
|
|||
Before:
|
||||
call ale#assert#SetUpLinterTest('sass', 'sasslint')
|
||||
call ale#test#SetFilename('test.sass')
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The default sasslint command should be correct):
|
||||
AssertLinter 'sass-lint',
|
||||
\ ale#path#CdString(expand('%:p:h'))
|
||||
\ . ale#Escape('sass-lint') . ' -v -q -f compact %t'
|
|
@ -0,0 +1,43 @@
|
|||
Before:
|
||||
call ale#assert#SetUpLinterTest('scss', 'sasslint')
|
||||
call ale#test#SetFilename('test.scss')
|
||||
unlet! b:executable
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(should default to source, bin/sass-lint.js):
|
||||
call ale#test#SetFilename('sasslint-test-files/with-source/test.scss')
|
||||
|
||||
let b:executable = ale#path#Simplify(
|
||||
\ g:dir
|
||||
\ . '/sasslint-test-files/with-source/node_modules/sass-lint/bin/sass-lint.js'
|
||||
\)
|
||||
|
||||
AssertLinter b:executable,
|
||||
\ (has('win32') ? 'node.exe ' : '')
|
||||
\ . ale#Escape(b:executable)
|
||||
\ . ' -v -q -f compact %t'
|
||||
|
||||
Execute(should fallback to bin, .bin/sass-lint):
|
||||
call ale#test#SetFilename('sasslint-test-files/with-bin/test.scss')
|
||||
|
||||
let b:executable = ale#path#Simplify(
|
||||
\ g:dir
|
||||
\ . '/sasslint-test-files/with-bin/node_modules/.bin/sass-lint'
|
||||
\)
|
||||
|
||||
AssertLinter b:executable, ale#Escape(b:executable) . ' -v -q -f compact %t'
|
||||
|
||||
Execute(should fallback to global bin):
|
||||
AssertLinter 'sass-lint', ale#Escape('sass-lint') . ' -v -q -f compact %t'
|
||||
|
||||
Execute(The global executable should be configurable):
|
||||
let b:ale_scss_sasslint_executable = 'foo'
|
||||
|
||||
AssertLinter 'foo', ale#Escape('foo') . ' -v -q -f compact %t'
|
||||
|
||||
Execute(The options should be configurable):
|
||||
let b:ale_scss_sasslint_options = '--bar'
|
||||
|
||||
AssertLinter 'sass-lint', ale#Escape('sass-lint') . ' --bar -v -q -f compact %t'
|
Loading…
Reference in New Issue