diff options
-rw-r--r-- | ale_linters/po/msgfmt.vim | 22 | ||||
-rw-r--r-- | test/handler/test_msgfmt_hander.vader | 24 |
2 files changed, 45 insertions, 1 deletions
diff --git a/ale_linters/po/msgfmt.vim b/ale_linters/po/msgfmt.vim index 578792bf..8279ccdc 100644 --- a/ale_linters/po/msgfmt.vim +++ b/ale_linters/po/msgfmt.vim @@ -1,10 +1,30 @@ " Author: Cian Butler https://github.com/butlerx " Description: msgfmt for PO files +function! ale_linters#po#msgfmt#Handle(buffer, lines) abort + let l:results = ale#handlers#unix#HandleAsWarning(a:buffer, a:lines) + let l:index = 0 + + for l:item in l:results + if l:index > 0 && l:item.text =~? 'this is the location of the first definition' + let l:last_item = l:results[l:index - 1] + + if l:last_item.text =~? 'duplicate message definition' + let l:last_item.text = 'duplicate of message at line ' . l:item.lnum + let l:item.text = 'first location of duplicate of message at line ' . l:last_item.lnum + endif + endif + + let l:index += 1 + endfor + + return l:results +endfunction + call ale#linter#Define('po', { \ 'name': 'msgfmt', \ 'executable': 'msgfmt', \ 'output_stream': 'stderr', \ 'command': 'msgfmt --statistics --output-file=- %t', -\ 'callback': 'ale#handlers#unix#HandleAsWarning', +\ 'callback': 'ale_linters#po#msgfmt#Handle', \}) diff --git a/test/handler/test_msgfmt_hander.vader b/test/handler/test_msgfmt_hander.vader new file mode 100644 index 00000000..1a67dbc6 --- /dev/null +++ b/test/handler/test_msgfmt_hander.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/po/msgfmt.vim + +After: + call ale#linter#Reset() + +Execute(Duplicate messages should be made easier to navigate): + AssertEqual + \ [ + \ {'lnum': 14, 'col': 0, 'type': 'W', 'text': 'some other thing'}, + \ {'lnum': 1746, 'col': 0, 'type': 'W', 'text': 'duplicate of message at line 262'}, + \ {'lnum': 262, 'col': 0, 'type': 'W', 'text': 'first location of duplicate of message at line 1746'}, + \ {'lnum': 666, 'col': 0, 'type': 'W', 'text': 'duplicate message definition...'}, + \ {'lnum': 888, 'col': 0, 'type': 'W', 'text': 'some other thing'}, + \ {'lnum': 999, 'col': 0, 'type': 'W', 'text': '...this is the location of the first definition'}, + \ ], + \ ale_linters#po#msgfmt#Handle(bufnr(''), [ + \ '/tmp/v6GMUFf/16/foo.po:14: some other thing', + \ '/tmp/v6GMUFf/16/foo.po:1746: duplicate message definition...', + \ '/tmp/v6GMUFf/16/foo.po:262: ...this is the location of the first definition', + \ '/tmp/v6GMUFf/16/foo.po:666: duplicate message definition...', + \ '/tmp/v6GMUFf/16/foo.po:888: some other thing', + \ '/tmp/v6GMUFf/16/foo.po:999: ...this is the location of the first definition', + \ ]) |