Skip to content

Commit

Permalink
Merge pull request #2152 from tobylane/luacheckinline
Browse files Browse the repository at this point in the history
[RDY] Luacheck inlining
  • Loading branch information
TheCycoONE committed Jul 3, 2022
2 parents 073ec51 + 0503905 commit 7a8ca36
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 119 deletions.
69 changes: 1 addition & 68 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -138,96 +138,29 @@ add_ignore("CorsixTH/Lua/rooms/operating_theatre.lua", "wait_for_ready")
-- W111: setting non-standard global variable XYZ
-- W113: accessing undefined variable XYZ
-- W121: setting read-only global variable XYZ
-- W122: mutating read-only global variable XYZ
-- W211: unused variable XYZ
-- W212: unused argument XYZ
-- W231: variable XYZ is never accessed
-- W542: empty if branch
add_ignore("CorsixTH/CorsixTH.lua", "121")
add_ignore("CorsixTH/Lua/app.lua", "122")
add_ignore("CorsixTH/Lua/app.lua", "212")
add_ignore("CorsixTH/Lua/calls_dispatcher.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/confirm_dialog.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/edit_room.lua", "113") -- accessing hasBit and bitOr utility.lua functions
add_ignore("CorsixTH/Lua/dialogs/edit_room.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/edit_room.lua", "542")
add_ignore("CorsixTH/Lua/dialogs/fullscreen.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/fullscreen/bank_manager.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/fullscreen/graphs.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/fullscreen/hospital_policy.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/fullscreen/research_policy.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/fullscreen/staff_management.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/furnish_corridor.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/grim_reaper.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/hire_staff.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/information.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/jukebox.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/menu.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/message.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/place_objects.lua", "542")
add_ignore("CorsixTH/Lua/dialogs/queue_dialog.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/resizables/customise.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/resizables/directory_browser.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/resizables/dropdown.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/resizables/lua_console.lua", "111")
add_ignore("CorsixTH/Lua/dialogs/resizables/main_menu.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/resizables/map_editor.lua", "542")
add_ignore("CorsixTH/Lua/dialogs/resizables/options.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/staff_rise.lua", "212")
add_ignore("CorsixTH/Lua/dialogs/staff_rise.lua", "542")
add_ignore("CorsixTH/Lua/entities/machine.lua", "212")
add_ignore("CorsixTH/Lua/entities/humanoids/grim_reaper.lua", "212")
add_ignore("CorsixTH/Lua/entities/humanoids/patient.lua", "212")
add_ignore("CorsixTH/Lua/entities/humanoids/patient.lua", "542")
add_ignore("CorsixTH/Lua/filesystem.lua", "212")
add_ignore("CorsixTH/Lua/graphics.lua", "542")
add_ignore("CorsixTH/Lua/humanoid_action.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/idle.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/multi_use_object.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/pickup.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_reception.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_reception.lua", "542")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_room.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/staff_reception.lua", "113") -- ReceptionDesk does exist
add_ignore("CorsixTH/Lua/humanoid_actions/use_object.lua", "542")
add_ignore("CorsixTH/Lua/humanoid_actions/vaccinate.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/vip_go_to_next_room.lua", "212")
add_ignore("CorsixTH/Lua/map.lua", "212")
add_ignore("CorsixTH/Lua/map.lua", "542")
add_ignore("CorsixTH/Lua/movie_player.lua", "542")
add_ignore("CorsixTH/Lua/objects/analyser.lua", "212")
add_ignore("CorsixTH/Lua/objects/door.lua", "212")
add_ignore("CorsixTH/Lua/objects/litter.lua", "212")
add_ignore("CorsixTH/Lua/objects/machines/operating_table.lua", "542")
add_ignore("CorsixTH/Lua/persistance.lua", "231") -- th_getupvalue assignments in lua5.2/5.3 code
add_ignore("CorsixTH/Lua/research_department.lua", "212")
add_ignore("CorsixTH/Lua/room.lua", "212")
add_ignore("CorsixTH/Lua/rooms/cardiogram.lua", "212")
add_ignore("CorsixTH/Lua/rooms/general_diag.lua", "212")
add_ignore("CorsixTH/Lua/rooms/psych.lua", "212")
add_ignore("CorsixTH/Lua/rooms/research.lua", "212")
add_ignore("CorsixTH/Lua/rooms/scanner_room.lua", "212")
add_ignore("CorsixTH/Lua/rooms/staff_room.lua", "212")
add_ignore("CorsixTH/Lua/rooms/staff_room.lua", "542")
add_ignore("CorsixTH/Lua/rooms/ward.lua", "111")
add_ignore("CorsixTH/Lua/rooms/ward.lua", "113")
add_ignore("CorsixTH/Lua/rooms/ward.lua", "211")
add_ignore("CorsixTH/Lua/rooms/ward.lua", "212")
add_ignore("CorsixTH/Lua/sprite_viewer.lua", "212")
add_ignore("CorsixTH/Lua/strict.lua", "212")
add_ignore("CorsixTH/Lua/strings.lua", "212")
add_ignore("CorsixTH/Lua/strings.lua", "122")
add_ignore("CorsixTH/Lua/ui.lua", "111") -- _ is set in debug code
add_ignore("CorsixTH/Lua/ui.lua", "212")
add_ignore("CorsixTH/Lua/utility.lua", "111") -- defining hasBit and bitOr
add_ignore("CorsixTH/Lua/utility.lua", "121")
add_ignore("CorsixTH/Lua/window.lua", "212")
add_ignore("CorsixTH/Lua/window.lua", "542")
add_ignore("CorsixTH/Lua/world.lua", "111")
add_ignore("CorsixTH/Lua/world.lua", "112")
add_ignore("CorsixTH/Lua/world.lua", "212")
add_ignore("CorsixTH/Lua/world.lua", "542")
add_ignore("CorsixTH/Luatest/non_strict.lua", "212")
add_ignore("CorsixTH/Luatest/spec/utility_spec.lua", "121")
add_ignore("CorsixTH/CorsixTH.lua", "143") -- luacheck is missing 5.4 debug functions
12 changes: 6 additions & 6 deletions CorsixTH/CorsixTH.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ end

