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:
parent
6f7959cb18
commit
4f60433684
3 changed files with 12 additions and 19 deletions
|
|
@ -7,7 +7,7 @@ local store = require('todo.store')
|
|||
local M = {}
|
||||
|
||||
---@type todo.Task[]?
|
||||
local undo_state = nil
|
||||
local _undo_state = nil
|
||||
|
||||
---@return integer bufnr
|
||||
function M.open()
|
||||
|
|
@ -46,7 +46,7 @@ end
|
|||
---@param bufnr integer
|
||||
function M._on_write(bufnr)
|
||||
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)
|
||||
buffer.render(bufnr)
|
||||
end
|
||||
|
|
@ -113,8 +113,7 @@ function M.prompt_date()
|
|||
end
|
||||
local due = input ~= '' and input or nil
|
||||
if due then
|
||||
local y, m, d = due:match('^(%d%d%d%d)-(%d%d)-(%d%d)$')
|
||||
if not y then
|
||||
if not due:match('^%d%d%d%d%-%d%d%-%d%d$') then
|
||||
vim.notify('Invalid date format. Use YYYY-MM-DD.', vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
|
|
|||
|
|
@ -199,7 +199,6 @@ function M.authorize()
|
|||
end
|
||||
local code_verifier = table.concat(verifier)
|
||||
|
||||
local sha_result = vim.system({ 'printf', '%s', code_verifier }, { text = true }):wait()
|
||||
local sha_pipe = vim
|
||||
.system({
|
||||
'sh',
|
||||
|
|
@ -401,7 +400,14 @@ function M.sync()
|
|||
local extra = task._extra or {}
|
||||
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)
|
||||
if not del_err then
|
||||
extra._gcal_event_id = nil
|
||||
|
|
@ -430,18 +436,6 @@ function M.sync()
|
|||
created = created + 1
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ describe('parse', function()
|
|||
end)
|
||||
|
||||
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)
|
||||
end)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue