test: add luacheck

This commit is contained in:
Guillaume ARM 2026-05-31 00:39:18 +02:00
parent 7ef47baadb
commit 1521ca9709
5 changed files with 74 additions and 5 deletions

61
.luacheckrc Normal file
View File

@ -0,0 +1,61 @@
-- Luacheck config for CC:Tweaked (ComputerCraft) Lua sandbox.
-- Runtime is Lua 5.1 inside the CC sandbox, not standard Lua, so we
-- extend lua51 with the globals and os/table extensions CC provides.
stds.cc = {
read_globals = {
-- ComputerCraft APIs injected as globals by the sandbox.
"fs",
"peripheral",
"parallel",
"shell",
"term",
"textutils",
"colors",
"colours",
"rednet",
"gps",
"http",
"settings",
"window",
"paintutils",
"keys",
"vector",
"commands",
"disk",
"periphemu", -- CraftOS-PC emulator only
"read",
"sleep",
"write",
-- CC extends the standard os/table tables with extra fields.
os = {
fields = {
"getComputerID", "getComputerLabel", "setComputerLabel",
"queueEvent", "pullEvent", "pullEventRaw",
"startTimer", "cancelTimer", "sleep",
"reboot", "shutdown", "version",
"epoch", "day", "clock", "time",
"loadAPI", "unloadAPI", "run",
},
},
table = {
fields = { "pack", "unpack" },
},
},
}
std = "lua51+cc"
-- _G.isRouterEnabled is a cross-module flag set/read at runtime; `_` is the
-- throwaway global used in router.lua.
globals = {
"isRouterEnabled",
"_",
}
-- `_VERSION` is a per-module convention (see CLAUDE.md) and intentionally unused.
ignore = {
"211/_VERSION", -- unused local _VERSION
}
max_line_length = false

10
Justfile Normal file
View File

@ -0,0 +1,10 @@
# Justfile for cc-libs
# Run `just check` to lint all Lua code with luacheck.
# List available recipes.
default:
@just --list
# Lint all Lua source with luacheck.
check:
luacheck apis programs servers startup install.lua

View File

@ -239,9 +239,9 @@ local function deployCommand()
local filePath = allFiles[i];
local fileContent = readFile(filePath)
local ok, res = net.sendRequest(CUBE_CHANNEL, 'deploy-file', { path = filePath, content = fileContent }, machineId);
local transferOk, res = net.sendRequest(CUBE_CHANNEL, 'deploy-file', { path = filePath, content = fileContent }, machineId);
if ok and res then
if transferOk and res then
fileTransfered = fileTransfered + 1;
else
print('Error transfering file \'' .. filePath .. '\'');

View File

@ -7,11 +7,9 @@ if firstArg == '-version' or firstArg == '--version' then
return;
end
local verbose = true
local printVerbose = print
if firstArg == '-silent' or firstArg == '--silent' then
verbose = false
printVerbose = function() end
end

View File

@ -44,7 +44,7 @@ local function getServerFns(serverList)
local servers = {};
for k, v in ipairs(serverList) do
local serverName = serverList[k];
local serverName = v;
servers[k] = function()
if serverName then