gpt4 book ai didi

lua - 如何在 luacheck 中将警告设为错误?

转载 作者:行者123 更新时间:2023-12-05 07:28:25 24 4
gpt4 key购买 nike

我希望 luacheck 将“accessing undefined variable 'variable'”警告视为错误,这对我来说总是有意义的。那么我该如何配置特定的警告,假设 W113 为错误,这样我就可以一目了然地找到它们

最佳答案

您可以使用 Lua 脚本通过命令行运行 luacheck,并在需要时使用模式匹配来排除错误:

local dir = assert(arg[1])
local f = assert(io.popen('luacheck --no-color ' .. dir, 'r')) -- no-color flag allows numbers represented as strings to be tonumber'd
local s = assert(f:read('*a'))
print(s)
f:close()

local errors = tonumber(s:match("Total:.+/ (.+) error"))

assert(errors == 0, "Luacheck: found " .. errors .. " critical error(s) in Lua code.")

当然,这意味着您不能直接运行 Luacheck——您必须改为执行脚本,因此它可能并不适用于所有场景。此外,如果日志输出在某个时候发生变化,脚本将需要相应地更新,因为模式匹配将失败。

示例:runLuacheck.lua。 在工作目录上运行 Luacheck。

关于lua - 如何在 luacheck 中将警告设为错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53349796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com