From de2d3da73834d36defba03865bed733c2a77ce4a Mon Sep 17 00:00:00 2001 From: Steve Matney Date: Sat, 22 Nov 2025 05:00:41 -0700 Subject: [PATCH] Adding --no-color flag to stylelint args (#5050) * Adding --no-color flag to sass stylelint * Adding --no-color to all stylelint args * Adding --no-color expectation to stylelint tests * Properly handling SyntaxError for stylelint; adding corresponding test * Fixing CSS stylelint parameters and adding regression test --- ale_linters/css/stylelint.vim | 2 +- ale_linters/html/stylelint.vim | 2 +- ale_linters/less/stylelint.vim | 2 +- ale_linters/sass/stylelint.vim | 2 +- ale_linters/scss/stylelint.vim | 2 +- ale_linters/stylus/stylelint.vim | 2 +- ale_linters/sugarss/stylelint.vim | 2 +- autoload/ale/fixers/stylelint.vim | 2 +- autoload/ale/handlers/css.vim | 2 +- .../test_stylelint_fixer_callback.vader | 4 +-- test/handler/test_stylelint_handler.vader | 23 +++++++++++++ test/linter/test_css_stylelint.vader | 33 +++++++++++++++++++ test/linter/test_html_stylelint.vader | 6 ++-- test/linter/test_less_stylelint.vader | 6 ++-- test/linter/test_scss_stylelint.vader | 6 ++-- test/linter/test_sugarss_stylelint.vader | 6 ++-- 16 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 test/linter/test_css_stylelint.vader diff --git a/ale_linters/css/stylelint.vim b/ale_linters/css/stylelint.vim index ceb42461..edd678d3 100644 --- a/ale_linters/css/stylelint.vim +++ b/ale_linters/css/stylelint.vim @@ -6,7 +6,7 @@ call ale#Set('css_stylelint_use_global', get(g:, 'ale_use_global_executables', 0 function! ale_linters#css#stylelint#GetCommand(buffer) abort return '%e ' . ale#Pad(ale#Var(a:buffer, 'css_stylelint_options')) - \ . ' --stdin-filename %s' + \ . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('css', { diff --git a/ale_linters/html/stylelint.vim b/ale_linters/html/stylelint.vim index c191c468..a95e4080 100644 --- a/ale_linters/html/stylelint.vim +++ b/ale_linters/html/stylelint.vim @@ -16,7 +16,7 @@ function! ale_linters#html#stylelint#GetCommand(buffer) abort return ale#Escape(l:executable) \ . (!empty(l:options) ? ' ' . l:options : '') - \ . ' --stdin-filename %s' + \ . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('html', { diff --git a/ale_linters/less/stylelint.vim b/ale_linters/less/stylelint.vim index 9430fe9b..28bb1c8e 100644 --- a/ale_linters/less/stylelint.vim +++ b/ale_linters/less/stylelint.vim @@ -7,7 +7,7 @@ call ale#Set('less_stylelint_use_global', get(g:, 'ale_use_global_executables', function! ale_linters#less#stylelint#GetCommand(buffer) abort let l:options = ale#Var(a:buffer, 'less_stylelint_options') - return '%e' . ale#Pad(l:options) . ' --stdin-filename %s' + return '%e' . ale#Pad(l:options) . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('less', { diff --git a/ale_linters/sass/stylelint.vim b/ale_linters/sass/stylelint.vim index 651d7fd5..725d7c4a 100644 --- a/ale_linters/sass/stylelint.vim +++ b/ale_linters/sass/stylelint.vim @@ -9,6 +9,6 @@ call ale#linter#Define('sass', { \ 'executable': {b -> ale#path#FindExecutable(b, 'sass_stylelint', [ \ 'node_modules/.bin/stylelint', \ ])}, -\ 'command': '%e --stdin-filename %s', +\ 'command': '%e --no-color --stdin-filename %s', \ 'callback': 'ale#handlers#css#HandleStyleLintFormat', \}) diff --git a/ale_linters/scss/stylelint.vim b/ale_linters/scss/stylelint.vim index 4f82a98a..d31928b3 100644 --- a/ale_linters/scss/stylelint.vim +++ b/ale_linters/scss/stylelint.vim @@ -6,7 +6,7 @@ call ale#Set('scss_stylelint_use_global', get(g:, 'ale_use_global_executables', function! ale_linters#scss#stylelint#GetCommand(buffer) abort return '%e ' . ale#Pad(ale#Var(a:buffer, 'scss_stylelint_options')) - \ . ' --stdin-filename %s' + \ . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('scss', { diff --git a/ale_linters/stylus/stylelint.vim b/ale_linters/stylus/stylelint.vim index 652e15d2..ce23a13d 100644 --- a/ale_linters/stylus/stylelint.vim +++ b/ale_linters/stylus/stylelint.vim @@ -7,7 +7,7 @@ call ale#Set('stylus_stylelint_use_global', get(g:, 'ale_use_global_executables' function! ale_linters#stylus#stylelint#GetCommand(buffer) abort return '%e' \ . ale#Pad(ale#Var(a:buffer, 'stylus_stylelint_options')) - \ . ' --stdin-filename %s' + \ . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('stylus', { diff --git a/ale_linters/sugarss/stylelint.vim b/ale_linters/sugarss/stylelint.vim index a12191b8..d3803c0f 100644 --- a/ale_linters/sugarss/stylelint.vim +++ b/ale_linters/sugarss/stylelint.vim @@ -8,7 +8,7 @@ call ale#Set('sugarss_stylelint_use_global', get(g:, 'ale_use_global_executables function! ale_linters#sugarss#stylelint#GetCommand(buffer) abort return '%e ' . ale#Pad(ale#Var(a:buffer, 'sugarss_stylelint_options')) \ . ' --syntax=sugarss' - \ . ' --stdin-filename %s' + \ . ' --no-color --stdin-filename %s' endfunction call ale#linter#Define('sugarss', { diff --git a/autoload/ale/fixers/stylelint.vim b/autoload/ale/fixers/stylelint.vim index 650b9c4a..0ce880f0 100644 --- a/autoload/ale/fixers/stylelint.vim +++ b/autoload/ale/fixers/stylelint.vim @@ -20,7 +20,7 @@ function! ale#fixers#stylelint#Fix(buffer) abort \ 'cwd': '%s:h', \ 'command': ale#node#Executable(a:buffer, l:executable) \ . ale#Pad(l:options) - \ . ' --fix --stdin --stdin-filename %s', + \ . ' --fix --stdin --no-color --stdin-filename %s', \ 'read_temporary_file': 0, \} endfunction diff --git a/autoload/ale/handlers/css.vim b/autoload/ale/handlers/css.vim index de9eadcc..a6fa4531 100644 --- a/autoload/ale/handlers/css.vim +++ b/autoload/ale/handlers/css.vim @@ -36,7 +36,7 @@ function! ale#handlers#css#HandleCSSLintFormat(buffer, lines) abort endfunction function! ale#handlers#css#HandleStyleLintFormat(buffer, lines) abort - let l:exception_pattern = '\v^Error:' + let l:exception_pattern = '\v^(Syntax)?Error:' for l:line in a:lines[:10] if len(matchlist(l:line, l:exception_pattern)) > 0 diff --git a/test/fixers/test_stylelint_fixer_callback.vader b/test/fixers/test_stylelint_fixer_callback.vader index ee7cfdd4..b3171ef4 100644 --- a/test/fixers/test_stylelint_fixer_callback.vader +++ b/test/fixers/test_stylelint_fixer_callback.vader @@ -17,7 +17,7 @@ Execute(The stylelint callback should return the correct default values): \ 'cwd': '%s:h', \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/stylelint/bin/stylelint.js')) - \ . ' --fix --stdin --stdin-filename %s', + \ . ' --fix --stdin --no-color --stdin-filename %s', \ } Execute(The stylelint callback should include custom stylelint options): @@ -30,5 +30,5 @@ Execute(The stylelint callback should include custom stylelint options): \ 'cwd': '%s:h', \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/stylelint/bin/stylelint.js')) - \ . ' --cache --fix --stdin --stdin-filename %s', + \ . ' --cache --fix --stdin --no-color --stdin-filename %s', \ } diff --git a/test/handler/test_stylelint_handler.vader b/test/handler/test_stylelint_handler.vader index 5cb34601..251691e5 100644 --- a/test/handler/test_stylelint_handler.vader +++ b/test/handler/test_stylelint_handler.vader @@ -41,3 +41,26 @@ Execute (stylelint should complain when no configuration file is used): \ 'detail': join(g:error_lines, "\n"), \ }], \ ale#handlers#css#HandleStyleLintFormat(347, g:error_lines[:]) + +Execute (stylelint should complain but not blow up when SyntaxError is encountered): + let g:error_lines = [ + \ 'SyntaxError: Unexpected token, expected "," (136:4)', + \ ' at constructor (/home/ts-project/node_modules/@babel/parser/lib/index.js:367:19)', + \ ' at TypeScriptParserMixin.raise (/home/ts-project/node_modules/@babel/parser/lib/index.js:6630:19)', + \ ' at TypeScriptParserMixin.unexpected (/home/ts-project/node_modules/@babel/parser/lib/index.js:6650:16)', + \ ' at TypeScriptParserMixin.expect (/home/ts-project/node_modules/@babel/parser/lib/index.js:6930:12)', + \ ' at TypeScriptParserMixin.tsParseDelimitedListWorker (/home/ts-project/node_modules/@babel/parser/lib/index.js:7932:14)', + \ ' at TypeScriptParserMixin.tsParseDelimitedList (/home/ts-project/node_modules/@babel/parser/lib/index.js:7909:25)', + \ ' at /home/ts-project/node_modules/@babel/parser/lib/index.js:9170:19', + \ ' at TypeScriptParserMixin.tsInTopLevelContext (/home/ts-project/node_modules/@babel/parser/lib/index.js:8834:14)', + \ ' at /home/ts-project/node_modules/@babel/parser/lib/index.js:9168:44', + \ ' at TypeScriptParserMixin.tsInType (/home/ts-project/node_modules/@babel/parser/lib/index.js:8841:14)', + \] + + AssertEqual + \ [{ + \ 'lnum': 1, + \ 'text': 'stylelint exception thrown (type :ALEDetail for more information)', + \ 'detail': join(g:error_lines, "\n"), + \ }], + \ ale#handlers#css#HandleStyleLintFormat(347, g:error_lines[:]) diff --git a/test/linter/test_css_stylelint.vader b/test/linter/test_css_stylelint.vader new file mode 100644 index 00000000..b6164471 --- /dev/null +++ b/test/linter/test_css_stylelint.vader @@ -0,0 +1,33 @@ +Before: + call ale#assert#SetUpLinterTest('css', 'stylelint') + unlet! b:executable + +After: + unlet! b:executable + call ale#assert#TearDownLinterTest() + +Execute(node_modules directories should be discovered): + call ale#test#SetFilename('../test-files/stylelint/nested/testfile.css') + + let b:executable = ale#path#Simplify( + \ g:dir + \ . '/../test-files/stylelint/node_modules/.bin/stylelint' + \) + + AssertLinter b:executable, ale#Escape(b:executable) . ' --no-color --stdin-filename %s' + +Execute(The global override should work): + let b:ale_css_stylelint_executable = 'foobar' + let b:ale_css_stylelint_use_global = 1 + + call ale#test#SetFilename('../test-files/stylelint/nested/testfile.css') + + AssertLinter 'foobar', ale#Escape('foobar') . ' --no-color --stdin-filename %s' + +Execute(Extra options should be configurable): + call ale#test#SetFilename('../test-files/dummy') + + let b:ale_css_stylelint_options = '--configFile ''/absolute/path/to/file''' + + AssertLinter 'stylelint', + \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --no-color --stdin-filename %s' diff --git a/test/linter/test_html_stylelint.vader b/test/linter/test_html_stylelint.vader index c5ac1b98..5f50cbd4 100644 --- a/test/linter/test_html_stylelint.vader +++ b/test/linter/test_html_stylelint.vader @@ -37,7 +37,7 @@ Execute(node_modules directories should be discovered): AssertEqual b:executable, ale_linters#html#stylelint#GetExecutable(bufnr('')) AssertEqual - \ ale#Escape(b:executable) . ' --stdin-filename %s', + \ ale#Escape(b:executable) . ' --no-color --stdin-filename %s', \ ale_linters#html#stylelint#GetCommand(bufnr('')) Execute(The global override should work): @@ -48,7 +48,7 @@ Execute(The global override should work): AssertEqual 'foobar', ale_linters#html#stylelint#GetExecutable(bufnr('')) AssertEqual - \ ale#Escape('foobar') . ' --stdin-filename %s', + \ ale#Escape('foobar') . ' --no-color --stdin-filename %s', \ ale_linters#html#stylelint#GetCommand(bufnr('')) Execute(Extra options should be configurable): @@ -56,5 +56,5 @@ Execute(Extra options should be configurable): AssertEqual 'stylelint', ale_linters#html#stylelint#GetExecutable(bufnr('')) AssertEqual - \ ale#Escape('stylelint') . ' --whatever --stdin-filename %s', + \ ale#Escape('stylelint') . ' --whatever --no-color --stdin-filename %s', \ ale_linters#html#stylelint#GetCommand(bufnr('')) diff --git a/test/linter/test_less_stylelint.vader b/test/linter/test_less_stylelint.vader index c27af79e..e1acf863 100644 --- a/test/linter/test_less_stylelint.vader +++ b/test/linter/test_less_stylelint.vader @@ -14,7 +14,7 @@ Execute(node_modules directories should be discovered): \ . '/../test-files/stylelint/node_modules/.bin/stylelint' \) - AssertLinter b:executable, ale#Escape(b:executable) . ' --stdin-filename %s' + AssertLinter b:executable, ale#Escape(b:executable) . ' --no-color --stdin-filename %s' Execute(The global override should work): let b:ale_less_stylelint_executable = 'foobar' @@ -22,11 +22,11 @@ Execute(The global override should work): call ale#test#SetFilename('../test-files/stylelint/nested/testfile.less') - AssertLinter 'foobar', ale#Escape('foobar') . ' --stdin-filename %s' + AssertLinter 'foobar', ale#Escape('foobar') . ' --no-color --stdin-filename %s' Execute(Extra options should be configurable): let b:ale_less_stylelint_options = '--whatever' call ale#test#SetFilename('../test-files/dummy') AssertLinter 'stylelint', - \ ale#Escape('stylelint') . ' --whatever --stdin-filename %s' + \ ale#Escape('stylelint') . ' --whatever --no-color --stdin-filename %s' diff --git a/test/linter/test_scss_stylelint.vader b/test/linter/test_scss_stylelint.vader index bf45ccd0..b4fedc7f 100644 --- a/test/linter/test_scss_stylelint.vader +++ b/test/linter/test_scss_stylelint.vader @@ -14,7 +14,7 @@ Execute(node_modules directories should be discovered): \ . '/../test-files/stylelint/node_modules/.bin/stylelint' \) - AssertLinter b:executable, ale#Escape(b:executable) . ' --stdin-filename %s' + AssertLinter b:executable, ale#Escape(b:executable) . ' --no-color --stdin-filename %s' Execute(The global override should work): let b:ale_scss_stylelint_executable = 'foobar' @@ -22,7 +22,7 @@ Execute(The global override should work): call ale#test#SetFilename('../test-files/stylelint/nested/testfile.scss') - AssertLinter 'foobar', ale#Escape('foobar') . ' --stdin-filename %s' + AssertLinter 'foobar', ale#Escape('foobar') . ' --no-color --stdin-filename %s' Execute(Extra options should be configurable): call ale#test#SetFilename('../test-files/dummy') @@ -30,4 +30,4 @@ Execute(Extra options should be configurable): let b:ale_scss_stylelint_options = '--configFile ''/absolute/path/to/file''' AssertLinter 'stylelint', - \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --stdin-filename %s' + \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --no-color --stdin-filename %s' diff --git a/test/linter/test_sugarss_stylelint.vader b/test/linter/test_sugarss_stylelint.vader index c6000a9a..2913489d 100644 --- a/test/linter/test_sugarss_stylelint.vader +++ b/test/linter/test_sugarss_stylelint.vader @@ -14,7 +14,7 @@ Execute(node_modules directories should be discovered): \ . '/../test-files/stylelint/node_modules/.bin/stylelint' \) - AssertLinter b:executable, ale#Escape(b:executable) . ' --syntax=sugarss --stdin-filename %s' + AssertLinter b:executable, ale#Escape(b:executable) . ' --syntax=sugarss --no-color --stdin-filename %s' Execute(The global override should work): let b:ale_sugarss_stylelint_executable = 'foobar' @@ -22,7 +22,7 @@ Execute(The global override should work): call ale#test#SetFilename('../test-files/stylelint/nested/testfile.sss') - AssertLinter 'foobar', ale#Escape('foobar') . ' --syntax=sugarss --stdin-filename %s' + AssertLinter 'foobar', ale#Escape('foobar') . ' --syntax=sugarss --no-color --stdin-filename %s' Execute(Extra options should be configurable): call ale#test#SetFilename('../test-files/dummy') @@ -30,4 +30,4 @@ Execute(Extra options should be configurable): let b:ale_sugarss_stylelint_options = '--configFile ''/absolute/path/to/file''' AssertLinter 'stylelint', - \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --syntax=sugarss --stdin-filename %s' + \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --syntax=sugarss --no-color --stdin-filename %s'