Enable stricter type checks

This commit is contained in:
Cooldude2606
2024-11-21 00:03:19 +00:00
parent 51c9356ecc
commit 99ab54da0a
11 changed files with 67 additions and 37 deletions

View File

@@ -1,14 +1,22 @@
{ {
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"completion.requireSeparator": "/", "completion.requireSeparator": "/",
"doc.regengine": "glob",
"doc.privateName": [ "__*" ],
"doc.packageName": [ "_*" ],
"runtime.pluginArgs": [ "runtime.pluginArgs": [
"--clusterio-modules" "--clusterio-modules"
], ],
"diagnostics.unusedLocalExclude": [ "_*", "i", "j", "k", "v" ], "doc": {
"diagnostics.groupFileStatus": { "regengine": "glob",
"privateName": [ "__*" ],
"packageName": [ "_*" ]
},
"type": {
"checkTableShape": true,
"inferParamType": true
},
"$comment-name-style-check": "Disabled below until config issue fixed: https://github.com/LuaLS/lua-language-server/issues/2643",
"diagnostics": {
"unusedLocalExclude": [ "_*", "i", "j", "k", "v" ],
"groupFileStatus": {
"ambiguity": "Any", "ambiguity": "Any",
"await": "None", "await": "None",
"codestyle": "Opened", "codestyle": "Opened",
@@ -23,11 +31,11 @@
"unbalanced": "Opened", "unbalanced": "Opened",
"unused": "Opened" "unused": "Opened"
}, },
"$comment-name-style-check": "Disabled below until config issue fixed: https://github.com/LuaLS/lua-language-server/issues/2643", "neededFileStatus": {
"diagnostics.neededFileStatus": {
"no-unknown": "None!", "no-unknown": "None!",
"spell-check": "None!", "spell-check": "None!",
"name-style-check": "None!" "name-style-check": "None!"
}
}, },
"nameStyle.config": { "nameStyle.config": {
"local_name_style": [{ "local_name_style": [{

View File

@@ -125,7 +125,6 @@ Commands._metatable = {
__class = "ExpCommand", __class = "ExpCommand",
} }
--- @type LuaPlayer
Commands.server = setmetatable({ Commands.server = setmetatable({
index = 0, index = 0,
color = ExpUtil.color.white, color = ExpUtil.color.white,
@@ -154,7 +153,7 @@ Commands.server = setmetatable({
Commands.error("Command does not support rcon usage, requires LuaPlayer." .. key) Commands.error("Command does not support rcon usage, requires LuaPlayer." .. key)
error("Command does not support rcon usage, requires LuaPlayer." .. key) error("Command does not support rcon usage, requires LuaPlayer." .. key)
end, end,
}) }) --[[ @as LuaPlayer ]]
--- Status Returns. --- Status Returns.
-- Return values used by command callbacks -- Return values used by command callbacks

View File

@@ -6,12 +6,13 @@ local json_to_table = helpers.json_to_table
--- Top level module table, contains event handlers and public methods --- Top level module table, contains event handlers and public methods
local Groups = {} local Groups = {}
--- @class ExpGroup --- @class ExpGroup : LuaPermissionGroup
--- @field group LuaPermissionGroup The permission group for this group proxy --- @field group LuaPermissionGroup The permission group for this group proxy
Groups._prototype = {} Groups._prototype = {}
Groups._metatable = { Groups._metatable = {
__index = setmetatable(Groups._prototype, { __index = setmetatable(Groups._prototype, {
--- @type any Annotation required because otherwise it is typed as 'table'
__index = function(self, key) __index = function(self, key)
return self.group[key] return self.group[key]
end, end,

View File

@@ -42,7 +42,7 @@ end
local function emit_event(args) local function emit_event(args)
local title = args.title or "" local title = args.title or ""
local color = args.color or "0x0" local color = args.color or "0x0" --- @type string | Color
local description = args.description or "" local description = args.description or ""
if type(color) == "table" then if type(color) == "table" then

View File

@@ -14,6 +14,7 @@ end
-- Will degrade a tile down to the next tile when called -- Will degrade a tile down to the next tile when called
local function degrade(surface, position) local function degrade(surface, position)
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local tile = surface.get_tile(position) local tile = surface.get_tile(position)
local tile_name = tile.name local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name] local degrade_tile_name = config.degrade_order[tile_name]
@@ -55,6 +56,7 @@ end
-- Gets the mean of the strengths around a tile to give the strength at that position -- Gets the mean of the strengths around a tile to give the strength at that position
local function get_tile_strength(surface, position) local function get_tile_strength(surface, position)
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local tile = surface.get_tile(position) local tile = surface.get_tile(position)
local tile_name = tile.name local tile_name = tile.name
local strength = config.strengths[tile_name] local strength = config.strengths[tile_name]
@@ -62,7 +64,7 @@ local function get_tile_strength(surface, position)
for x = -1, 1 do -- x loop for x = -1, 1 do -- x loop
local px = position.x + x local px = position.x + x
for y = -1, 1 do -- y loop for y = -1, 1 do -- y loop
local check_tile = surface.get_tile{ x = px, y = position.y + y } local check_tile = surface.get_tile(px, position.y + y)
local check_tile_name = check_tile.name local check_tile_name = check_tile.name
local check_strength = config.strengths[check_tile_name] or 0 local check_strength = config.strengths[check_tile_name] or 0
strength = strength + check_strength strength = strength + check_strength

View File

@@ -144,9 +144,11 @@ local function spawn_area(surface, position)
local fr = config.spawn_area.landfill_radius local fr = config.spawn_area.landfill_radius
local fr2 = fr ^ 2 local fr2 = fr ^ 2
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local fill_tile = surface.get_tile(position).name local fill_tile = surface.get_tile(position).name
-- Make sure a non water tile is used for each tile -- Make sure a non water tile is used for each tile
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
if surface.get_tile(position).collides_with("player") then fill_tile = "landfill" end if surface.get_tile(position).collides_with("player") then fill_tile = "landfill" end
if decon_tile == nil then decon_tile = fill_tile end if decon_tile == nil then decon_tile = fill_tile end
@@ -160,6 +162,7 @@ local function spawn_area(surface, position)
if dst < tr2 then if dst < tr2 then
-- If it is inside the decon radius always set the tile -- If it is inside the decon radius always set the tile
table.insert(tiles_to_make, { name = decon_tile, position = pos }) table.insert(tiles_to_make, { name = decon_tile, position = pos })
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
elseif dst < fr2 and surface.get_tile(pos).collides_with("player") then elseif dst < fr2 and surface.get_tile(pos).collides_with("player") then
-- If it is inside the fill radius only set the tile if it is water -- If it is inside the fill radius only set the tile if it is water
table.insert(tiles_to_make, { name = fill_tile, position = pos }) table.insert(tiles_to_make, { name = fill_tile, position = pos })

View File

@@ -1,18 +1,21 @@
local Commands = require("modules/exp_commands") local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic
local function pl(type, target, amount) ---@param target LuaEntity | LuaPlayer
---@param amount number
local function pl(target, amount)
local c local c
local s local s
if type == "p" then --- @cast target any Remove cast once implemented
error("Needs updating to use 2.0 logistics")
if target.object_name == "LuaPlayer" then
c = target.clear_personal_logistic_slot c = target.clear_personal_logistic_slot
s = target.set_personal_logistic_slot s = target.set_personal_logistic_slot
elseif type == "s" then else
c = target.clear_vehicle_logistic_slot c = target.clear_vehicle_logistic_slot
s = target.set_vehicle_logistic_slot s = target.set_vehicle_logistic_slot
else
return
end end
for _, v in pairs(config.request) do for _, v in pairs(config.request) do
@@ -69,15 +72,16 @@ end
Commands.new("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)") Commands.new("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:argument("amount", "", Commands.types.integer_range(-1, 10)) :argument("amount", "", Commands.types.integer_range(-1, 10))
:add_aliases{ "pl" } :add_aliases{ "pl" }
:add_flags{ "disabled" } -- Remove once implemented above
:register(function(player, amount) :register(function(player, amount)
--- @cast amount number --- @cast amount number
if player.force.technologies["logistic-robotics"].researched then if player.force.technologies["logistic-robotics"].researched then
if player.selected ~= nil then if player.selected ~= nil then
if player.selected.name == "spidertron" then if player.selected.name == "spidertron" then
pl("s", player.selected, amount / 10) pl(player.selected, amount / 10)
end end
else else
pl("p", player, amount / 10) pl(player, amount / 10)
end end
else else
return Commands.status.error("Personal Logistic not researched") return Commands.status.error("Personal Logistic not researched")

View File

@@ -75,8 +75,14 @@ local function clear_module(player, area, machine)
local m_current_module_content = m_current_module.get_contents() local m_current_module_content = m_current_module.get_contents()
if m_current_module_content then if m_current_module_content then
for k, m in pairs(m_current_module_content) do for _, item in pairs(m_current_module_content) do
surface.spill_item_stack(entity.bounding_box.left_top, { name = k, count = m }, true, force, false) surface.spill_item_stack{
position = entity.bounding_box.left_top,
stack = item --[[ @as ItemStackDefinition https://forums.factorio.com/viewtopic.php?f=233&t=122323]],
enable_looted = true,
force = force,
allow_belts = false
}
end end
end end
@@ -90,7 +96,7 @@ local function apply_module(player, area, machine, modules)
for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do
local m_current_recipe local m_current_recipe
if entity.prototype.crafting_speed then if entity.prototype.get_crafting_speed() then
m_current_recipe = entity.get_recipe() m_current_recipe = entity.get_recipe()
end end

View File

@@ -193,6 +193,7 @@ local function update_science_pack(pack_table, science_pack_data)
pack_table.parent.non_made.visible = false pack_table.parent.non_made.visible = false
-- Update the icon -- Update the icon
--- @type LuaGuiElement
local pack_icon = pack_table["icon-" .. science_pack] or science_pack_base(pack_table, science_pack_data) local pack_icon = pack_table["icon-" .. science_pack] or science_pack_base(pack_table, science_pack_data)
local icon_style = science_pack_data.icon_style local icon_style = science_pack_data.icon_style
pack_icon.style = icon_style pack_icon.style = icon_style

View File

@@ -9,6 +9,10 @@ local tonumber = tonumber
local pairs = pairs local pairs = pairs
local table_size = table_size local table_size = table_size
--- @generic T: table
--- @type fun(table: T, metatable?: table|metatable): T
setmetatable = setmetatable
--- Adds all keys of the source table to destination table as a shallow copy --- Adds all keys of the source table to destination table as a shallow copy
--- @generic K, V --- @generic K, V
--- @param dst table<K, V> Table to insert into --- @param dst table<K, V> Table to insert into

View File

@@ -394,6 +394,8 @@ end
--- @field surface LuaSurface The surface to search for targets on --- @field surface LuaSurface The surface to search for targets on
--- @field allow_creation boolean? If new entities can be create to store the items --- @field allow_creation boolean? If new entities can be create to store the items
--- @field cache Common.get_or_create_storage_cache? Internal search cache passed between subsequent calls --- @field cache Common.get_or_create_storage_cache? Internal search cache passed between subsequent calls
--- @field name? EntityID Entity to be created if allow_creation is true
--- @field force? ForceID Force of the created entity, defaults to 'neutral'
--- Find, or optionally create, a storage entity which a stack can be inserted into --- Find, or optionally create, a storage entity which a stack can be inserted into
--- @param options Common.get_or_create_storage_param --- @param options Common.get_or_create_storage_param