Luacheck lintcmd always prints 0 errors and 0 warnings



I am trying to massage the output of luacheck so that it fits into the lintcmd option of kakoune.

Here is what I have so far:

A file kak-luacheck, somewhere in PATH.

# kak: filetype=sh
# This script massages the output of luacheck to be consumable by kakoune.
# It is meant to be used as the 'lintcmd' option and as such, is very specific to
# kakoune.
luacheck --jobs 8 --cache "/tmp/luaccheckcache" --codes --formatter plain --filename "$1" - | sed 's/(E...)/error:/' | sed 's/(W...)/warning:/'

# | sd "\(E\d\d\d\)" "error:" | sd "\(W\d\d\d\)" "warning:"
# somewhere in kakrc. inside filetype hook for lua files.
evaluate-commands %{ printf 'set-option global lintcmd "%s %s"' 'kak-luacheck' "$kak_buffile" }

It is my understanding, that kakoune wants to consume the lint issues in the format:

{filename}:{line}:{column}: {kind}: {message}

The format of luacheck is almost right, except for the {kind} part.

Output of kak-luacheck without the pipes to sed:

   /mdfmt cat mdfmt.lua | kak-luacheck mdfmt.lua
mdfmt.lua:3:7: (W211) unused variable 'set'
mdfmt.lua:4:7: (W211) unused variable 'range'
mdfmt.lua:6:7: (W211) unused variable 'capture'
mdfmt.lua:7:7: (W211) unused variable 'capture_table'
mdfmt.lua:9:7: (W211) unused variable 'markdown_grammer'
mdfmt.lua:31:10: (W113) accessing undefined variable 'whitespace'

Output of kak-luacheck with sed:

   /mdfmt cat mdfmt.lua | kak-luacheck mdfmt.lua
mdfmt.lua:3:7: warning: unused variable 'set'
mdfmt.lua:4:7: warning: unused variable 'range'
mdfmt.lua:6:7: warning: unused variable 'capture'
mdfmt.lua:7:7: warning: unused variable 'capture_table'
mdfmt.lua:9:7: warning: unused variable 'markdown_grammer'
mdfmt.lua:31:10: warning: accessing undefined variable 'whitespace'

Here is a the sample lua file:

local lpeg = require 'lpeg'
local pattern = lpeg.P
local set = lpeg.S
local range = lpeg.R
local variable = lpeg.V
local capture = lpeg.C
local capture_table = lpeg.Ct

local markdown_grammer = {
markdown = variable'paragraph' +
           variable'header' +
           variable'code_block' +
           variable'block_quote' +
           variable'reference_link' +
           variable'thematic_break' +
           variable'list' +
           variable'blank_line' +
paragraph = variable'excape' +
            variable'entity_reference' +
            variable'code_span' +
            variable'emphasis' +
            variable'link' +
            variable'image' +
            variable'autolink' +
            variable'html' +
            variable'hard_break' +
            variable'soft_break' +
            variable'text' ,
header = whitespace * pattern'#'^1 ,

The output of my script looks fine to me, but in kakoune the modeline always shows “0 error(s) 0 warning(s)”.
Am I missing something obvious?


I got it working with the shell script:

luacheck --codes --formatter plain $1 | sed 's/(E...)/error:/' | sed 's/(W...)/warning:/'

and the kakrc:

hook global WinSetOption filetype=lua %{
    set window lintcmd /abs/path/to/
    set global debug shell

I’m not sure which change made it work exactly, but the set global debug shell means you can run :buffer *debug* and see what the output of the shell command ends up being so you can figure it out from there.


Thanks for the hint with debug shell.
I think my mistake was assuming that kak would pipe the buffer into the lintcmd. It seems to however pass the file path of a temp file containing the buffer.