From 2b73ab1cd0e5a61b5b68957c1f1772a65a02a319 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 24 Feb 2026 18:49:18 -0500 Subject: [PATCH] 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. --- lua/pending/parse.lua | 15 +++++++-------- lua/pending/sync/gcal.lua | 12 +++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lua/pending/parse.lua b/lua/pending/parse.lua index b72214f..ebe909a 100644 --- a/lua/pending/parse.lua +++ b/lua/pending/parse.lua @@ -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 diff --git a/lua/pending/sync/gcal.lua b/lua/pending/sync/gcal.lua index f3c84e2..6635575 100644 --- a/lua/pending/sync/gcal.lua +++ b/lua/pending/sync/gcal.lua @@ -99,9 +99,11 @@ end ---@param str string ---@return string local function url_encode(str) - return str:gsub('([^%w%-%.%_%~])', function(c) - return string.format('%%%02X', string.byte(c)) - end) + return ( + str:gsub('([^%w%-%.%_%~])', function(c) + return string.format('%%%02X', string.byte(c)) + end) + ) end ---@param method string @@ -449,8 +451,8 @@ function M.sync() end local calendar_id, err = find_or_create_calendar(access_token) - if err then - vim.notify('pending.nvim: ' .. err, vim.log.levels.ERROR) + if err or not calendar_id then + vim.notify('pending.nvim: ' .. (err or 'calendar not found'), vim.log.levels.ERROR) return end