Browse Source

Add luacheck to check builtin (#7895)

rubenwardy 4 years ago
parent
commit
8e757859d6

+ 74 - 0
.luacheckrc

@@ -0,0 +1,74 @@
+unused_args = false
+allow_defined_top = true
+
+ignore = {
+	"131", -- Unused global variable
+	"431", -- Shadowing an upvalue
+	"432", -- Shadowing an upvalue argument
+}
+
+read_globals = {
+	"ItemStack",
+	"INIT",
+	"DIR_DELIM",
+	"dump", "dump2",
+	"fgettext", "fgettext_ne",
+	"vector",
+	"VoxelArea",
+	"profiler",
+	"Settings",
+
+	string = {fields = {"split"}},
+	table  = {fields = {"copy", "getn", "indexof", "insert_all"}},
+	math   = {fields = {"hypot"}},
+}
+
+globals = {
+	"core",
+	"gamedata",
+	os = { fields = { "tempfolder" } },
+	"_",
+}
+
+files["builtin/client/register.lua"] = {
+	globals = {
+		debug = {fields={"getinfo"}},
+	}
+}
+
+files["builtin/common/misc_helpers.lua"] = {
+	globals = {
+		"dump", "dump2", "table", "math", "string",
+		"fgettext", "fgettext_ne", "basic_dump", "game", -- ???
+		"file_exists", "get_last_folder", "cleanup_path", -- ???
+	},
+}
+
+files["builtin/common/vector.lua"] = {
+	globals = { "vector" },
+}
+
+files["builtin/game/voxelarea.lua"] = {
+	globals = { "VoxelArea" },
+}
+
+files["builtin/game/init.lua"] = {
+	globals = { "profiler" },
+}
+
+files["builtin/common/filterlist.lua"] = {
+	globals = {
+		"filterlist",
+		"compare_worlds", "sort_worlds_alphabetic", "sort_mod_list", -- ???
+	},
+}
+
+files["builtin/mainmenu"] = {
+	globals = {
+		"gamedata",
+	},
+
+	read_globals = {
+		"PLATFORM",
+	},
+}

+ 4 - 4
builtin/client/chatcommands.lua

@@ -16,7 +16,7 @@ core.register_on_sending_chat_message(function(message)
 	end
 
 	local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
- 	param = param or ""
+	param = param or ""
 
 	if not cmd then
 		core.display_chat_message(core.gettext("-!- Empty command"))
@@ -26,9 +26,9 @@ core.register_on_sending_chat_message(function(message)
 	local cmd_def = core.registered_chatcommands[cmd]
 	if cmd_def then
 		core.set_last_run_mod(cmd_def.mod_origin)
-		local _, message = cmd_def.func(param)
-		if message then
-			core.display_chat_message(message)
+		local _, result = cmd_def.func(param)
+		if result then
+			core.display_chat_message(result)
 		end
 	else
 		core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)

+ 0 - 1
builtin/common/filterlist.lua

@@ -250,7 +250,6 @@ end
 
 --------------------------------------------------------------------------------
 function compare_worlds(world1,world2)
-
 	if world1.path ~= world2.path then
 		return false
 	end

+ 3 - 4
builtin/common/information_formspecs.lua

@@ -31,7 +31,6 @@ local mod_cmds = {}
 local function load_mod_command_tree()
 	mod_cmds = {}
 
-	local check_player_privs = core.check_player_privs
 	for name, def in pairs(core.registered_chatcommands) do
 		mod_cmds[def.mod_origin] = mod_cmds[def.mod_origin] or {}
 		local cmds = mod_cmds[def.mod_origin]
@@ -86,8 +85,8 @@ end
 
 local function build_privs_formspec(name)
 	local privs = {}
-	for name, def in pairs(core.registered_privileges) do
-		privs[#privs + 1] = { name, def }
+	for priv_name, def in pairs(core.registered_privileges) do
+		privs[#privs + 1] = { priv_name, def }
 	end
 	table.sort(privs, function(a, b) return a[1] < b[1] end)
 
@@ -137,7 +136,7 @@ help_command.func = function(name, param)
 	if param == "" or param == "all" then
 		core.show_formspec(name, "__builtin:help_cmds",
 			build_chatcommands_formspec(name))
-		return 
+		return
 	end
 
 	return old_help_func(name, param)

+ 9 - 8
builtin/common/misc_helpers.lua

@@ -128,6 +128,7 @@ function dump(o, indent, nested, level)
 	if t ~= "table" then
 		return basic_dump(o)
 	end
+
 	-- Contains table -> true/nil of currently nested tables
 	nested = nested or {}
 	if nested[o] then
@@ -136,10 +137,11 @@ function dump(o, indent, nested, level)
 	nested[o] = true
 	indent = indent or "\t"
 	level = level or 1
-	local t = {}
+
+	local ret = {}
 	local dumped_indexes = {}
 	for i, v in ipairs(o) do
-		t[#t + 1] = dump(v, indent, nested, level + 1)
+		ret[#ret + 1] = dump(v, indent, nested, level + 1)
 		dumped_indexes[i] = true
 	end
 	for k, v in pairs(o) do
@@ -148,7 +150,7 @@ function dump(o, indent, nested, level)
 				k = "["..dump(k, indent, nested, level + 1).."]"
 			end
 			v = dump(v, indent, nested, level + 1)
-			t[#t + 1] = k.." = "..v
+			ret[#ret + 1] = k.." = "..v
 		end
 	end
 	nested[o] = nil
@@ -157,10 +159,10 @@ function dump(o, indent, nested, level)
 		local end_indent_str = "\n"..string.rep(indent, level - 1)
 		return string.format("{%s%s%s}",
 				indent_str,
-				table.concat(t, ","..indent_str),
+				table.concat(ret, ","..indent_str),
 				end_indent_str)
 	end
-	return "{"..table.concat(t, ", ").."}"
+	return "{"..table.concat(ret, ", ").."}"
 end
 
 --------------------------------------------------------------------------------
@@ -407,9 +409,8 @@ if INIT == "game" then
 		end
 
 		local old_itemstack = ItemStack(itemstack)
-		local new_itemstack, removed = core.item_place_node(
-			itemstack, placer, pointed_thing, param2, prevent_after_place
-		)
+		local new_itemstack = core.item_place_node(itemstack, placer,
+				pointed_thing, param2, prevent_after_place)
 		return infinitestacks and old_itemstack or new_itemstack
 	end
 

+ 0 - 1
builtin/common/serialize.lua

@@ -218,4 +218,3 @@ test_in = {escape_chars="\n\r\t\v\\\"\'", non_european="θשׁ٩∂"}
 test_out = core.deserialize(core.serialize(test_in))
 assert(test_in.escape_chars == test_out.escape_chars)
 assert(test_in.non_european == test_out.non_european)
-

+ 30 - 27
builtin/game/chatcommands.lua

@@ -27,8 +27,8 @@ core.register_on_chat_message(function(name, message)
 	local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
 	if has_privs then
 		core.set_last_run_mod(cmd_def.mod_origin)
-		local success, message = cmd_def.func(name, param)
-		if message then
+		local _, result = cmd_def.func(name, param)
+		if result then
 			core.chat_send_player(name, message)
 		end
 	else
@@ -125,10 +125,10 @@ core.register_chatcommand("haspriv", {
 			if core.check_player_privs(player_name, privs) then
 				table.insert(players_with_priv, player_name)
 			end
-		end	
+		end
 		return true, "Players online with the \"" .. param .. "\" privilege: " ..
 			table.concat(players_with_priv, ", ")
-	end	
+	end
 })
 
 local function handle_grant_command(caller, grantname, grantprivstr)
@@ -261,11 +261,12 @@ core.register_chatcommand("setpassword", {
 			toname = param:match("^([^ ]+) *$")
 			raw_password = nil
 		end
+
 		if not toname then
 			return false, "Name field required"
 		end
-		local act_str_past = "?"
-		local act_str_pres = "?"
+
+		local act_str_past, act_str_pres
 		if not raw_password then
 			core.set_player_password(toname, "")
 			act_str_past = "cleared"
@@ -277,13 +278,14 @@ core.register_chatcommand("setpassword", {
 			act_str_past = "set"
 			act_str_pres = "sets"
 		end
+
 		if toname ~= name then
 			core.chat_send_player(toname, "Your password was "
 					.. act_str_past .. " by " .. name)
 		end
 
-		core.log("action", name .. " " .. act_str_pres
-		.. " password of " .. toname .. ".")
+		core.log("action", name .. " " .. act_str_pres ..
+				" password of " .. toname .. ".")
 
 		return true, "Password of player \"" .. toname .. "\" " .. act_str_past
 	end,
@@ -367,35 +369,35 @@ core.register_chatcommand("teleport", {
 			return pos, false
 		end
 
-		local teleportee = nil
 		local p = {}
 		p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
 		p.x = tonumber(p.x)
 		p.y = tonumber(p.y)
 		p.z = tonumber(p.z)
 		if p.x and p.y and p.z then
+
 			local lm = 31000
 			if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then
 				return false, "Cannot teleport out of map bounds!"
 			end
-			teleportee = core.get_player_by_name(name)
+			local teleportee = core.get_player_by_name(name)
 			if teleportee then
 				teleportee:set_pos(p)
 				return true, "Teleporting to "..core.pos_to_string(p)
 			end
 		end
 
-		local teleportee = nil
-		local p = nil
-		local target_name = nil
-		target_name = param:match("^([^ ]+)$")
-		teleportee = core.get_player_by_name(name)
+		local target_name = param:match("^([^ ]+)$")
+		local teleportee = core.get_player_by_name(name)
+
+		p = nil
 		if target_name then
 			local target = core.get_player_by_name(target_name)
 			if target then
 				p = target:get_pos()
 			end
 		end
+
 		if teleportee and p then
 			p = find_free_position_near(p)
 			teleportee:set_pos(p)
@@ -407,9 +409,9 @@ core.register_chatcommand("teleport", {
 			return false, "You don't have permission to teleport other players (missing bring privilege)"
 		end
 
-		local teleportee = nil
-		local p = {}
-		local teleportee_name = nil
+		teleportee = nil
+		p = {}
+		local teleportee_name
 		teleportee_name, p.x, p.y, p.z = param:match(
 				"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
 		p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
@@ -422,10 +424,8 @@ core.register_chatcommand("teleport", {
 					.. " to " .. core.pos_to_string(p)
 		end
 
-		local teleportee = nil
-		local p = nil
-		local teleportee_name = nil
-		local target_name = nil
+		teleportee = nil
+		p = nil
 		teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
 		if teleportee_name then
 			teleportee = core.get_player_by_name(teleportee_name)
@@ -459,7 +459,8 @@ core.register_chatcommand("set", {
 			core.settings:set(setname, setvalue)
 			return true, setname .. " = " .. setvalue
 		end
-		local setname, setvalue = string.match(param, "([^ ]+) (.+)")
+
+		setname, setvalue = string.match(param, "([^ ]+) (.+)")
 		if setname and setvalue then
 			if not core.settings:get(setname) then
 				return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
@@ -467,14 +468,16 @@ core.register_chatcommand("set", {
 			core.settings:set(setname, setvalue)
 			return true, setname .. " = " .. setvalue
 		end
-		local setname = string.match(param, "([^ ]+)")
+
+		setname = string.match(param, "([^ ]+)")
 		if setname then
-			local setvalue = core.settings:get(setname)
+			setvalue = core.settings:get(setname)
 			if not setvalue then
 				setvalue = "<not set>"
 			end
 			return true, setname .. " = " .. setvalue
 		end
+
 		return false, "Invalid parameters (see /help set)."
 	end,
 })
@@ -692,7 +695,7 @@ core.register_chatcommand("pulverize", {
 		end
 		core.log("action", name .. " pulverized \"" ..
 			wielded_item:get_name() .. " " .. wielded_item:get_count() .. "\"")
-		player:set_wielded_item(nil)			
+		player:set_wielded_item(nil)
 		return true, "An item was pulverized."
 	end,
 })
@@ -771,7 +774,7 @@ core.register_chatcommand("rollback", {
 		end
 		local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
 		if not target_name then
-			local player_name = nil
+			local player_name
 			player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
 			if not player_name then
 				return false, "Invalid parameters. See /help rollback"

+ 1 - 1
builtin/game/forceloading.lua

@@ -111,7 +111,7 @@ end
 
 -- periodical forceload persistence
 local function periodically_persist_forceloaded_blocks()
-	
+
 	-- only persist if the blocks actually changed
 	if forceload_blocks_changed then
 		persist_forceloaded_blocks()

+ 0 - 6
builtin/game/item.lua

@@ -206,7 +206,6 @@ function core.get_node_drops(node, toolname)
 	-- Extended drop table
 	local got_items = {}
 	local got_count = 0
-	local _, item, tool
 	for _, item in ipairs(drop.items) do
 		local good_rarity = true
 		local good_tool = true
@@ -614,15 +613,10 @@ function core.node_dig(pos, node, digger)
 	end
 
 	-- Run script hook
-	local _, callback
 	for _, callback in ipairs(core.registered_on_dignodes) do
 		local origin = core.callback_origins[callback]
 		if origin then
 			core.set_last_run_mod(origin.mod)
-			--print("Running " .. tostring(callback) ..
-			--	" (a " .. origin.name .. " callback in " .. origin.mod .. ")")
-		else
-			--print("No data associated with callback")
 		end
 
 		-- Copy pos and node because callback can modify them

+ 1 - 1
builtin/game/misc.lua

@@ -62,7 +62,7 @@ end
 core.register_on_joinplayer(function(player)
 	local player_name = player:get_player_name()
 	player_list[player_name] = player
-	if not minetest.is_singleplayer() then
+	if not core.is_singleplayer() then
 		local status = core.get_server_status(player_name, true)
 		if status and status ~= "" then
 			core.chat_send_player(player_name, status)

+ 1 - 1
builtin/game/privileges.lua

@@ -18,7 +18,7 @@ function core.register_privilege(name, param)
 			def.description = "(no description)"
 		end
 	end
-	local def = {}
+	local def
 	if type(param) == "table" then
 		def = param
 	else

+ 3 - 8
builtin/game/register.lua

@@ -303,7 +303,6 @@ end
 
 -- Alias the forbidden item names to "" so they can't be
 -- created via itemstrings (e.g. /give)
-local name
 for name in pairs(forbidden_item_names) do
 	core.registered_aliases[name] = ""
 	register_alias_raw(name, "")
@@ -363,9 +362,9 @@ core.register_node(":ignore", {
 	drop = "",
 	groups = {not_in_creative_inventory=1},
 	on_place = function(itemstack, placer, pointed_thing)
-		minetest.chat_send_player(
+		core.chat_send_player(
 				placer:get_player_name(),
-				minetest.colorize("#FF0000",
+				core.colorize("#FF0000",
 				"You can't place 'ignore' nodes!"))
 		return ""
 	end,
@@ -413,10 +412,6 @@ function core.run_callbacks(callbacks, mode, ...)
 		local origin = core.callback_origins[callbacks[i]]
 		if origin then
 			core.set_last_run_mod(origin.mod)
-			--print("Running " .. tostring(callbacks[i]) ..
-			--	" (a " .. origin.name .. " callback in " .. origin.mod .. ")")
-		else
-			--print("No data associated with callback")
 		end
 		local cb_ret = callbacks[i](...)
 
@@ -537,7 +532,7 @@ end
 core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } }
 
 function core.registered_on_player_hpchange(player, hp_change, reason)
-	local last = false
+	local last
 	for i = #core.registered_on_player_hpchanges.modifiers, 1, -1 do
 		local func = core.registered_on_player_hpchanges.modifiers[i]
 		hp_change, last = func(player, hp_change, reason)

+ 10 - 12
builtin/game/statbars.lua

@@ -1,8 +1,7 @@
 -- cache setting
 local enable_damage = core.settings:get_bool("enable_damage")
 
-local health_bar_definition =
-{
+local health_bar_definition = {
 	hud_elem_type = "statbar",
 	position = { x=0.5, y=1 },
 	text = "heart.png",
@@ -12,8 +11,7 @@ local health_bar_definition =
 	offset = { x=(-10*24)-25, y=-(48+24+16)},
 }
 
-local breath_bar_definition =
-{
+local breath_bar_definition = {
 	hud_elem_type = "statbar",
 	position = { x=0.5, y=1 },
 	text = "bubble.png",
@@ -30,8 +28,8 @@ local function scaleToDefault(player, field)
 	local current = player["get_" .. field](player)
 	local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
 	local max_display = math.max(nominal,
- 		math.max(player:get_properties()[field .. "_max"], current))
- 	return current / max_display * nominal 
+		math.max(player:get_properties()[field .. "_max"], current))
+	return current / max_display * nominal
 end
 
 local function update_builtin_statbars(player)
@@ -53,8 +51,8 @@ local function update_builtin_statbars(player)
 	local immortal = player:get_armor_groups().immortal == 1
 	if flags.healthbar and enable_damage and not immortal then
 		local number = scaleToDefault(player, "hp")
- 		if hud.id_healthbar == nil then
- 			local hud_def = table.copy(health_bar_definition)
+		if hud.id_healthbar == nil then
+			local hud_def = table.copy(health_bar_definition)
 			hud_def.number = number
 			hud.id_healthbar = player:hud_add(hud_def)
 		else
@@ -70,7 +68,7 @@ local function update_builtin_statbars(player)
 			player:get_breath() < breath_max then
 		local number = 2 * scaleToDefault(player, "breath")
 		if hud.id_breathbar == nil then
- 			local hud_def = table.copy(breath_bar_definition)
+			local hud_def = table.copy(breath_bar_definition)
 			hud_def.number = number
 			hud.id_breathbar = player:hud_add(hud_def)
 		else
@@ -125,14 +123,14 @@ local function player_event_handler(player,eventname)
 	return false
 end
 
-function core.hud_replace_builtin(name, definition)
+function core.hud_replace_builtin(hud_name, definition)
 
 	if type(definition) ~= "table" or
 			definition.hud_elem_type ~= "statbar" then
 		return false
 	end
 
-	if name == "health" then
+	if hud_name == "health" then
 		health_bar_definition = definition
 
 		for name, ids in pairs(hud_ids) do
@@ -146,7 +144,7 @@ function core.hud_replace_builtin(name, definition)
 		return true
 	end
 
-	if name == "breath" then
+	if hud_name == "breath" then
 		breath_bar_definition = definition
 
 		for name, ids in pairs(hud_ids) do

+ 3 - 2
builtin/mainmenu/common.lua

@@ -93,9 +93,9 @@ function render_serverlist_row(spec, is_favorite)
 		end
 	end
 
-	local details = ""
 	local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
 
+	local details
 	if is_favorite then
 		details = "1,"
 	else
@@ -118,11 +118,11 @@ function render_serverlist_row(spec, is_favorite)
 	end
 
 	if spec.clients and spec.clients_max then
-		local clients_color = ''
 		local clients_percent = 100 * spec.clients / spec.clients_max
 
 		-- Choose a color depending on how many clients are connected
 		-- (relatively to clients_max)
+		local clients_color
 		if     grey_out		      then clients_color = '#aaaaaa'
 		elseif spec.clients == 0      then clients_color = ''        -- 0 players: default/white
 		elseif clients_percent <= 60  then clients_color = '#a1e587' -- 0-60%: green
@@ -171,6 +171,7 @@ os.tempfolder = function()
 	local filetocheck = os.tmpname()
 	os.remove(filetocheck)
 
+	-- luacheck: ignore
 	-- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/
 	--   The C runtime (CRT) function called by os.tmpname is tmpnam.
 	--   Microsofts tmpnam implementation in older CRT / MSVC releases is defective.

+ 0 - 1
builtin/mainmenu/dlg_contentstore.lua

@@ -270,7 +270,6 @@ function store.load()
 	assert(core.create_dir(tmpdir))
 
 	local base_url     = core.settings:get("contentdb_url")
-	local show_nonfree = core.settings:get_bool("show_nonfree_packages")
 	local url = base_url ..
 		"/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
 		core.get_max_supp_proto()

+ 6 - 6
builtin/mainmenu/dlg_create_world.lua

@@ -24,10 +24,10 @@ local function create_world_formspec(dialogdata)
 	local current_mg   = core.settings:get("mg_name")
 	local gameid = core.settings:get("menu_last_game")
 
-	local game, gameidx = nil , 0
+	local gameidx = 0
 	if gameid ~= nil then
-		game, gameidx = pkgmgr.find_by_gameid(gameid)
-		
+		_, gameidx = pkgmgr.find_by_gameid(gameid)
+
 		if gameidx == nil then
 			gameidx = 0
 		end
@@ -82,7 +82,7 @@ local function create_world_formspec(dialogdata)
 
 		"button[3.25,6;2.5,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
 		"button[5.75,6;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
-		
+
 	if #pkgmgr.games == 0 then
 		retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
 				fgettext("You have no games installed.") .. "]label[2.25,4.4;" ..
@@ -111,10 +111,10 @@ local function create_world_buttonhandler(this, fields)
 				local random_world_name = "Unnamed" .. random_number
 				worldname = random_world_name
 			end
-			local message = nil
 
 			core.settings:set("fixed_map_seed", fields["te_seed"])
 
+			local message
 			if not menudata.worldlist:uid_exists_raw(worldname) then
 				core.settings:set("mg_name",fields["dd_mapgen"])
 				message = core.create_world(worldname,gameindex)
@@ -165,6 +165,6 @@ function create_create_world_dlg(update_worldlistfilter)
 					create_world_buttonhandler,
 					nil)
 	retval.update_worldlist_filter = update_worldlistfilter
-	
+
 	return retval
 end

+ 23 - 19
builtin/mainmenu/dlg_settings_advanced.lua

@@ -148,9 +148,9 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
 		local values = {}
 		local ti = 1
 		local index = 1
-		for line in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
-			index = default:find("[+-]?[%d.-e]+", index) + line:len()
-			table.insert(values, line)
+		for match in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
+			index = default:find("[+-]?[%d.-e]+", index) + match:len()
+			table.insert(values, match)
 			ti = ti + 1
 			if ti > 9 then
 				break
@@ -322,17 +322,20 @@ end
 -- read_all: whether to ignore certain setting types for GUI or not
 -- parse_mods: whether to parse settingtypes.txt in mods and games
 local function parse_config_file(read_all, parse_mods)
-	local builtin_path = core.get_builtin_path() .. FILENAME
-	local file = io.open(builtin_path, "r")
 	local settings = {}
-	if not file then
-		core.log("error", "Can't load " .. FILENAME)
-		return settings
-	end
 
-	parse_single_file(file, builtin_path, read_all, settings, 0, true)
+	do
+		local builtin_path = core.get_builtin_path() .. FILENAME
+		local file = io.open(builtin_path, "r")
+		if not file then
+			core.log("error", "Can't load " .. FILENAME)
+			return settings
+		end
+
+		parse_single_file(file, builtin_path, read_all, settings, 0, true)
 
-	file:close()
+		file:close()
+	end
 
 	if parse_mods then
 		-- Parse games
@@ -344,7 +347,7 @@ local function parse_config_file(read_all, parse_mods)
 			local file = io.open(path, "r")
 			if file then
 				if not games_category_initialized then
-					local translation = fgettext_ne("Games"), -- not used, but needed for xgettext
+					fgettext_ne("Games") -- not used, but needed for xgettext
 					table.insert(settings, {
 						name = "Games",
 						level = 0,
@@ -377,7 +380,7 @@ local function parse_config_file(read_all, parse_mods)
 			local file = io.open(path, "r")
 			if file then
 				if not mods_category_initialized then
-					local translation = fgettext_ne("Mods"), -- not used, but needed for xgettext
+					fgettext_ne("Mods") -- not used, but needed for xgettext
 					table.insert(settings, {
 						name = "Mods",
 						level = 0,
@@ -753,7 +756,7 @@ local function create_change_setting_formspec(dialogdata)
 			" (" .. setting.name .. ")"
 	end
 
-	local comment_text = ""
+	local comment_text
 	if setting.comment == "" then
 		comment_text = fgettext_ne("(No description of setting given)")
 	else
@@ -918,7 +921,7 @@ local function handle_change_setting_buttons(this, fields)
 	return false
 end
 
-local function create_settings_formspec(tabview, name, tabdata)
+local function create_settings_formspec(tabview, _, tabdata)
 	local formspec = "size[12,5.4;true]" ..
 			"tablecolumns[color;tree;text,width=28;text]" ..
 			"tableoptions[background=#00000000;border=false]" ..
@@ -950,7 +953,7 @@ local function create_settings_formspec(tabview, name, tabdata)
 			formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. ","
 					.. value .. ","
 
-		elseif entry.type == "key" then
+		elseif entry.type == "key" then --luacheck: ignore
 			-- ignore key settings, since we have a special dialog for them
 
 		elseif entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then
@@ -1029,8 +1032,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
 	if fields["btn_edit"] or list_enter then
 		local setting = settings[selected_setting]
 		if setting and setting.type ~= "category" then
-			local edit_dialog = dialog_create("change_setting", create_change_setting_formspec,
-					handle_change_setting_buttons)
+			local edit_dialog = dialog_create("change_setting",
+					create_change_setting_formspec, handle_change_setting_buttons)
 			edit_dialog:set_parent(this)
 			this:hide()
 			edit_dialog:show()
@@ -1076,4 +1079,5 @@ end
 -- For RUN_IN_PLACE the generated files may appear in the 'bin' folder.
 -- See comment and alternative line at the end of 'generate_from_settingtypes.lua'.
 
---assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))
+--assert(loadfile(core.get_builtin_path().."mainmenu"..DIR_DELIM..
+--		"generate_from_settingtypes.lua"))(parse_config_file(true, false))

+ 2 - 5
builtin/mainmenu/pkgmgr.lua

@@ -285,8 +285,6 @@ function pkgmgr.identify_modname(modpath,filename)
 end
 --------------------------------------------------------------------------------
 function pkgmgr.render_packagelist(render_list)
-	local retval = ""
-
 	if render_list == nil then
 		if pkgmgr.global_mods == nil then
 			pkgmgr.refresh_globals()
@@ -295,7 +293,6 @@ function pkgmgr.render_packagelist(render_list)
 	end
 
 	local list = render_list:get_list()
-	local last_modpack = nil
 	local retval = {}
 	for i, v in ipairs(list) do
 		local color = ""
@@ -465,7 +462,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
 			else
 				return nil,
 					fgettext("Install Mod: Unable to find suitable folder name for modpack $1",
-					modfilename)
+					path)
 			end
 		end
 	elseif basefolder.type == "mod" then
@@ -490,7 +487,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
 			if targetfolder ~= nil and pkgmgr.isValidModname(targetfolder) then
 				targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
 			else
-				return nil, fgettext("Install Mod: Unable to find real mod name for: $1", modfilename)
+				return nil, fgettext("Install Mod: Unable to find real mod name for: $1", path)
 			end
 		end
 

+ 2 - 2
builtin/mainmenu/tab_local.lua

@@ -21,7 +21,7 @@ local current_game, singleplayer_refresh_gamebar
 if enable_gamebar then
 	function current_game()
 		local last_game_id = core.settings:get("menu_last_game")
-		local game, index = pkgmgr.find_by_gameid(last_game_id)
+		local game = pkgmgr.find_by_gameid(last_game_id)
 
 		return game
 	end
@@ -222,7 +222,7 @@ local function main_button_handler(this, fields, name, tabdata)
 				--update last game
 				local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
 				if world then
-					local game, index = pkgmgr.find_by_gameid(world.gameid)
+					local game = pkgmgr.find_by_gameid(world.gameid)
 					core.settings:set("menu_last_game", game.id)
 				end
 

+ 3 - 3
builtin/mainmenu/tab_online.lua

@@ -20,7 +20,7 @@ local function get_formspec(tabview, name, tabdata)
 	-- Update the cached supported proto info,
 	-- it may have changed after a change by the settings menu.
 	common_update_cached_supp_proto()
-	local fav_selected = nil
+	local fav_selected
 	if menudata.search_result then
 		fav_selected = menudata.search_result[tabdata.fav_selected]
 	else
@@ -273,8 +273,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
 			for k = 1, #keywords do
 				local keyword = keywords[k]
 				if server.name then
-					local name = server.name:lower()
-					local _, count = name:gsub(keyword, keyword)
+					local sername = server.name:lower()
+					local _, count = sername:gsub(keyword, keyword)
 					found = found + count * 4
 				end
 

+ 0 - 2
builtin/mainmenu/tab_settings.lua

@@ -148,11 +148,9 @@ local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
 
 		core.create_world("singleplayerworld", 1)
 		worldlist = core.get_worlds()
-		found_singleplayerworld = false
 
 		for i = 1, #worldlist do
 			if worldlist[i].name == "singleplayerworld" then
-				found_singleplayerworld = true
 				gamedata.worldindex = i
 			end
 		end

+ 4 - 4
builtin/mainmenu/tab_simple_main.lua

@@ -188,10 +188,10 @@ local function main_button_handler(tabview, fields, name, tabdata)
 
 		core.settings:set("address", fields.te_address)
 		core.settings:set("remote_port", fields.te_port)
-			
- 		core.start()		
- 		return true		
- 	end
+
+		core.start()
+		return true
+	end
 
 	if fields.btn_config_sp_world then
 		local configdialog = create_configure_world_dlg(1)

+ 20 - 20
builtin/mainmenu/textures.lua

@@ -23,9 +23,9 @@ function mm_texture.init()
 	mm_texture.defaulttexturedir = core.get_texturepath() .. DIR_DELIM .. "base" ..
 						DIR_DELIM .. "pack" .. DIR_DELIM
 	mm_texture.basetexturedir = mm_texture.defaulttexturedir
-	
+
 	mm_texture.texturepack = core.settings:get("texture_path")
-	
+
 	mm_texture.gameid = nil
 end
 
@@ -39,7 +39,7 @@ function mm_texture.update(tab,gamedetails)
 	if gamedetails == nil then
 		return
 	end
-	
+
 	mm_texture.update_game(gamedetails)
 end
 
@@ -48,18 +48,18 @@ function mm_texture.reset()
 	mm_texture.gameid = nil
 	local have_bg      = false
 	local have_overlay = mm_texture.set_generic("overlay")
-	
+
 	if not have_overlay then
 		have_bg = mm_texture.set_generic("background")
 	end
-	
+
 	mm_texture.clear("header")
 	mm_texture.clear("footer")
 	core.set_clouds(false)
-	
+
 	mm_texture.set_generic("footer")
 	mm_texture.set_generic("header")
-	
+
 	if not have_bg then
 		if core.settings:get_bool("menu_clouds") then
 			core.set_clouds(true)
@@ -74,30 +74,30 @@ function mm_texture.update_game(gamedetails)
 	if mm_texture.gameid == gamedetails.id then
 		return
 	end
-	
+
 	local have_bg      = false
 	local have_overlay = mm_texture.set_game("overlay",gamedetails)
-	
+
 	if not have_overlay then
 		have_bg = mm_texture.set_game("background",gamedetails)
 	end
-	
+
 	mm_texture.clear("header")
 	mm_texture.clear("footer")
 	core.set_clouds(false)
-	
+
 	if not have_bg then
-		
+
 		if core.settings:get_bool("menu_clouds") then
 			core.set_clouds(true)
 		else
 			mm_texture.set_dirt_bg()
 		end
 	end
-	
+
 	mm_texture.set_game("footer",gamedetails)
 	mm_texture.set_game("header",gamedetails)
-	
+
 	mm_texture.gameid = gamedetails.id
 end
 
@@ -116,7 +116,7 @@ function mm_texture.set_generic(identifier)
 			return true
 		end
 	end
-	
+
 	if mm_texture.defaulttexturedir ~= nil then
 		local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
 										identifier .. ".png"
@@ -124,13 +124,13 @@ function mm_texture.set_generic(identifier)
 			return true
 		end
 	end
-	
+
 	return false
 end
 
 --------------------------------------------------------------------------------
 function mm_texture.set_game(identifier, gamedetails)
-	
+
 	if gamedetails == nil then
 		return false
 	end
@@ -142,7 +142,7 @@ function mm_texture.set_game(identifier, gamedetails)
 			return true
 		end
 	end
-	
+
 	-- Find out how many randomized textures the game provides
 	local n = 0
 	local filename
@@ -167,7 +167,7 @@ function mm_texture.set_game(identifier, gamedetails)
 	if core.set_background(identifier, path) then
 		return true
 	end
-	
+
 	return false
 end
 
@@ -178,7 +178,7 @@ function mm_texture.set_dirt_bg()
 			return true
 		end
 	end
-	
+
 	-- Use universal fallback texture in textures/base/pack
 	local minimalpath = defaulttexturedir .. "menu_bg.png"
 	core.set_background("background", minimalpath, true, 128)

+ 2 - 1
builtin/profiler/instrumentation.lua

@@ -117,7 +117,8 @@ end
 local function assert_can_be_called(func, func_name, level)
 	if not can_be_called(func) then
 		-- Then throw an *helpful* error, by pointing on our caller instead of us.
-		error(format("Invalid argument to %s. Expected function-like type instead of '%s'.", func_name, type(func)), level + 1)
+		error(format("Invalid argument to %s. Expected function-like type instead of '%s'.",
+				func_name, type(func)), level + 1)
 	end
 end