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
11 changed files with 163 additions and 32 deletions
|
@ -1,9 +1,28 @@
|
||||||
" Author: KabbAmine - https://github.com/KabbAmine,
|
" Author: sQVe - https://github.com/sQVe
|
||||||
" Ben Falconer <ben@falconers.me.uk>
|
|
||||||
|
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', {
|
call ale#linter#Define('sass', {
|
||||||
\ 'name': 'sasslint',
|
\ 'name': 'sasslint',
|
||||||
\ 'executable': 'sass-lint',
|
\ 'executable_callback': 'ale_linters#sass#sasslint#GetExecutable',
|
||||||
\ 'command_callback': 'ale#handlers#sasslint#GetCommand',
|
\ 'command_callback': 'ale_linters#sass#sasslint#GetCommand',
|
||||||
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
|
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -1,18 +1,28 @@
|
||||||
" Author: KabbAmine - https://github.com/KabbAmine, Ben Falconer
|
" Author: sQVe - https://github.com/sQVe
|
||||||
" <ben@falconers.me.uk>
|
|
||||||
|
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
|
function! ale_linters#scss#sasslint#GetCommand(buffer) abort
|
||||||
return ale#path#BufferCdString(a:buffer)
|
let l:executable = ale_linters#scss#sasslint#GetExecutable(a:buffer)
|
||||||
\ . ale#Escape('sass-lint')
|
let l:options = ale#Var(a:buffer, 'scss_sasslint_options')
|
||||||
\ . ' -v'
|
|
||||||
\ . ' -q'
|
return ale#node#Executable(a:buffer, l:executable)
|
||||||
\ . ' -f compact'
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . ' %t'
|
\ . ' -v -q -f compact %t'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('scss', {
|
call ale#linter#Define('scss', {
|
||||||
\ 'name': 'sasslint',
|
\ 'name': 'sasslint',
|
||||||
\ 'executable': 'sass-lint',
|
\ 'executable_callback': 'ale_linters#scss#sasslint#GetExecutable',
|
||||||
\ 'command_callback': 'ale_linters#scss#sasslint#GetCommand',
|
\ 'command_callback': 'ale_linters#scss#sasslint#GetCommand',
|
||||||
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
|
\ '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*
|
ALE SASS Integration *ale-sass-options*
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
sasslint *ale-sass-sasslint*
|
||||||
|
|
||||||
|
See |ale-scss-sasslint| for information about the available options.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
stylelint *ale-sass-stylelint*
|
stylelint *ale-sass-stylelint*
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,33 @@ prettier *ale-scss-prettier*
|
||||||
See |ale-javascript-prettier| for information about the available options.
|
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*
|
stylelint *ale-scss-stylelint*
|
||||||
|
|
||||||
|
|
|
@ -288,6 +288,7 @@ CONTENTS *ale-contents*
|
||||||
rustc...............................|ale-rust-rustc|
|
rustc...............................|ale-rust-rustc|
|
||||||
rustfmt.............................|ale-rust-rustfmt|
|
rustfmt.............................|ale-rust-rustfmt|
|
||||||
sass..................................|ale-sass-options|
|
sass..................................|ale-sass-options|
|
||||||
|
sasslint............................|ale-sass-sasslint|
|
||||||
stylelint...........................|ale-sass-stylelint|
|
stylelint...........................|ale-sass-stylelint|
|
||||||
scala.................................|ale-scala-options|
|
scala.................................|ale-scala-options|
|
||||||
sbtserver...........................|ale-scala-sbtserver|
|
sbtserver...........................|ale-scala-sbtserver|
|
||||||
|
@ -295,6 +296,7 @@ CONTENTS *ale-contents*
|
||||||
scalastyle..........................|ale-scala-scalastyle|
|
scalastyle..........................|ale-scala-scalastyle|
|
||||||
scss..................................|ale-scss-options|
|
scss..................................|ale-scss-options|
|
||||||
prettier............................|ale-scss-prettier|
|
prettier............................|ale-scss-prettier|
|
||||||
|
sasslint............................|ale-scss-sasslint|
|
||||||
stylelint...........................|ale-scss-stylelint|
|
stylelint...........................|ale-scss-stylelint|
|
||||||
sh....................................|ale-sh-options|
|
sh....................................|ale-sh-options|
|
||||||
sh-language-server..................|ale-sh-language-server|
|
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'
|
Reference in a new issue