Skip to content

Commit 43a5662

Browse files
committed
add annotations for luacheck
1 parent 9b613bd commit 43a5662

18 files changed

Lines changed: 47 additions & 34 deletions

assign-attributes.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local valid_args = utils.invert({
7979

8080

8181
-- ----------------------------------------------- UTILITY FUNCTIONS ------------------------------------------------ --
82-
local function print_yellow(text)
82+
function print_yellow(text)
8383
dfhack.color(COLOR_YELLOW)
8484
print(text)
8585
dfhack.color(-1)
@@ -146,7 +146,7 @@ function assign(attributes, unit, reset)
146146
reset = reset or false
147147

148148
if type(unit) == "number" then
149-
unit = df.unit.find(tonumber(unit))
149+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
150150
else
151151
unit = unit or dfhack.gui.getSelectedUnit(true)
152152
end

assign-beliefs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function assign(beliefs, unit, reset)
100100
reset = reset or false
101101

102102
if type(unit) == "number" then
103-
unit = df.unit.find(tonumber(unit))
103+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
104104
end
105105
unit = unit or dfhack.gui.getSelectedUnit(true)
106106
if not unit then

assign-facets.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function assign(facets, unit, reset)
9898
reset = reset or false
9999

100100
if type(unit) == "number" then
101-
unit = df.unit.find(tonumber(unit))
101+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
102102
end
103103
unit = unit or dfhack.gui.getSelectedUnit(true)
104104
if not unit then

assign-goals.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function assign(goals, unit, reset)
8181
reset = reset or false
8282

8383
if type(unit) == "number" then
84-
unit = df.unit.find(tonumber(unit))
84+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
8585
end
8686
unit = unit or dfhack.gui.getSelectedUnit(true)
8787
if not unit then

assign-preferences.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ local preference_functions = {
219219
-- ---------------- LIKEMATERIAL ---------------- --
220220
LIKEMATERIAL = function(token)
221221
local mat_info = dfhack.matinfo.find(token)
222+
local ret = {}
222223
if mat_info then
223-
return {
224+
ret = { --luacheck:retype
224225
type = df.unit_preference.T_type.LikeMaterial,
225226
item_type = -1,
226227
creature_id = -1,
@@ -239,8 +240,8 @@ local preference_functions = {
239240
}
240241
else
241242
print_yellow("WARNING: '" .. token .. "' does not seem to be a valid material token. Skipping...")
242-
return {}
243243
end
244+
return ret
244245
end,
245246
-- ---------------- LIKECREATURE ---------------- --
246247
LIKECREATURE = function(token)
@@ -572,11 +573,11 @@ function assign(preferences, unit, reset)
572573
assert(not unit or type(unit) == "number" or type(unit) == "userdata")
573574
assert(not reset or type(reset) == "boolean")
574575

575-
preferences = preferences or {}
576+
local preferences = preferences or {} --as:string[][]
576577
reset = reset or false
577578

578579
if type(unit) == "number" then
579-
unit = df.unit.find(tonumber(unit))
580+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
580581
end
581582
unit = unit or dfhack.gui.getSelectedUnit(true)
582583
if not unit then
@@ -594,8 +595,8 @@ function assign(preferences, unit, reset)
594595
for preference_type, preference_tokens in pairs(preferences) do
595596
assert(type(preference_tokens) == "table" or type(preference_tokens) == "string")
596597
local funct = preference_functions[preference_type:upper()]
597-
if type(preference_tokens) == "string" then
598-
preference_tokens = {preference_tokens} --retype string as table with only one item
598+
if type(preference_tokens) == "string" then --luacheck:skip
599+
preference_tokens = {preference_tokens}
599600
end
600601
for _, token in ipairs(preference_tokens) do
601602
assert(type(token) == "string")

assign-profile.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ end
107107
--- See the modules documentation for more details.
108108
--- :unit: a valid unit id, a df.unit object, or nil. If nil, the currently selected unit will be targeted.
109109
--- :reset: nil, or a table value/boolean. See this script documentation for valid values.
110+
--luacheck: in=string[],df.unit,bool[]
110111
function apply_profile(profile, unit, reset_table)
111112
assert(not profile or type(profile) == "table")
112113
assert(not unit or type(unit) == "number" or type(unit) == "userdata")
@@ -132,11 +133,12 @@ end
132133
--- The filename must begin with a slash and must be a relative path starting from the root DF
133134
--- directory and ending at the desired file.
134135
--- Return the parsed profile as a table.
136+
--luacheck: in=string,string
135137
function load_profile(profile_name, filename)
136138
assert(profile_name ~= nil)
137139

138140
local json_file = string.format("%s%s", dfhack.getDFPath(), filename or default_filename)
139-
local profiles
141+
local profiles = {} --as:string[][]
140142
if dfhack.filesystem.isfile(json_file) then
141143
profiles = json.decode_file(json_file)
142144
else

assign-skills.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function assign(skills, unit, reset)
9696
reset = reset or false
9797

9898
if type(unit) == "number" then
99-
unit = df.unit.find(tonumber(unit))
99+
unit = df.unit.find(tonumber(unit)) --luacheck:retype
100100
end
101101
unit = unit or dfhack.gui.getSelectedUnit(true)
102102
if not unit then

combat-harden.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function main(...)
7979
value = tonumber(args.value) or 100
8080
end
8181

82-
local unitsList = {}
82+
local unitsList = {} --as:df.unit[]
8383

8484
if not args.all and not args.citizens then
8585
-- Assume trying to target a unit

deep-embark.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function getFeatureID(cavernType)
8989
end
9090

9191
function getFeatureBlocks(featureID)
92-
local featureBlocks = {}
92+
local featureBlocks = {} --as:number[]
9393
for i,block in ipairs(df.global.world.map.map_blocks) do
9494
if block.global_feature == featureID and block.local_feature == -1 then
9595
table.insert(featureBlocks, i)
@@ -122,7 +122,7 @@ function isValidTiletype(tiletype)
122122
end
123123

124124
function getValidEmbarkTiles(block)
125-
local validTiles = {}
125+
local validTiles = {} --as:{_type:table,x:number,y:number,z:number}[]
126126
for xi = 0,15 do
127127
for yi = 0,15 do
128128
if block.designation[xi][yi].flow_size == 0
@@ -230,7 +230,7 @@ function moveEmbarkStuff(selectedBlock, embarkTiles)
230230

231231
-- Move wagon contents:
232232
local wagonFound = false
233-
for _, wagon in ipairs(df.global.world.buildings.other.WAGON) do
233+
for _, wagon in ipairs(df.global.world.buildings.other.WAGON) do --as:df.building_wagonst
234234
if wagon.age == 0 then -- just in case there's an older wagon present for some reason
235235
local contained = wagon.contained_items
236236
for i = #contained-1, 0, -1 do

dorf_tables.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ print("Loading data tables..")
2121

2222
-- p denotes probability, always.
2323
local O = 0
24+
--luacheck:global
2425
job_distributions = {
2526
Thresholds = { 7, 14, 21, 28, 30, 35, 42, 49, 56, 63, 70, 77, 80, 110, 1000 }, --Don't touch unless you wanna recalculate the distributions,
2627
_Grunt = { O, 1, 2, O, O, 1, 2, O, 4, 1, 1, 4, O, 10, 880; cur = 0; max = nil },
@@ -74,6 +75,7 @@ Stat Rolling:
7475

7576

7677
--probability is used for generating all dwarf stats, some jobs include dorf_types which will upgrade particular stats
78+
--luacheck:global
7779
attrib_levels = { -- prob, avg, std deviation
7880
incompetent = {p=0.01, 100, 20},
7981
verybad = {p=0.02, 250, 25},
@@ -98,6 +100,7 @@ dorf_jobs = {
98100
and also the probability that the profession will be applied during the algorithm's execution.
99101
}
100102
--]]
103+
--luacheck:global
101104
jobs = {
102105
_Grunt = {
103106
req={'RECRUIT'}, max={1988},
@@ -183,6 +186,7 @@ jobs = {
183186
types={'genius3','intuitive2','leader'}}
184187
}
185188

189+
--luacheck:global
186190
professions = {
187191
--Basic Dwarfing
188192
MINER = { skills = {MINING=3} },
@@ -288,6 +292,7 @@ professions = {
288292
}
289293

290294
--probability is used for randomly applying types to any and all dwarves
295+
--luacheck:global
291296
types = {
292297
resilient1 = {
293298
p = 0.2,

0 commit comments

Comments
 (0)