From 2c4da0b88a29c74b2990efe40e8f26ed6ddac9f9 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 4 Apr 2018 15:35:56 +0100 Subject: [PATCH] Add luacheck --- .luacheckrc | 14 ++++++++++++++ .travis.yml | 12 ++++++++++++ api.lua | 6 +++--- triggers.lua | 24 ++++++++++++------------ 4 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 .luacheckrc create mode 100644 .travis.yml diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..f6b420e --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,14 @@ +unused_args = false +allow_defined_top = true + +globals = { + "minetest", "awards", +} + +read_globals = { + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + "vector", "default", "ItemStack", + "dump", "sfinv", "intllib", + "unified_inventory", +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..077e778 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: generic +sudo: false +addons: + apt: + packages: + - luarocks +before_install: + - luarocks install --local luacheck +script: +- $HOME/.luarocks/bin/luacheck --no-color . +notifications: + email: false diff --git a/api.lua b/api.lua index af5e405..b3253ef 100644 --- a/api.lua +++ b/api.lua @@ -46,8 +46,8 @@ function awards.load() return {} end -function awards.register_trigger(name, func) - awards.trigger_types[name] = func +function awards.register_trigger(name, tfunc) + awards.trigger_types[name] = tfunc awards.on[name] = {} awards['register_on_'..name] = function(func) table.insert(awards.on[name], func) @@ -380,7 +380,7 @@ function awards.getFormspec(name, to, sid) formspec = formspec .. "textarea[0.5,2.7;4.8,1.45;;" .. string.format(status, minetest.formspec_escape(title)) .. ";]" - + if def and def.icon then formspec = formspec .. "image[1,0;3,3;" .. def.icon .. "]" end diff --git a/triggers.lua b/triggers.lua index 594974a..ac3afc8 100644 --- a/triggers.lua +++ b/triggers.lua @@ -233,9 +233,9 @@ minetest.register_on_dignode(function(pos, oldnode, digger) local tnodedug = string.split(entry.node, ":") local tmod = tnodedug[1] local titem = tnodedug[2] - if not tmod or not titem or not data.count[tmod] or not data.count[tmod][titem] then - -- table running failed! - elseif data.count[tmod][titem] > entry.target-1 then + if not (not tmod or not titem or not data.count[tmod] or + not data.count[tmod][titem]) and + data.count[tmod][titem] > entry.target-1 then return entry.award end elseif awards.get_total_item_count(data, "count") > entry.target-1 then @@ -260,9 +260,9 @@ minetest.register_on_placenode(function(pos, node, digger) local tnodedug = string.split(entry.node, ":") local tmod = tnodedug[1] local titem = tnodedug[2] - if not tmod or not titem or not data.place[tmod] or not data.place[tmod][titem] then - -- table running failed! - elseif data.place[tmod][titem] > entry.target-1 then + if not (not tmod or not titem or not data.place[tmod] or + not data.place[tmod][titem]) and + data.place[tmod][titem] > entry.target-1 then return entry.award end elseif awards.get_total_item_count(data, "place") > entry.target-1 then @@ -286,9 +286,9 @@ minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, local titemstring = string.split(entry.item, ":") local tmod = titemstring[1] local titem = titemstring[2] - if not tmod or not titem or not data.eat[tmod] or not data.eat[tmod][titem] then - -- table running failed! - elseif data.eat[tmod][titem] > entry.target-1 then + if not (not tmod or not titem or not data.eat[tmod] or + not data.eat[tmod][titem]) and + data.eat[tmod][titem] > entry.target-1 then return entry.award end elseif awards.get_total_item_count(data, "eat") > entry.target-1 then @@ -314,9 +314,9 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv local titemcrafted = string.split(entry.item, ":") local tmod = titemcrafted[1] local titem = titemcrafted[2] - if not tmod or not titem or not data.craft[tmod] or not data.craft[tmod][titem] then - -- table running failed! - elseif data.craft[tmod][titem] > entry.target-1 then + if not (not tmod or not titem or not data.craft[tmod] or + not data.craft[tmod][titem]) and + data.craft[tmod][titem] > entry.target-1 then return entry.award end elseif awards.get_total_item_count(data, "craft") > entry.target-1 then