-- Set a large enough cstacklimit to load complex saves in stack based
-- versions of lua, such as 5.4.[01]
if debug.setcstacklimit then
debug.setcstacklimit(30000)
if debug.setcstacklimit then -- luacheck: ignore 143 luacheck is missing 5.4 debug functions
debug.setcstacklimit(30000) -- luacheck: ignore 143
end

-- Parse script parameters:
Expand Down Expand Up @@ -90,7 +90,7 @@ end
if _VERSION ~= "Lua 5.1" then
if _VERSION == "Lua 5.2" or _VERSION == "Lua 5.3" or _VERSION == "Lua 5.4" then
-- Compatibility: Keep the global unpack function
unpack = table.unpack
unpack = table.unpack -- luacheck: ignore 121
-- Compatibility: Provide a replacement for deprecated ipairs()
-- NB: It might be wiser to migrate away from ipairs entirely, but the
-- following works as an immediate band-aid
Expand All @@ -103,7 +103,7 @@ if _VERSION ~= "Lua 5.1" then
return i, v
end
end
function ipairs(t)
function ipairs(t) -- luacheck: ignore 121
if type(t) ~= "table" then
error("table expected, got " .. type(t))
end
Expand All @@ -120,8 +120,8 @@ end

-- Enable strict mode
corsixth.require("strict")
require = destrict(require)
dofile = destrict(dofile)
require = destrict(require) -- luacheck: ignore 121
dofile = destrict(dofile) -- luacheck: ignore 121

