Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add df-luacheck to Travis build. #1295

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "depends/jsoncpp"]
path = depends/jsoncpp-sub
url = ../../DFHack/jsoncpp.git
[submodule "travis/df-luacheck"]
path = travis/df-luacheck
url = ../../DFHack/df-luacheck.git
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cache:
directories:
- $HOME/DF-travis
- $HOME/lua53
- $TRAVIS_BUILD_DIR/travis/df-luacheck/node_modules
addons:
apt:
packages: &default_packages
Expand Down Expand Up @@ -32,6 +33,7 @@ before_install:
- pip install --user "sphinx==1.4" "requests[security]"
- sh travis/build-lua.sh
- sh travis/download-df.sh
- cd travis/df-luacheck && npm install && cd ../..
- echo "export DFHACK_HEADLESS=1" >> "$HOME/.dfhackrc"
- echo "export DFHACK_DISABLE_CONSOLE=1" >> "$HOME/.dfhackrc"
script:
Expand All @@ -54,6 +56,7 @@ script:
- cp travis/dfhack_travis.init "$DF_FOLDER"/
- python travis/run-tests.py "$DF_FOLDER"
- python travis/check-rpc.py "$DF_FOLDER/dfhack-rpc.txt"
- travis/df-luacheck/luacheck.sh --verbose .
before_cache:
- cat "$DF_FOLDER/stderr.log"
- rm -rf "$DF_FOLDER"
Expand Down
3 changes: 2 additions & 1 deletion library/lua/binpatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local function load_patch(name)
return nil, 'could not parse: '..line
end

offset, oldv, newv = tonumber(offset,16), tonumber(oldv,16), tonumber(newv,16)
offset, oldv, newv = tonumber(offset,16), tonumber(oldv,16), tonumber(newv,16) --luacheck: retype
if oldv > 255 or newv > 255 then
file:close()
return nil, 'invalid byte values: '..line
Expand Down Expand Up @@ -67,6 +67,7 @@ local function rebase_patch(patch)
return { name = patch.name, old_bytes = nold, new_bytes = nnew }
end

--luacheck: defclass={name:string,old_bytes:'number[]',new_bytes:'number[]'}
BinaryPatch = defclass(BinaryPatch)

