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:
parent
87eedc8610
commit
2b73ab1cd0
2 changed files with 14 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -99,9 +99,11 @@ end
|
|||
---@param str string
|
||||
---@return string
|
||||
local function url_encode(str)
|
||||
return str:gsub('([^%w%-%.%_%~])', function(c)
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue