Add luacheck and fix reported warnings
This commit is contained in:
parent
5545c25ea7
commit
a3c1a490e0
|
@ -0,0 +1,11 @@
|
||||||
|
on: [push, pull_request]
|
||||||
|
name: build
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- name: lint
|
||||||
|
uses: Roang-zero1/factorio-mod-luacheck@master
|
||||||
|
with:
|
||||||
|
luacheckrc_url: ""
|
|
@ -0,0 +1,23 @@
|
||||||
|
max_line_length = 80
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
'formspec_ast',
|
||||||
|
'minetest',
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
string = {fields = {'split', 'trim'}},
|
||||||
|
table = {fields = {'copy'}}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- The elements.lua file is auto-generated and has a hideously long line which
|
||||||
|
-- luacheck complains about.
|
||||||
|
files["elements.lua"].ignore = {""}
|
||||||
|
|
||||||
|
-- Because formspec_ast supports running outside of MT, some string and table
|
||||||
|
-- functions are added in init.lua (unless running in MT).
|
||||||
|
files['init.lua'].globals = read_globals
|
||||||
|
|
||||||
|
-- This error is thrown for methods that don't use the implicit "self"
|
||||||
|
-- parameter.
|
||||||
|
ignore = {"212/self"}
|
15
core.lua
15
core.lua
|
@ -83,7 +83,6 @@ local function raw_parse(spec)
|
||||||
if #inner > 0 then
|
if #inner > 0 then
|
||||||
table.insert(inner, i)
|
table.insert(inner, i)
|
||||||
table.insert(elem, inner)
|
table.insert(elem, inner)
|
||||||
inner = {}
|
|
||||||
else
|
else
|
||||||
table.insert(elem, i)
|
table.insert(elem, i)
|
||||||
end
|
end
|
||||||
|
@ -204,7 +203,7 @@ types['...'] = function(elems, obj, res)
|
||||||
local template = {obj}
|
local template = {obj}
|
||||||
local val = {}
|
local val = {}
|
||||||
local is_string = type(obj[2]) == 'string'
|
local is_string = type(obj[2]) == 'string'
|
||||||
for i, elem in ipairs(elems) do
|
for _, elem in ipairs(elems) do
|
||||||
local n = parse_value({elem}, template)
|
local n = parse_value({elem}, template)
|
||||||
if is_string then
|
if is_string then
|
||||||
n = n[obj[1]]
|
n = n[obj[1]]
|
||||||
|
@ -251,7 +250,7 @@ local function parse_elem(elem, custom_handlers)
|
||||||
end
|
end
|
||||||
|
|
||||||
local good, ast_elem
|
local good, ast_elem
|
||||||
for i, template in ipairs(data) do
|
for _, template in ipairs(data) do
|
||||||
if type(template) == 'function' then
|
if type(template) == 'function' then
|
||||||
good, ast_elem = pcall(template, elem)
|
good, ast_elem = pcall(template, elem)
|
||||||
if good and (not ast_elem or not ast_elem.type) then
|
if good and (not ast_elem or not ast_elem.type) then
|
||||||
|
@ -351,7 +350,7 @@ local function unparse_ellipsis(elem, obj1, res, inner)
|
||||||
elseif type(obj1[2]) == 'string' then
|
elseif type(obj1[2]) == 'string' then
|
||||||
local value = elem[obj1[1]]
|
local value = elem[obj1[1]]
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
for k, v in ipairs(value) do
|
for _, v in ipairs(value) do
|
||||||
table.insert(res, tostring(v))
|
table.insert(res, tostring(v))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -359,7 +358,7 @@ local function unparse_ellipsis(elem, obj1, res, inner)
|
||||||
local data = elem[elem.type or 'data'] or elem
|
local data = elem[elem.type or 'data'] or elem
|
||||||
for _, elem2 in ipairs(data) do
|
for _, elem2 in ipairs(data) do
|
||||||
local r = {}
|
local r = {}
|
||||||
for i, obj2 in ipairs(obj1) do
|
for _, obj2 in ipairs(obj1) do
|
||||||
if obj2[2] == '...' then
|
if obj2[2] == '...' then
|
||||||
unparse_ellipsis(elem2, obj2[1], r, true)
|
unparse_ellipsis(elem2, obj2[1], r, true)
|
||||||
elseif type(obj2[2]) == 'string' then
|
elseif type(obj2[2]) == 'string' then
|
||||||
|
@ -421,7 +420,7 @@ local function unparse_elem(elem, res, force)
|
||||||
local err = unparse_elem(elem, res, true)
|
local err = unparse_elem(elem, res, true)
|
||||||
if err then return err end
|
if err then return err end
|
||||||
for _, e in ipairs(elem) do
|
for _, e in ipairs(elem) do
|
||||||
local err = unparse_elem(e, res)
|
err = unparse_elem(e, res)
|
||||||
if err then return err end
|
if err then return err end
|
||||||
end
|
end
|
||||||
return unparse_elem({type=elem.type .. '_end'}, res, true)
|
return unparse_elem({type=elem.type .. '_end'}, res, true)
|
||||||
|
@ -434,7 +433,7 @@ local function unparse_elem(elem, res, force)
|
||||||
|
|
||||||
local good, raw_elem
|
local good, raw_elem
|
||||||
local possible_elems = {}
|
local possible_elems = {}
|
||||||
for i, template in ipairs(data) do
|
for _, template in ipairs(data) do
|
||||||
if type(template) == 'function' then
|
if type(template) == 'function' then
|
||||||
good, raw_elem = false, 'Unknown element.'
|
good, raw_elem = false, 'Unknown element.'
|
||||||
else
|
else
|
||||||
|
@ -520,7 +519,7 @@ function parse_mt:__index(key)
|
||||||
return func(obj or '')
|
return func(obj or '')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return function(obj)
|
return function(_)
|
||||||
error('Unknown element type: ' .. tostring(key))
|
error('Unknown element type: ' .. tostring(key))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
10
helpers.lua
10
helpers.lua
|
@ -137,9 +137,9 @@ function formspec_ast.show_formspec(player, formname, formspec)
|
||||||
return 'No such player!'
|
return 'No such player!'
|
||||||
end
|
end
|
||||||
|
|
||||||
local formspec, err = formspec_ast.interpret(formspec)
|
local new_fs, err = formspec_ast.interpret(formspec)
|
||||||
if formspec then
|
if new_fs then
|
||||||
minetest.show_formspec(player, formname, formspec)
|
minetest.show_formspec(player, formname, new_fs)
|
||||||
else
|
else
|
||||||
minetest.log('warning', 'formspec_ast.show_formspec(): ' ..
|
minetest.log('warning', 'formspec_ast.show_formspec(): ' ..
|
||||||
tostring(err))
|
tostring(err))
|
||||||
|
@ -166,7 +166,7 @@ formspec_ast.register_element('formspec_ast:centered_label', function(raw,
|
||||||
y = 0,
|
y = 0,
|
||||||
w = parse.number(raw[2][1]),
|
w = parse.number(raw[2][1]),
|
||||||
h = parse.number(raw[2][2]),
|
h = parse.number(raw[2][2]),
|
||||||
texture_name = '',
|
texture_name = 'blank.png',
|
||||||
name = '',
|
name = '',
|
||||||
label = parse.string(raw[3]),
|
label = parse.string(raw[3]),
|
||||||
noclip = true,
|
noclip = true,
|
||||||
|
@ -193,7 +193,7 @@ formspec_ast.register_element('formspec_ast:centered_label', function(raw,
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Add a formspec element to crash clients
|
-- Add a formspec element to crash clients
|
||||||
formspec_ast.register_element('formspec_ast:crash', function(raw, parse)
|
formspec_ast.register_element('formspec_ast:crash', function(_, _)
|
||||||
return {
|
return {
|
||||||
type = 'list',
|
type = 'list',
|
||||||
inventory_location = '___die',
|
inventory_location = '___die',
|
||||||
|
|
|
@ -186,8 +186,8 @@ function formspec_ast.safe_parse(tree, custom_handlers)
|
||||||
|
|
||||||
-- Iterate over the tree and add valid elements to a new table.
|
-- Iterate over the tree and add valid elements to a new table.
|
||||||
local res = {formspec_version = tree.formspec_version}
|
local res = {formspec_version = tree.formspec_version}
|
||||||
for i, elem in ipairs(tree) do
|
for _, elem in ipairs(tree) do
|
||||||
local good, msg = pcall(validate_elem, elem)
|
local good, _ = pcall(validate_elem, elem)
|
||||||
if good then
|
if good then
|
||||||
res[#res + 1] = elem
|
res[#res + 1] = elem
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue