fix: resolve remaining LuaLS type errors

Problem: CI lua-typecheck-action reported three categories of errors:
1. parse.lua - multi-assignment of tonumber() results left y/m/d typed
   as number? rather than integer, failing os.time()'s field types
2. gcal.lua - url_encode returned str:gsub() which yields string+integer
   but the annotation declared @return string (redundant-return-value)
3. gcal.lua - calendar_id typed string? from find_or_create_calendar was
   passed to functions expecting string; the existing `if err` guard did
   not narrow the type for LuaLS

Solution: replace the y/m/d multi-assignment with yn/mn/dn locals whose
types resolve cleanly to integer; wrap the gsub return in parentheses to
discard the count; add `or not calendar_id` to the error guard so LuaLS
narrows calendar_id to string for the rest of the scope.
This commit is contained in:
Barrett Ruth 2026-02-24 18:49:18 -05:00 committed by Barrett Ruth
parent 87eedc8610
commit 2b73ab1cd0
2 changed files with 14 additions and 13 deletions

View file

@ -10,19 +10,18 @@ local function is_valid_date(s)
if not y then
return false
end
y, m, d =
tonumber(y), --[[@as integer]]
tonumber(m), --[[@as integer]]
tonumber(d) --[[@as integer]]
if m < 1 or m > 12 then
local yn = tonumber(y) --[[@as integer]]
local mn = tonumber(m) --[[@as integer]]
local dn = tonumber(d) --[[@as integer]]
if mn < 1 or mn > 12 then
return false
end
if d < 1 or d > 31 then
if dn < 1 or dn > 31 then
return false
end
local t = os.time({ year = y, month = m, day = d })
local t = os.time({ year = yn, month = mn, day = dn })
local check = os.date('*t', t) --[[@as osdate]]
return check.year == y and check.month == m and check.day == d
return check.year == yn and check.month == mn and check.day == dn
end
---@return string