mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-11 15:01:57 +08:00
Skip whitespace warnings from ruff, if so configured
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
This commit is contained in:
@@ -72,20 +72,31 @@ function! ale_linters#python#ruff#Handle(buffer, lines) abort
|
|||||||
try
|
try
|
||||||
let l:item = json_decode(l:line)
|
let l:item = json_decode(l:line)
|
||||||
catch
|
catch
|
||||||
let l:item = v:null
|
" If we can't decode a line, skip it.
|
||||||
|
continue
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if !empty(l:item)
|
if (l:item.code is# 'W291' || l:item.code is# 'W293')
|
||||||
call add(l:output, {
|
\&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
|
||||||
\ 'lnum': l:item.location.row,
|
" Skip warnings for trailing whitespace if the option is off.
|
||||||
\ 'col': l:item.location.column,
|
continue
|
||||||
\ 'end_lnum': l:item.end_location.row,
|
|
||||||
\ 'end_col': l:item.end_location.column - 1,
|
|
||||||
\ 'code': l:item.code,
|
|
||||||
\ 'text': l:item.message,
|
|
||||||
\ 'type': l:item.code =~? '\vE\d+' ? 'E' : 'W',
|
|
||||||
\})
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if l:item.code is# 'W391'
|
||||||
|
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
|
||||||
|
" Skip warnings for trailing blank lines if the option is off
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'lnum': l:item.location.row,
|
||||||
|
\ 'col': l:item.location.column,
|
||||||
|
\ 'end_lnum': l:item.end_location.row,
|
||||||
|
\ 'end_col': l:item.end_location.column - 1,
|
||||||
|
\ 'code': l:item.code,
|
||||||
|
\ 'text': l:item.message,
|
||||||
|
\ 'type': l:item.code =~? '\vE\d+' ? 'E' : 'W',
|
||||||
|
\})
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
Before:
|
Before:
|
||||||
|
Save g:ale_warn_about_trailing_blank_lines
|
||||||
|
Save g:ale_warn_about_trailing_whitespace
|
||||||
|
|
||||||
|
let g:ale_warn_about_trailing_blank_lines = 1
|
||||||
|
let g:ale_warn_about_trailing_whitespace = 1
|
||||||
|
|
||||||
runtime ale_linters/python/ruff.vim
|
runtime ale_linters/python/ruff.vim
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
unlet! b:ale_warn_about_trailing_blank_lines
|
||||||
|
unlet! b:ale_warn_about_trailing_whitespace
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(We should handle basic output of ruff correctly):
|
Execute(We should handle basic output of ruff correctly):
|
||||||
@@ -41,3 +52,66 @@ Execute(We should handle mixed error lines and JSON output from ruff):
|
|||||||
\ 'ERROR: oh noes!',
|
\ 'ERROR: oh noes!',
|
||||||
\ '{"cell":null,"code":"F821","end_location":{"column":8,"row":2},"filename":"/home/eduardo/Code/Python/test.py","fix":null,"location":{"column":1,"row":2},"message":"Undefined name example","noqa_row":2,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}',
|
\ '{"cell":null,"code":"F821","end_location":{"column":8,"row":2},"filename":"/home/eduardo/Code/Python/test.py","fix":null,"location":{"column":1,"row":2},"message":"Undefined name example","noqa_row":2,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(Warnings about trailing whitespace should be reported by default):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W291',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'who cares',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W293',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'who cares',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W291","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ '{"cell":null,"code":"W293","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Disabling trailing whitespace warnings should work):
|
||||||
|
let b:ale_warn_about_trailing_whitespace = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W291","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ '{"cell":null,"code":"W293","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Warnings about trailing blank lines should be reported by default):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W391',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'blank line at end of file',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W391","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"blank line at end of file","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Disabling trailing blank line warnings should work):
|
||||||
|
let b:ale_warn_about_trailing_blank_lines = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W391","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"blank line at end of file","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user