From 537e7560918e098d5f1a02f31f7938566028e906 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 31 Aug 2020 15:50:33 +0200 Subject: [PATCH] add `.luacheckrc` and gh action --- .github/workflows/luacheck.yml | 17 +++++++++++++++++ .luacheckrc | 30 ++++++++++++++++++++++++++++++ mesecons_microcontroller/init.lua | 11 ++++++----- mesecons_pistons/init.lua | 6 +++--- mesecons_pressureplates/init.lua | 4 ++-- mesecons_random/init.lua | 2 +- 6 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/luacheck.yml create mode 100644 .luacheckrc diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..4077f41 --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,17 @@ +name: luacheck + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: apt + run: sudo apt-get install -y luarocks + - name: luacheck install + run: luarocks install --local luacheck + - name: luacheck run + run: $HOME/.luarocks/bin/luacheck ./ diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..8dc0e23 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,30 @@ + +globals = { + "mesecon", + "minetest" +} + +-- ignore unused vars +unused = false + +read_globals = { + -- Stdlib + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + + -- Minetest + "vector", "ItemStack", + "dump", "VoxelArea", + + -- system + "DIR_DELIM", + + -- deps + "default", "screwdriver" +} + +ignore = { + "631", -- line too long + "621", -- inconsistent indendation + "542", -- empty if branch +} diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index f9ba979..16665ef 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -405,7 +405,7 @@ yc.command_print = function(params, eeprom, L) if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then s = s..param:sub(2, #param-1) else - r = yc.command_parsecondition(param, L, eeprom) + local r = yc.command_parsecondition(param, L, eeprom) if r == "1" or r == "0" then s = s..r else return nil end @@ -543,12 +543,13 @@ yc.command_parsecondition = function(cond, L, eeprom) cond = string.gsub(cond, "!0", "1") cond = string.gsub(cond, "!1", "0") - local i = 2 - local l = string.len(cond) + i = 2 + l = string.len(cond) while i<=l do local s = cond:sub(i,i) local b = tonumber(cond:sub(i-1, i-1)) local a = tonumber(cond:sub(i+1, i+1)) + local buf if cond:sub(i+1, i+1) == nil then break end if s == "=" then if a==nil then return nil end @@ -562,8 +563,8 @@ yc.command_parsecondition = function(cond, L, eeprom) i = i + 1 end - local i = 2 - local l = string.len(cond) + i = 2 + l = string.len(cond) while i<=l do local s = cond:sub(i,i) local b = tonumber(cond:sub(i-1, i-1)) diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 66c74b2..a927003 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -22,7 +22,7 @@ local function get_pistonspec_name(name, part) return end for spec_name, spec in pairs(specs) do - for part, value in pairs(spec) do + for _, value in pairs(spec) do if name == value then return spec_name, part end @@ -462,8 +462,8 @@ end local function piston_get_stopper(node, dir, stack, stackid) local pistonspec = get_pistonspec(node.name, "onname") - local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) - local pusherpos = vector.add(stack[stackid].pos, dir) + local inverted_dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) + local pusherpos = vector.add(stack[stackid].pos, inverted_dir) local pushernode = minetest.get_node(pusherpos) if pistonspec.pusher == pushernode.name then for _, s in ipairs(stack) do diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua index 8137676..5ba43c0 100644 --- a/mesecons_pressureplates/init.lua +++ b/mesecons_pressureplates/init.lua @@ -50,8 +50,8 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te if not groups then groups = {} end - local groups_off = table.copy(groups) - local groups_on = table.copy(groups) + groups_off = table.copy(groups) + groups_on = table.copy(groups) groups_on.not_in_creative_inventory = 1 mesecon.register_node(basename, { diff --git a/mesecons_random/init.lua b/mesecons_random/init.lua index 0536007..b2a1702 100644 --- a/mesecons_random/init.lua +++ b/mesecons_random/init.lua @@ -59,7 +59,7 @@ minetest.register_node("mesecons_random:ghoststone_active", { }}, on_construct = function(pos) -- remove shadow - shadowpos = vector.add(pos, vector.new(0, 1, 0)) + local shadowpos = vector.add(pos, vector.new(0, 1, 0)) if (minetest.get_node(shadowpos).name == "air") then minetest.dig_node(shadowpos) end