From e2df27e363724372501972180e94d8dd6e07cfa3 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Thu, 22 Feb 2018 04:15:02 +0000 Subject: [PATCH] lualoader: Address some 'luacheck' concerns luacheck pointed out an assortment of issues, ranging from non-standard globals being created as well as unused parameters, variables, and redundant assignments. Using '_' as a placeholder for values unused (whether it be parameters unused or return values unused, assuming multiple return values) feels clean and gets the point across, so I've adopted it. It also helps flag candidates for cleanup later in some of the lambdas I've created, giving me an easy way to re-evaluate later if we're still not using some of these features. --- stand/lua/cli.lua | 8 ++++---- stand/lua/config.lua | 19 ++++++++----------- stand/lua/core.lua | 1 - stand/lua/drawer.lua | 19 ++++++++++--------- stand/lua/loader.lua | 7 +++---- stand/lua/menu.lua | 14 +++++++------- stand/lua/password.lua | 2 +- 7 files changed, 33 insertions(+), 37 deletions(-) diff --git a/stand/lua/cli.lua b/stand/lua/cli.lua index c95d09a5fad6..757f11c4f7ce 100644 --- a/stand/lua/cli.lua +++ b/stand/lua/cli.lua @@ -50,7 +50,7 @@ local parse_boot_args = function(argv, with_kernel) local kernel_name local argstr = "" - for k, v in ipairs(argv) do + for _, v in ipairs(argv) do if with_kernel and v:sub(1,1) ~= "-" then kernel_name = v else @@ -92,7 +92,7 @@ end -- Module exports function cli.boot(...) - local cmd_name, argv = cli.arguments(...) + local _, argv = cli.arguments(...) local kernel, argstr = parse_boot_args(argv) if kernel ~= nil then loader.perform("unload") @@ -102,7 +102,7 @@ function cli.boot(...) end function cli.autoboot(...) - local cmd_name, argv = cli.arguments(...) + local _, argv = cli.arguments(...) local argstr = parse_boot_args(argv, false) core.autoboot(argstr) end @@ -110,7 +110,7 @@ end -- Used for splitting cli varargs into cmd_name and the rest of argv function cli.arguments(...) local argv = {...} - local cmd_name = "" + local cmd_name cmd_name, argv = core.popFrontTable(argv) return cmd_name, argv end diff --git a/stand/lua/config.lua b/stand/lua/config.lua index 84aedd3eb109..6bb45bfb4964 100644 --- a/stand/lua/config.lua +++ b/stand/lua/config.lua @@ -37,7 +37,7 @@ local carousel_choices = {} pattern_table = { [1] = { str = "^%s*(#.*)", - process = function(k, v) end + process = function(_, _) end }, -- module_load="value" [2] = { @@ -94,7 +94,7 @@ pattern_table = { -- exec="command" [9] = { str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)", - process = function(k, v) + process = function(k, _) if loader.perform(k) ~= 0 then print("Failed to exec '" .. k .. "'") end @@ -283,10 +283,7 @@ function config.parse(name, silent) return silent end - local text - local r - - text, r = io.read(f) + local text, _ = io.read(f) if text == nil then if not silent then @@ -302,7 +299,7 @@ function config.parse(name, silent) if line:match("^%s*$") == nil then local found = false - for i, val in ipairs(pattern_table) do + for _, val in ipairs(pattern_table) do local k, v, c = line:match(val.str) if k ~= nil then found = true @@ -339,7 +336,7 @@ function config.loadkernel(other_kernel) local try_load = function (names) for name in names:gmatch("([^;]+)%s*;?") do - r = loader.perform("load " .. flags .. " " .. name) + local r = loader.perform("load " .. flags .. " " .. name) if r == 0 then return name end @@ -376,7 +373,7 @@ function config.loadkernel(other_kernel) -- Use our cached module_path, so we don't end up with multiple -- automatically added kernel paths to our final module_path local module_path = config.module_path - local res = nil + local res if other_kernel ~= nil then kernel = other_kernel @@ -385,7 +382,7 @@ function config.loadkernel(other_kernel) -- then try load with module_path=${kernel} local paths = {"/boot/" .. kernel, kernel} - for k,v in pairs(paths) do + for _, v in pairs(paths) do loader.setenv("module_path", v) res = load_bootfile() @@ -452,7 +449,7 @@ end function config.loadelf() local kernel = config.kernel_selected or config.kernel_loaded - local loaded = false + local loaded print("Loading kernel...") loaded = config.loadkernel(kernel) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 05f46a2290c8..43c5f15f42db 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -200,7 +200,6 @@ function core.bootenvList() local bootenv_count = tonumber(loader.getenv("bootenvs_count")) local bootenvs = {} local curenv - local curenv_idx = 0 local envcount = 0 local unique = {} diff --git a/stand/lua/drawer.lua b/stand/lua/drawer.lua index f2ad0be17eec..eb260c92263a 100644 --- a/stand/lua/drawer.lua +++ b/stand/lua/drawer.lua @@ -38,6 +38,7 @@ local fbsd_logo local beastie_color local beastie local fbsd_logo_v +local orb_color local orb local none local none_shifted = false @@ -178,7 +179,7 @@ drawer.menu_name_handlers = { -- This is designed so that everything, including menu separators, may -- have their names derived differently. The default action for entry -- types not specified here is to use entry.name directly. - [core.MENU_SEPARATOR] = function(drawing_menu, entry) + [core.MENU_SEPARATOR] = function(_, entry) if entry.name ~= nil then if type(entry.name) == "function" then return entry.name() @@ -187,7 +188,7 @@ drawer.menu_name_handlers = { end return "" end, - [core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry) + [core.MENU_CAROUSEL_ENTRY] = function(_, entry) local carid = entry.carousel_id local caridx = config.getCarouselIndex(carid) local choices = entry.items @@ -263,8 +264,8 @@ function drawer.drawscreen(menu_opts) end function drawer.drawmenu(m) - x = drawer.menu_position.x - y = drawer.menu_position.y + local x = drawer.menu_position.x + local y = drawer.menu_position.y -- print the menu and build the alias table local alias_table = {} @@ -288,7 +289,7 @@ function drawer.drawmenu(m) -- fill the alias table alias_table[tostring(entry_num)] = e if e.alias ~= nil then - for n, a in ipairs(e.alias) do + for _, a in ipairs(e.alias) do alias_table[a] = e end end @@ -303,10 +304,10 @@ end function drawer.drawbox() - x = drawer.box_pos_dim.x - y = drawer.box_pos_dim.y - w = drawer.box_pos_dim.w - h = drawer.box_pos_dim.h + local x = drawer.box_pos_dim.x + local y = drawer.box_pos_dim.y + local w = drawer.box_pos_dim.w + local h = drawer.box_pos_dim.h local hl = string.char(0xCD) local vl = string.char(0xBA) diff --git a/stand/lua/loader.lua b/stand/lua/loader.lua index 6b658a59b5cb..48bc429cdb13 100644 --- a/stand/lua/loader.lua +++ b/stand/lua/loader.lua @@ -27,16 +27,15 @@ -- $FreeBSD$ -- -local cli = require("cli") +require("cli") local config = require("config") local menu = require("menu") local password = require("password") -local local_module -local result, errstr, errnoval = lfs.attributes("/boot/lua/local.lua") +local result, _, _ = lfs.attributes("/boot/lua/local.lua") -- Effectively discard any errors; we'll just act if it succeeds. if result ~= nil then - local_module = require("local") + require("local") end config.load() diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index 55f4f34e12c1..f9ff91a96b69 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -59,11 +59,11 @@ menu.handlers = { -- continue or not. The return value may be omitted if this entry should -- have no bearing on whether we continue or not, indicating that we -- should just continue after execution. - [core.MENU_ENTRY] = function(current_menu, entry) + [core.MENU_ENTRY] = function(_, entry) -- run function entry.func() end, - [core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry) + [core.MENU_CAROUSEL_ENTRY] = function(_, entry) -- carousel (rotating) functionality local carid = entry.carousel_id local caridx = config.getCarouselIndex(carid) @@ -77,11 +77,11 @@ menu.handlers = { entry.func(caridx, choices[caridx], choices) end end, - [core.MENU_SUBMENU] = function(current_menu, entry) + [core.MENU_SUBMENU] = function(_, entry) -- recurse return menu.run(entry.submenu) end, - [core.MENU_RETURN] = function(current_menu, entry) + [core.MENU_RETURN] = function(_, entry) -- allow entry to have a function/side effect if entry.func ~= nil then entry.func() @@ -122,7 +122,7 @@ menu.boot_environments = { bootenv_name .. " (" .. idx .. " of " .. #all_choices .. ")" end, - func = function(idx, choice, all_choices) + func = function(_, choice, _) bootenvSet(choice) end, alias = {"a", "A"}, @@ -312,7 +312,7 @@ menu.welcome = { kernel_name .. " (" .. idx .. " of " .. #all_choices .. ")" end, - func = function(idx, choice, all_choices) + func = function(_, choice, _) config.selectkernel(choice) end, alias = {"k", "K"} @@ -361,7 +361,7 @@ function menu.run(m) if m == menu.default then autoboot_key = menu.autoboot() end - cont = true + local cont = true while cont do local key = autoboot_key or io.getchar() autoboot_key = nil diff --git a/stand/lua/password.lua b/stand/lua/password.lua index 92dce5e39b37..77ece36aa5b0 100644 --- a/stand/lua/password.lua +++ b/stand/lua/password.lua @@ -38,7 +38,7 @@ function password.read() local n = 0 while true do - ch = io.getchar() + local ch = io.getchar() if ch == core.KEY_ENTER then break end