Skip to content
Snippets Groups Projects
Commit 4249d65a authored by bobcanthelpyou's avatar bobcanthelpyou
Browse files

treewide: fix luacheck warnings

parent 80b6e7f1
No related branches found
No related tags found
No related merge requests found
Showing
with 55 additions and 52 deletions
...@@ -57,7 +57,7 @@ local f_password = Form(translate("Password"), translate( ...@@ -57,7 +57,7 @@ local f_password = Form(translate("Password"), translate(
) )
f_password.reset = false f_password.reset = false
local s = f_password:section(Section) s = f_password:section(Section)
local pw1 = s:option(Value, "pw1", translate("Password")) local pw1 = s:option(Value, "pw1", translate("Password"))
pw1.password = true pw1.password = true
......
...@@ -22,18 +22,18 @@ function mode:write(data) ...@@ -22,18 +22,18 @@ function mode:write(data)
-- methods will be recreated and filled with the original values from site.mesh_vpn.fastd.methods -- methods will be recreated and filled with the original values from site.mesh_vpn.fastd.methods
-- if performance mode was selected, and the method 'null' was not present in the original table, it will be added -- if performance mode was selected, and the method 'null' was not present in the original table, it will be added
local methods = {} local site_methods = {}
if data == 'performance' then if data == 'performance' then
table.insert(methods, 'null') table.insert(site_methods, 'null')
end end
for _, method in ipairs(site.mesh_vpn.fastd.methods()) do for _, method in ipairs(site.mesh_vpn.fastd.methods()) do
if method ~= 'null' then if method ~= 'null' then
table.insert(methods, method) table.insert(site_methods, method)
end end
end end
uci:set('fastd', 'mesh_vpn', 'method', methods) uci:set('fastd', 'mesh_vpn', 'method', site_methods)
uci:save('fastd') uci:save('fastd')
uci:commit('fastd') uci:commit('fastd')
......
...@@ -13,7 +13,7 @@ local function load(filename, i18n) ...@@ -13,7 +13,7 @@ local function load(filename, i18n)
local func = assert(loadfile(filename)) local func = assert(loadfile(filename))
setfenv(func, setmetatable({}, {__index = setfenv(func, setmetatable({}, {__index =
function(tbl, key) function(_, key)
return classes[key] or i18n[key] or _G[key] return classes[key] or i18n[key] or _G[key]
end end
})) }))
......
...@@ -145,7 +145,7 @@ function AbstractValue:depends(field, value) ...@@ -145,7 +145,7 @@ function AbstractValue:depends(field, value)
table.insert(self.deps, deps) table.insert(self.deps, deps)
end end
function AbstractValue:deplist(section, deplist) function AbstractValue:deplist(_, deplist)
local deps = {} local deps = {}
for _, d in ipairs(deplist or self.deps) do for _, d in ipairs(deplist or self.deps) do
...@@ -257,7 +257,8 @@ function AbstractValue:handle() ...@@ -257,7 +257,8 @@ function AbstractValue:handle()
end end
end end
function AbstractValue:write(value) -- will be overridden: write(value)
function AbstractValue:write()
end end
......
...@@ -42,7 +42,7 @@ ipv4_gateway.default = wan.gateway ...@@ -42,7 +42,7 @@ ipv4_gateway.default = wan.gateway
ipv4_gateway.datatype = "ip4addr" ipv4_gateway.datatype = "ip4addr"
local s = f:section(Section) s = f:section(Section)
local ipv6 = s:option(ListValue, "ipv6", translate("IPv6")) local ipv6 = s:option(ListValue, "ipv6", translate("IPv6"))
ipv6:value("dhcpv6", translate("Automatic (RA/DHCPv6)")) ipv6:value("dhcpv6", translate("Automatic (RA/DHCPv6)"))
...@@ -61,7 +61,7 @@ ipv6_gateway.default = wan6.ip6gw ...@@ -61,7 +61,7 @@ ipv6_gateway.default = wan6.ip6gw
ipv6_gateway.datatype = "ip6addr" ipv6_gateway.datatype = "ip6addr"
if dns_static then if dns_static then
local s = f:section(Section) s = f:section(Section)
local dns = s:option(DynamicList, "dns", translate("Static DNS servers")) local dns = s:option(DynamicList, "dns", translate("Static DNS servers"))
dns.default = uci:get_list("gluon-wan-dnsmasq", dns_static, "server") dns.default = uci:get_list("gluon-wan-dnsmasq", dns_static, "server")
...@@ -74,7 +74,7 @@ if dns_static then ...@@ -74,7 +74,7 @@ if dns_static then
end end
end end
local s = f:section(Section) s = f:section(Section)
local mesh_wan = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface")) local mesh_wan = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
mesh_wan.default = not uci:get_bool("network", "mesh_wan", "disabled") mesh_wan.default = not uci:get_bool("network", "mesh_wan", "disabled")
...@@ -84,7 +84,7 @@ function mesh_wan:write(data) ...@@ -84,7 +84,7 @@ function mesh_wan:write(data)
end end
if sysconfig.lan_ifname then if sysconfig.lan_ifname then
local s = f:section(Section) s = f:section(Section)
local mesh_lan = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface")) local mesh_lan = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
mesh_lan.default = not uci:get_bool("network", "mesh_lan", "disabled") mesh_lan.default = not uci:get_bool("network", "mesh_lan", "disabled")
...@@ -107,24 +107,24 @@ if sysconfig.lan_ifname then ...@@ -107,24 +107,24 @@ if sysconfig.lan_ifname then
end end
local section local section
uci:foreach("system", "gpio_switch", function(s) uci:foreach("system", "gpio_switch", function(si)
if s[".name"]:match("poe") then if si[".name"]:match("poe") then
if not section then if not section then
section = f:section(Section) section = f:section(Section)
end end
local port = s.name:match("^PoE Power Port(%d*)$") local port = si.name:match("^PoE Power Port(%d*)$")
local name local name
if port then if port then
name = translatef("Enable PoE Power Port %s", port) name = translatef("Enable PoE Power Port %s", port)
else else
name = translate("Enable " .. s.name) name = translate("Enable " .. si.name)
end end
local poe = section:option(Flag, s[".name"], name) local poe = section:option(Flag, si[".name"], name)
poe.default = uci:get_bool("system", s[".name"], "value") poe.default = uci:get_bool("system", si[".name"], "value")
function poe:write(data) function poe:write(data)
uci:set("system", s[".name"], "value", data) uci:set("system", si[".name"], "value", data)
end end
end end
end) end)
......
...@@ -17,8 +17,8 @@ s = f:section(Section, nil, translate( ...@@ -17,8 +17,8 @@ s = f:section(Section, nil, translate(
o = s:option(ListValue, "role", translate("Role")) o = s:option(ListValue, "role", translate("Role"))
o.default = role o.default = role
for _, role in ipairs(site.roles.list()) do for _, role_value in ipairs(site.roles.list()) do
o:value(role, site_i18n.translate('gluon-web-node-role:role:' .. role)) o:value(role, site_i18n.translate('gluon-web-node-role:role:' .. role_value))
end end
function o:write(data) function o:write(data)
......
local iwinfo = require 'iwinfo' local iwinfo = require 'iwinfo'
local site = require 'gluon.site'
local uci = require("simple-uci").cursor() local uci = require("simple-uci").cursor()
local util = require 'gluon.util' local util = require 'gluon.util'
......
...@@ -109,8 +109,8 @@ local function dispatch(config, http, request) ...@@ -109,8 +109,8 @@ local function dispatch(config, http, request)
return _node({...}) return _node({...})
end, end,
entry = function(path, target, title, order) entry = function(entry_path, target, title, order)
local c = _node(path, true) local c = _node(entry_path, true)
c.target = target c.target = target
c.title = title c.title = title
...@@ -204,7 +204,7 @@ return function(config, http) ...@@ -204,7 +204,7 @@ return function(config, http)
table.insert(request, node) table.insert(request, node)
end end
ok, err = pcall(dispatch, config, http, request) local ok, err = pcall(dispatch, config, http, request)
if not ok then if not ok then
http:status(500, "Internal Server Error") http:status(500, "Internal Server Error")
http:prepare_content("text/plain") http:prepare_content("text/plain")
......
...@@ -53,7 +53,7 @@ end ...@@ -53,7 +53,7 @@ end
function Http:getcookie(name) function Http:getcookie(name)
local c = string.gsub(";" .. (self:getenv("HTTP_COOKIE") or "") .. ";", "%s*;%s*", ";") local c = string.gsub(";" .. (self:getenv("HTTP_COOKIE") or "") .. ";", "%s*;%s*", ";")
local p = ";" .. name .. "=(.-);" local p = ";" .. name .. "=(.-);"
local i, j, value = c:find(p) local _, _, value = c:find(p)
return value and protocol.urldecode(value) return value and protocol.urldecode(value)
end end
......
...@@ -124,13 +124,13 @@ local function mimedecode_message_body(src, msg, filecb) ...@@ -124,13 +124,13 @@ local function mimedecode_message_body(src, msg, filecb)
local store = nil local store = nil
local lchunk = nil local lchunk = nil
local function parse_headers(chunk, field) local function parse_headers(chunk, pfield)
local stat local stat
repeat repeat
chunk, stat = chunk:gsub( chunk, stat = chunk:gsub(
"^([A-Z][A-Za-z0-9%-_]+): +([^\r\n]+)\r\n", "^([A-Z][A-Za-z0-9%-_]+): +([^\r\n]+)\r\n",
function(k,v) function(k,v)
field.headers[k] = v pfield.headers[k] = v
return "" return ""
end end
) )
...@@ -140,26 +140,26 @@ local function mimedecode_message_body(src, msg, filecb) ...@@ -140,26 +140,26 @@ local function mimedecode_message_body(src, msg, filecb)
-- End of headers -- End of headers
if stat > 0 then if stat > 0 then
if field.headers["Content-Disposition"] then if pfield.headers["Content-Disposition"] then
if field.headers["Content-Disposition"]:match("^form%-data; ") then if pfield.headers["Content-Disposition"]:match("^form%-data; ") then
field.name = field.headers["Content-Disposition"]:match('name="(.-)"') pfield.name = pfield.headers["Content-Disposition"]:match('name="(.-)"')
field.file = field.headers["Content-Disposition"]:match('filename="(.+)"$') pfield.file = pfield.headers["Content-Disposition"]:match('filename="(.+)"$')
end end
end end
if not field.headers["Content-Type"] then if not pfield.headers["Content-Type"] then
field.headers["Content-Type"] = "text/plain" pfield.headers["Content-Type"] = "text/plain"
end end
if field.name then if pfield.name then
initval(msg.params, field.name) initval(msg.params, pfield.name)
if field.file then if pfield.file then
appendval(msg.params, field.name, field.file) appendval(msg.params, pfield.name, pfield.file)
store = filecb store = filecb
else else
store = function(hdr, buf, eof) store = function(_, buf, _)
appendval(msg.params, field.name, buf) appendval(msg.params, pfield.name, buf)
end end
end end
else else
...@@ -197,6 +197,7 @@ local function mimedecode_message_body(src, msg, filecb) ...@@ -197,6 +197,7 @@ local function mimedecode_message_body(src, msg, filecb)
if spos then if spos then
local predata = data:sub(1, spos - 1) local predata = data:sub(1, spos - 1)
local eof
if inhdr then if inhdr then
predata, eof = parse_headers(predata, field) predata, eof = parse_headers(predata, field)
...@@ -225,11 +226,12 @@ local function mimedecode_message_body(src, msg, filecb) ...@@ -225,11 +226,12 @@ local function mimedecode_message_body(src, msg, filecb)
-- We found at least some boundary. Save -- We found at least some boundary. Save
-- the unparsed remaining data for the -- the unparsed remaining data for the
-- next chunk. -- next chunk.
lchunk, data = data, nil lchunk = data
else else
-- There was a complete chunk without a boundary. Parse it as headers or -- There was a complete chunk without a boundary. Parse it as headers or
-- append it as data, depending on our current state. -- append it as data, depending on our current state.
if inhdr then if inhdr then
local eof
lchunk, eof = parse_headers(data, field) lchunk, eof = parse_headers(data, field)
inhdr = not eof inhdr = not eof
else else
...@@ -240,7 +242,7 @@ local function mimedecode_message_body(src, msg, filecb) ...@@ -240,7 +242,7 @@ local function mimedecode_message_body(src, msg, filecb)
if store then if store then
store(field, lchunk, false) store(field, lchunk, false)
end end
lchunk, chunk = chunk, nil lchunk = chunk
end end
end end
end end
......
...@@ -13,7 +13,7 @@ return function(config) ...@@ -13,7 +13,7 @@ return function(config)
return string.format('%s/%s.%s.lmo', i18ndir, pkg, lang) return string.format('%s/%s.%s.lmo', i18ndir, pkg, lang)
end end
local function no_translation(key) local function no_translation()
return nil return nil
end end
......
...@@ -44,13 +44,13 @@ return function(config, env) ...@@ -44,13 +44,13 @@ return function(config, env)
translate = t.translate, translate = t.translate,
translatef = t.translatef, translatef = t.translatef,
_translate = t._translate, _translate = t._translate,
include = function(name) include = function(include_name)
ctx.render(name, scope, pkg) ctx.render(include_name, scope, pkg)
end, end,
} }
setfenv(template, setmetatable({}, { setfenv(template, setmetatable({}, {
__index = function(tbl, key) __index = function(_, key)
return scope[key] or locals[key] or env[key] return scope[key] or locals[key] or env[key]
end end
})) }))
......
...@@ -37,7 +37,7 @@ local site, domain_code, domain, conf ...@@ -37,7 +37,7 @@ local site, domain_code, domain, conf
local function merge(a, b) local function merge(a, b)
local function is_array(t) local function is_array(t)
local n = 0 local n = 0
for k, v in pairs(t) do for _ in pairs(t) do
n = n + 1 n = n + 1
end end
return n == #t return n == #t
...@@ -216,12 +216,12 @@ local function check_chanlist(channels) ...@@ -216,12 +216,12 @@ local function check_chanlist(channels)
return function(chanlist) return function(chanlist)
for group in chanlist:gmatch("%S+") do for group in chanlist:gmatch("%S+") do
if group:match("^%d+$") then if group:match("^%d+$") then
channel = tonumber(group) local channel = tonumber(group)
if not is_valid_channel(channel) then if not is_valid_channel(channel) then
return false return false
end end
elseif group:match("^%d+-%d+$") then elseif group:match("^%d+-%d+$") then
from, to = group:match("^(%d+)-(%d+)$") local from, to = group:match("^(%d+)-(%d+)$")
from = tonumber(from) from = tonumber(from)
to = tonumber(to) to = tonumber(to)
if from >= to then if from >= to then
...@@ -344,8 +344,9 @@ end ...@@ -344,8 +344,9 @@ end
function need_chanlist(path, channels, required) function need_chanlist(path, channels, required)
local valid_chanlist = check_chanlist(channels) local valid_chanlist = check_chanlist(channels)
return need(path, valid_chanlist, required, 'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). ' .. return need(path, valid_chanlist, required,
'Valid channels are: ' .. array_to_string(channels)) 'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). '
.. 'Valid channels are: ' .. array_to_string(channels))
end end
function need_domain_name(path) function need_domain_name(path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment