Files
ale/test/handler/test_ruff_handler.vader
T
Alex Fikl a1ff838e9e Add option to use human readable ruff errors (#5153)
* feat: add option to use human readable ruff errors

* test: add small test for python_ruff_human_readable
2026-08-19 10:44:51 +09:00

140 lines
4.8 KiB
Plaintext

Before:
Save g:ale_warn_about_trailing_blank_lines
Save g:ale_warn_about_trailing_whitespace
Save g:ale_python_ruff_human_readable
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
let g:ale_python_ruff_human_readable = 0
runtime ale_linters/python/ruff.vim
After:
Restore
unlet! b:ale_warn_about_trailing_blank_lines
unlet! b:ale_warn_about_trailing_whitespace
unlet! b:ale_python_ruff_human_readable
call ale#linter#Reset()
Execute(We should handle basic output of ruff correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'code': 'F821',
\ 'type': 'W',
\ 'end_col': 7,
\ 'end_lnum': 2,
\ 'text': 'Undefined name example',
\ },
\ ],
\ ale_linters#python#ruff#Handle(bufnr(''), [
\ '{"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(We should handle totally broken output from ruff):
AssertEqual [], ale_linters#python#ruff#Handle(bufnr(''), ['ERROR: oh noes!'])
Execute(We should handle mixed error lines and JSON output from ruff):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'code': 'F821',
\ 'type': 'W',
\ 'end_col': 7,
\ 'end_lnum': 2,
\ 'text': 'Undefined name example',
\ },
\ ],
\ ale_linters#python#ruff#Handle(bufnr(''), [
\ '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"}',
\ ])
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":""}',
\ ])
Execute(python_ruff_human_readable should use rule names instead of codes):
let b:ale_python_ruff_human_readable = 1
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'end_lnum': 2,
\ 'end_col': 7,
\ 'code': 'undefined-name',
\ 'type': 'W',
\ 'text': 'Undefined name example',
\ },
\ ],
\ ale_linters#python#ruff#Handle(bufnr(''), [
\ '{"cell":null,"code":"F821","end_location":{"column":8,"row":2},"filename":"/test.py","fix":null,"location":{"column":1,"row":2},"message":"Undefined name example","name":"undefined-name","noqa_row":2,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}',
\ ])