From 1521ca9709c878106790f4e6df815c0c280d6a58 Mon Sep 17 00:00:00 2001 From: Trap Date: Sun, 31 May 2026 00:39:18 +0200 Subject: [PATCH] test: add luacheck --- .luacheckrc | 61 +++++++++++++++++++++++++++++++++++++++++++++ Justfile | 10 ++++++++ programs/cube.lua | 4 +-- programs/router.lua | 2 -- startup/servers.lua | 2 +- 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 .luacheckrc create mode 100644 Justfile diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..a67133c --- /dev/null +++ b/.luacheckrc @@ -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 diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..d8e3542 --- /dev/null +++ b/Justfile @@ -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 diff --git a/programs/cube.lua b/programs/cube.lua index d8e5397..435a109 100644 --- a/programs/cube.lua +++ b/programs/cube.lua @@ -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 .. '\''); diff --git a/programs/router.lua b/programs/router.lua index c93b9db..4fc6b6b 100644 --- a/programs/router.lua +++ b/programs/router.lua @@ -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 diff --git a/startup/servers.lua b/startup/servers.lua index 7f6c03d..5d9cd66 100644 --- a/startup/servers.lua +++ b/startup/servers.lua @@ -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