BinaryPatch.ATTRS {
Expand Down
2 changes: 1 addition & 1 deletion library/lua/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class_obj = class_obj or {}
common_methods = common_methods or {}

-- Forbidden names for class fields and methods.
reserved_names = { super = true, ATTRS = true }
local reserved_names = { super = true, ATTRS = true }

-- Attribute table metatable
attrs_meta = attrs_meta or {}
Expand Down
15 changes: 10 additions & 5 deletions library/lua/dfhack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ end

-- Error handling

--luacheck: global
safecall = dfhack.safecall
--luacheck: global
curry = dfhack.curry

function dfhack.pcall(f, ...)
Expand Down Expand Up @@ -87,6 +89,7 @@ dfhack.exception.__index = dfhack.exception

-- Module loading

--luacheck: skip
local function find_required_module_arg()
-- require -> module code -> mkmodule -> find_...
if debug.getinfo(4,'f').func == require then
Expand Down Expand Up @@ -353,7 +356,7 @@ function safe_index(obj,idx,...)
if type(idx) == 'number' and (idx < 0 or idx >= #obj) then
return nil
end
obj = obj[idx]
obj = obj[idx] --luacheck: retype
if select('#',...) > 0 then
return safe_index(obj,...)
else
Expand Down Expand Up @@ -600,6 +603,7 @@ end
function dfhack.reqscript(name)
return dfhack.script_environment(name, true)
end
--luacheck: global
reqscript = dfhack.reqscript

function dfhack.script_environment(name, strict)
Expand Down Expand Up @@ -736,7 +740,8 @@ function dfhack.script_help(script_name, extension)
end

local function _run_command(...)
args = {...}
local command = {} --as:__arg
local args = {...}
if type(args[1]) == 'table' then
command = args[1]
elseif #args > 1 and type(args[2]) == 'table' then
Expand Down Expand Up @@ -792,7 +797,7 @@ if dfhack.is_core_context then
if dfhack.filesystem.exists(name) then
dfhack.printerr(perr)
end
elseif safecall(f) then
elseif safecall(f) then --luacheck: skip
if not internal.save_init then
internal.save_init = {}
end
Expand All @@ -802,7 +807,7 @@ if dfhack.is_core_context then

dfhack.onStateChange.DFHACK_PER_SAVE = function(op)
if op == SC_WORLD_LOADED or op == SC_WORLD_UNLOADED then
if internal.save_init then
if internal.save_init then --luacheck: skip
for k,v in ipairs(internal.save_init) do
if v.onUnload then
safecall(v.onUnload)
Expand All @@ -828,7 +833,7 @@ if dfhack.is_core_context then
end
elseif internal.save_init then
for k,v in ipairs(internal.save_init) do
if v.onStateChange then
if v.onStateChange then --luacheck: skip
safecall(v.onStateChange, op)
end
end
Expand Down
26 changes: 17 additions & 9 deletions library/lua/dfhack/workshops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local _ENV = mkmodule('dfhack.workshops')

local utils = require 'utils'

--luacheck:global
input_filter_defaults = {
item_type = -1,
item_subtype = -1,
Expand All @@ -24,7 +25,12 @@ input_filter_defaults = {
quantity = 1
}
local fuel={item_type=df.item_type.BAR,mat_type=df.builtin_mats.COAL}
jobs_furnace={

-- typedef for luacheck
local workshop_job = {} --as:{_type:workshop_job,name:string,items:'input_filter_defaults[]',job_fields:none}

--luacheck:global
jobs_furnace={ --as:workshop_job[][]
[df.furnace_type.Smelter]={
{
name="Melt metal object",
Expand Down Expand Up @@ -85,7 +91,8 @@ jobs_furnace={
}
},
}
jobs_workshop={
--luacheck:global
jobs_workshop={ --as:workshop_job[][]

[df.workshop_type.Jewelers]={
{
Expand Down Expand Up @@ -398,7 +405,7 @@ jobs_workshop={
},
},
[df.workshop_type.Leatherworks]={
defaults={item_type=SKIN_TANNED},
defaults={item_type=df.item_type.SKIN_TANNED},
{
name="construct leather bag",
items={{}},
Expand Down Expand Up @@ -475,7 +482,7 @@ local function matchIds(bid1,wid1,cid1,bid2,wid2,cid2)
return true
end
local function scanRawsReaction(buildingId,workshopId,customId)
local ret={}
local ret={} --as:df.reaction[]
for idx,reaction in ipairs(df.global.world.raws.reactions.reactions) do
for k,v in pairs(reaction.building.type) do
if matchIds(buildingId,workshopId,customId,v,reaction.building.subtype[k],reaction.building.custom[k]) then
Expand All @@ -495,7 +502,7 @@ end
local function addReactionJobs(ret,bid,wid,cid)
local reactions=scanRawsReaction(bid,wid or -1,cid or -1)
for idx,react in pairs(reactions) do
local job={name=react.name,
local job={name=react.name, --as:workshop_job
items={},job_fields={job_type=df.job_type.CustomReaction,reaction_name=react.code}
}
for reagentId,reagent in pairs(react.reagents) do
Expand All @@ -521,7 +528,8 @@ local function addSmeltJobs(ret,use_fuel)
for idx,ore in pairs(ores) do
print("adding:",ore.material.state_name.Solid)
printall(ore)
local job={name="smelt "..ore.material.state_name.Solid,job_fields={job_type=df.job_type.SmeltOre,mat_type=df.builtin_mats.INORGANIC,mat_index=idx},items={
local job={ --as:workshop_job
name="smelt "..ore.material.state_name.Solid,job_fields={job_type=df.job_type.SmeltOre,mat_type=df.builtin_mats.INORGANIC,mat_index=idx},items={
{item_type=df.item_type.BOULDER,mat_type=df.builtin_mats.INORGANIC,mat_index=idx,vector_id=df.job_item_vector_id.BOULDER}}}
if use_fuel then
table.insert(job.items,fuel)
Expand All @@ -531,8 +539,7 @@ local function addSmeltJobs(ret,use_fuel)
return ret
end
function getJobs(buildingId,workshopId,customId)
local ret={}
local c_jobs
local c_jobs = {} --as:workshop_job[]
if buildingId==df.building_type.Workshop then
c_jobs=jobs_workshop[workshopId]
elseif buildingId==df.building_type.Furnace then
Expand All @@ -551,10 +558,11 @@ function getJobs(buildingId,workshopId,customId)
c_jobs=utils.clone(c_jobs,true)
end

local ret = {} --as:c_jobs
addReactionJobs(c_jobs,buildingId,workshopId,customId)
for jobId,contents in pairs(c_jobs) do
if jobId~="defaults" then
local entry={}
local entry={} --as:workshop_job
entry.name=contents.name
local lclDefaults=utils.clone(input_filter_defaults,true)
if c_jobs.defaults ~=nil then
Expand Down
Loading