fix: resolve selene lint warnings and errors

Problem: unused variables (undo_state, sha_result, date match
captures) and duplicate if/else branches in gcal sync triggered
selene warnings and errors.

Solution: prefix unused state with underscore, simplify date
validation to a single pattern match, remove dead sha_result
call, and merge duplicate event deletion branches into a single
condition.
This commit is contained in:
Barrett Ruth 2026-02-24 15:20:06 -05:00
parent edd16f6ecf
commit b00a4f01d4
3 changed files with 12 additions and 19 deletions

View file

@ -7,7 +7,7 @@ local store = require('todo.store')
local M = {} local M = {}
---@type todo.Task[]? ---@type todo.Task[]?
local undo_state = nil local _undo_state = nil
---@return integer bufnr ---@return integer bufnr
function M.open() function M.open()
@ -46,7 +46,7 @@ end
---@param bufnr integer ---@param bufnr integer
function M._on_write(bufnr) function M._on_write(bufnr)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
undo_state = store.active_tasks() _undo_state = store.active_tasks()
diff.apply(lines) diff.apply(lines)
buffer.render(bufnr) buffer.render(bufnr)
end end
@ -113,8 +113,7 @@ function M.prompt_date()
end end
local due = input ~= '' and input or nil local due = input ~= '' and input or nil
if due then if due then
local y, m, d = due:match('^(%d%d%d%d)-(%d%d)-(%d%d)$') if not due:match('^%d%d%d%d%-%d%d%-%d%d$') then
if not y then
vim.notify('Invalid date format. Use YYYY-MM-DD.', vim.log.levels.ERROR) vim.notify('Invalid date format. Use YYYY-MM-DD.', vim.log.levels.ERROR)
return return
end end

View file

@ -199,7 +199,6 @@ function M.authorize()
end end
local code_verifier = table.concat(verifier) local code_verifier = table.concat(verifier)
local sha_result = vim.system({ 'printf', '%s', code_verifier }, { text = true }):wait()
local sha_pipe = vim local sha_pipe = vim
.system({ .system({
'sh', 'sh',
@ -401,7 +400,14 @@ function M.sync()
local extra = task._extra or {} local extra = task._extra or {}
local event_id = extra._gcal_event_id local event_id = extra._gcal_event_id
if (task.status == 'done' or task.status == 'deleted') and event_id then local should_delete = event_id
and (
task.status == 'done'
or task.status == 'deleted'
or (task.status == 'pending' and not task.due)
)
if should_delete then
local del_err = delete_event(access_token, calendar_id, event_id) local del_err = delete_event(access_token, calendar_id, event_id)
if not del_err then if not del_err then
extra._gcal_event_id = nil extra._gcal_event_id = nil
@ -430,18 +436,6 @@ function M.sync()
created = created + 1 created = created + 1
end end
end end
elseif task.status == 'pending' and not task.due and event_id then
local del_err = delete_event(access_token, calendar_id, event_id)
if not del_err then
extra._gcal_event_id = nil
if next(extra) == nil then
task._extra = nil
else
task._extra = extra
end
task.modified = os.date('!%Y-%m-%dT%H:%M:%SZ')
deleted = deleted + 1
end
end end
end end

View file

@ -103,7 +103,7 @@ describe('parse', function()
end) end)
it('ignores lowercase prefix', function() it('ignores lowercase prefix', function()
local desc, meta = parse.command_add('hello: world') local desc, _ = parse.command_add('hello: world')
assert.are.equal('hello: world', desc) assert.are.equal('hello: world', desc)
end) end)