-- Load the class system (required for App)
corsixth.require("class")
Expand Down
9 changes: 4 additions & 5 deletions CorsixTH/Lua/dialogs/edit_room.lua
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ function UIEditRoom:screenToWall(x, y)
local rect = self.blueprint_rect
if cellx == rect.x or cellx == rect.x - 1 or cellx == rect.x + rect.w or cellx == rect.x + rect.w - 1 or
celly == rect.y or celly == rect.y - 1 or celly == rect.y + rect.h or celly == rect.y + rect.h - 1 then
celly == rect.y or celly == rect.y - 1 or celly == rect.y + rect.h or
celly == rect.y + rect.h - 1 then -- luacheck: ignore 542
else
return
end
Expand Down Expand Up @@ -1007,17 +1008,15 @@ function UIEditRoom:onMouseDown(button, x, y)
if self.world.user_actions_allowed and not self.confirm_dialog_open then
if button == "left" then
if self.phase == "walls" then
if 0 <= x and x < self.width and 0 <= y and y < self.height then
if 0 <= x and x < self.width and 0 <= y and y < self.height then -- luacheck: ignore 542
else
local mouse_x, mouse_y = self.ui:ScreenToWorld(self.x + x, self.y + y)
self.mouse_down_x = math.floor(mouse_x)
self.mouse_down_y = math.floor(mouse_y)
if self.move_rect then
self.move_rect_x = self.mouse_down_x - self.blueprint_rect.x
self.move_rect_y = self.mouse_down_y - self.blueprint_rect.y
elseif self.resize_rect then
-- nothing to do
else
elseif not self.resize_rect then
self:setBlueprintRect(self.mouse_down_x, self.mouse_down_y, 1, 1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion CorsixTH/Lua/dialogs/place_objects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function UIPlaceObjects:onMouseUp(button, x, y)
repaint = true
elseif button == "left" then
if #self.objects > 0 then
if 0 <= x and x < self.width and 0 <= y and y < self.height then
if 0 <= x and x < self.width and 0 <= y and y < self.height then -- luacheck: ignore 542
-- Click within window - do nothing
elseif self.object_cell_x and self.object_cell_y and self.object_blueprint_good then
self:placeObject()
Expand Down
8 changes: 3 additions & 5 deletions CorsixTH/Lua/dialogs/resizables/map_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ end
--!return (array of {xpos, ypos} tables) Coordinates to draw the selected sprite.
function UIMapEditor:getDrawPoints()
if self.cursor.state == "disabled" then
-- Nothing to compute, drop to bottom {} return.
return {} -- Nothing to compute
elseif self.cursor.state == "grid" then
local bx, by = self:areaOnWorld(self.cursor.xpos, self.cursor.ypos,
Expand Down Expand Up @@ -1109,9 +1109,6 @@ function UIMapEditor:onMouseDown(button, xpos, ypos)
repaint = true
end
elseif self.cursor.state == "right" then
-- Ignore all down buttons, until RMB is released.
elseif self.cursor.state == "paste" then
if button == "left" then
self.cursor.state = "paste-left"
Expand All @@ -1124,6 +1121,7 @@ function UIMapEditor:onMouseDown(button, xpos, ypos)
end
-- "both", "delete-left", "parcel-left", "paste-left" do not handle buttons.
-- Ignore all down buttons, until RMB is released.
end
Expand Down Expand Up @@ -1471,7 +1469,7 @@ function UIMapEditor:onMouseUp(button, x, y)
local repaint = false
if self.cursor.state == "disabled" then
-- Don't care about buttons.
return repaint -- Don't care about buttons
elseif self.cursor.state == "left" then
if button == "left" then
Expand Down
5 changes: 2 additions & 3 deletions CorsixTH/Lua/dialogs/staff_rise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ function UIStaffRise:drawDoctorAttributes(canvas)
-- Junior / Doctor / Consultant marker
local marker_x = x + 98
if profile.is_junior then
elseif profile.is_consultant then
if profile.is_consultant then
marker_x = marker_x + 52
else
elseif not profile.is_junior then
marker_x = marker_x + 22
end
Expand Down
3 changes: 1 addition & 2 deletions CorsixTH/Lua/entities/humanoids/patient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,7 @@ function Patient:updateMessage(choice)
-- no requirements missing
enabled = false
end
else -- if choice == "guess_cure" then
-- TODO: implement
-- TODO: implement choice == "guess_cure"
end

for _, c in ipairs(self.message.choices) do
Expand Down
2 changes: 1 addition & 1 deletion CorsixTH/Lua/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function Graphics:loadFont(sprite_table, x_sep, y_sep, ...)
local use_bitmap_font = true
-- Force bitmap font for the moneybar (Font05V)
if not sprite_table:isVisible(46) or load_font == "Font05V" then -- uppercase M
if not sprite_table:isVisible(46) or load_font == "Font05V" then -- luacheck: ignore 542
-- The font doesn't contain an uppercase M, so (in all likelihood) is used
-- for drawing special symbols rather than text, so the original bitmap
-- font should be used.
Expand Down
7 changes: 2 additions & 5 deletions CorsixTH/Lua/humanoid_actions/seek_reception.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ local function action_seek_reception_start(action, humanoid)
-- Go through all receptions desks.
for _, desk in ipairs(humanoid.hospital:findReceptionDesks()) do
if (not desk.receptionist and not desk.reserved_for) then
-- Not an allowed reception desk to go to.
else
-- Ok, so we found one.
if desk.receptionist or desk.reserved_for then
-- Ok, so we found one with staff at it or on the way.
-- Is this one better than the last one?
-- A lower score is better.
-- First find out where the usage tile is.
Expand Down
2 changes: 1 addition & 1 deletion CorsixTH/Lua/humanoid_actions/staff_reception.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local StaffReceptionAction = _G["StaffReceptionAction"]
-- Action class for the "staff reception desk" action.
--!param desk (object) Desk to staff.
function StaffReceptionAction:StaffReceptionAction(desk)
assert(class.is(desk, ReceptionDesk), "Invalid value for parameter 'desk'")
assert(class.is(desk, ReceptionDesk), "Invalid value for parameter 'desk'") -- luacheck: ignore 113
self:HumanoidAction("staff_reception")
self.object = desk -- Reception desk object.
Expand Down
3 changes: 2 additions & 1 deletion CorsixTH/Lua/humanoid_actions/use_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ local function action_use_phase(action, humanoid, phase)
-- Even it out so that an integer number of animation sequences are done.
length = action.min_length + action.min_length % length
end
if phase == 0 and (not is_list) and length == 1 and action.prolonged_usage and
action.on_interrupt and not action.loop_callback then
action.on_interrupt and not action.loop_callback then -- luacheck: ignore 542
-- a timer would be redundant, so do not set one
else
humanoid:setTimer(length, action_use_object_tick)
Expand Down
2 changes: 1 addition & 1 deletion CorsixTH/Lua/map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ function Map:draw(canvas, sx, sy, sw, sh, dx, dy)
break
elseif screenY > -32 then
repeat
if screenX < -32 then
if screenX < -32 then -- luacheck: ignore 542
elseif screenX < sw + 32 then
local xy = y * self.width + x
local xpos = dx + screenX - 32
Expand Down
3 changes: 1 addition & 2 deletions CorsixTH/Lua/movie_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ function MoviePlayer:playAdvanceMovie(level)
if self.audio.background_music then
self.holding_bg_music = self.audio:pauseBackgroundTrack()
else
end
if level == 12 then
self.audio:playSound("DICE122M.WAV")
else
Expand Down
5 changes: 2 additions & 3 deletions CorsixTH/Lua/objects/machines/operating_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ local OperatingTable = _G["OperatingTable"]
OperatingTable:slaveMixinClass()
function OperatingTable:machineUsed(...)
if self.master then
-- Is slave. Do nothing.
else
-- Only if the table is the primary/master of the pair
if not self.master then
return Machine.machineUsed(self, ...)
end
end
Expand Down
2 changes: 1 addition & 1 deletion CorsixTH/Lua/persistance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ strict_declare_global "permanent"
strict_declare_global "unpermanent"
local th_getfenv
local th_getupvalue
local th_getupvalue -- luacheck: ignore 231
if _G._VERSION == "Lua 5.2" or _G._VERSION == "Lua 5.3" or _G._VERSION == "Lua 5.4" then
th_getfenv = function(f)
local _, val = nil, nil
Expand Down
3 changes: 1 addition & 2 deletions CorsixTH/Lua/rooms/staff_room.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ function StaffRoom:onHumanoidEnter(humanoid)
self.humanoids[humanoid] = true
self:tryAdvanceQueue()
humanoid:setDynamicInfoText("")
-- Other humanoids shouldn't be entering, so don't worry about them
if class.is(humanoid, Staff) then
-- Receptionists cannot enter, so we do not have to worry about them
-- If it is a handyman and he is here to do a job, let him pass
if not humanoid.on_call then
humanoid:setNextAction(UseStaffRoomAction())
self.door.queue.visitor_count = self.door.queue.visitor_count + 1
end
else
-- Other humanoids shouldn't be entering, so don't worry about them
end
end
Expand Down
4 changes: 2 additions & 2 deletions CorsixTH/Lua/rooms/ward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ function WardRoom:commandEnteringPatient(patient)
bed.reserved_for = patient
-- Old callback kept for persistence in savegame version 155, April 2021
local --[[persistable:ward_loop_callback]] function _(action)
if length <= 0 then
if length <= 0 then -- luacheck: ignore 113
action.prolonged_usage = false
end
length = length - 1
length = length - 1 -- luacheck: ignore 111 113
end
-- New callback
local --[[persistable:ward_loop_callback2]] function loop_callback(action)
Expand Down
4 changes: 2 additions & 2 deletions CorsixTH/Lua/strings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,11 @@ case(0xA4, 0xA5) -- n-tilde
local case_pattern = "\195[\128-\191]" -- Unicode range [0xC0, 0xFF] as UTF-8
local orig_upper = string.upper
function string.upper(s)
function string.upper(s) -- luacheck: ignore 122
return orig_upper(s:gsub(case_pattern, lower_to_upper))
end
local orig_lower = string.lower
function string.lower(s)
function string.lower(s) -- luacheck: ignore 122
return orig_lower(s:gsub(case_pattern, upper_to_lower))
end
1 change: 1 addition & 0 deletions CorsixTH/Lua/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function UI:UI(app, minimal)
end
function UI:runDebugScript()
-- luacheck: ignore 111 _ is set in debug code
print("Executing Debug Script...")
local path_sep = package.config:sub(1, 1)
local lua_dir = debug.getinfo(1, "S").source:sub(2, -8)
Expand Down
4 changes: 2 additions & 2 deletions CorsixTH/Lua/utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ do
if not metamethod_called then
local next = next
local getmetatable = getmetatable
pairs = function(t)
pairs = function(t) -- luacheck: ignore 121
local mt = getmetatable(t)
if mt then
local __pairs = mt.__pairs
Expand All @@ -161,7 +161,7 @@ do
ipairs(setmetatable({}, {__ipairs = function() metamethod_called = true end}))
if not metamethod_called then
local ipairs_orig = ipairs
ipairs = function(t)
ipairs = function(t) -- luacheck: ignore 121
local mt = getmetatable(t)
if mt then
local __ipairs = mt.__ipairs
Expand Down
3 changes: 0 additions & 3 deletions CorsixTH/Lua/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,6 @@ top-left corner of the window.
top-left corner of the window.
]]
function Window:hitTest(x, y)
if x < 0 or y < 0 or (self.width and x >= self.width) or (self.height and y >= self.height) then
-- return false
end
if self.panels[1] then
for _, panel in ipairs(self.panels) do
if self:hitTestPanel(x, y, panel) then
Expand Down

0 comments on commit 7a8ca36

Please sign in to comment.