Skip to content

Commit c93a64b

Browse files
phanenibhagwan
authored andcommitted
chore(luals): remove need-check-nil
1 parent a30df77 commit c93a64b

17 files changed

Lines changed: 41 additions & 22 deletions

.luarc.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"unbalanced": "Opened",
2626
"unused": "Opened"
2727
},
28-
"disable": ["need-check-nil", "different-requires"],
28+
"disable": ["different-requires"],
2929
"unusedLocalExclude": ["_*"]
3030
},
3131
"workspace": {

lua/fzf-lua/config.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ M.globals = setmetatable({}, {
7676
local setup_default = utils.map_get(setup_defaults(), index)
7777
local setup_value = utils.map_get(setup_opts(), index)
7878
local function build_bind_tables(keys)
79+
assert(fzflua_default)
7980
-- bind tables are logical exception, do not merge with defaults unless `[1] == true`
8081
-- normalize all binds as lowercase to prevent duplicate keys (#654)
8182
local ret = {}
@@ -150,7 +151,7 @@ function M.normalize_opts(opts, globals, __resume_key)
150151

151152
-- opts can also be a function that returns an opts table
152153
if type(opts) == "function" then
153-
opts = opts()
154+
opts = opts() or {}
154155
end
155156

156157
local profile = opts.profile or (function()
@@ -202,6 +203,7 @@ function M.normalize_opts(opts, globals, __resume_key)
202203
-- merge with setup options "defaults" table
203204
globals = vim.tbl_deep_extend("keep", globals, M.setup_opts.defaults or {})
204205
end
206+
---@cast globals table
205207

206208
-- merge current opts with revious __call_opts on resume
207209
if opts.resume then

lua/fzf-lua/core.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ M.set_title_flags = function(opts, titles)
821821
end
822822

823823
M.set_header = function(opts, hdr_tbl)
824+
---@param cwd string
825+
---@return string
824826
local function normalize_cwd(cwd)
825827
if path.is_absolute(cwd) and not path.equals(cwd, uv.cwd()) then
826828
-- since we're always converting cwd to full path

lua/fzf-lua/libuv.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ end
6060
---@return integer pid
6161
M.spawn = function(opts, fn_transform, fn_done)
6262
local EOL = opts.EOL or "\n"
63-
local output_pipe = uv.new_pipe(false)
64-
local error_pipe = uv.new_pipe(false)
63+
local output_pipe = assert(uv.new_pipe(false))
64+
local error_pipe = assert(uv.new_pipe(false))
6565
local write_cb_count, read_cb_count, on_exit_called = 0, 0, nil
6666
local prev_line_content = nil
6767
local handle, pid
@@ -494,7 +494,7 @@ M.spawn_stdio = function(opts, fn_transform_str, fn_preprocess_str, fn_postproce
494494
if type(fd) ~= "number" then
495495
exit(1, ("error opening '%s': %s" .. EOL):format(pipename, fd))
496496
end
497-
local pipe = uv.new_pipe(false)
497+
local pipe = assert(uv.new_pipe(false))
498498
pipe:open(fd)
499499
return pipe
500500
end

lua/fzf-lua/make_entry.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local path = require "fzf-lua.path"
55
local utils = require "fzf-lua.utils"
66
local libuv = require "fzf-lua.libuv"
77
local devicons = require "fzf-lua.devicons"
8-
local config = nil
8+
local config
99

1010
-- attempt to load the current config
1111
-- should fail if we're running headless

lua/fzf-lua/path.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ end
134134
function M.normalize(path)
135135
local p = M.tilde_to_HOME(path)
136136
if utils.__IS_WINDOWS then
137-
p = p:gsub([[\]], [[/]])
137+
p = (p:gsub([[\]], [[/]]))
138138
end
139139
return p
140140
end
@@ -243,16 +243,15 @@ M.HOME = function()
243243
return M.__HOME
244244
end
245245

246-
---@param path string?
247-
---@return string?
246+
---@param path string
247+
---@return string
248248
function M.tilde_to_HOME(path)
249-
return path and path:gsub("^~", M.HOME()) or nil
249+
return (path:gsub("^~", M.HOME()))
250250
end
251251

252-
---@param path string?
253-
---@return string?
252+
---@param path string
253+
---@return string
254254
function M.HOME_to_tilde(path)
255-
if not path then return end
256255
if utils.__IS_WINDOWS then
257256
local home = M.HOME()
258257
if path:sub(1, #home):lower() == home:lower() then
@@ -575,7 +574,8 @@ function M.keymap_to_entry(str, opts)
575574
if not mode or not keymap then return {} end
576575
mode, keymap = vim.trim(mode), vim.trim(keymap)
577576
mode = valid_modes[mode] and mode or "" -- only valid modes
578-
local out, vmap, cmd = nil, nil, string.format("verbose %smap %s", mode, keymap)
577+
local out
578+
local vmap, cmd = nil, string.format("verbose %smap %s", mode, keymap)
579579
-- Run in the context of the originating buffer or keympas might return
580580
-- "No mapping found"
581581
pcall(vim.api.nvim_buf_call, opts.__CTX.bufnr, function()

lua/fzf-lua/previewer/builtin.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ function Previewer.base:update_ts_context()
995995
local lang = vim.treesitter.language.get_lang(ft)
996996
if not utils.has_ts_parser(lang) then return end
997997
local parser = vim.treesitter.get_parser(self.preview_bufnr, lang)
998+
if not parser then return end
998999
local context_updated
9991000
TSContext.zindex = self.win.winopts.zindex + 20
10001001
for _, t in ipairs({ 0, 20, 50, 100 }) do

lua/fzf-lua/providers/buffers.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ end
218218

219219
M.blines = function(opts)
220220
opts = config.normalize_opts(opts, "blines")
221+
-- TODO: remove this guard
222+
if not opts then return end
221223
opts.current_buffer_only = true
222224
if utils.mode_is_visual() then
223225
local _, sel = utils.get_visual_selection()
226+
if not sel then return end
224227
opts.start_line = opts.start_line or sel.start.line
225228
opts.end_line = opts.end_line or sel["end"].line
226229
end
@@ -255,6 +258,7 @@ M.buffer_lines = function(opts)
255258
local bnames = {}
256259
local longest_bname = 0
257260
for _, b in ipairs(buffers) do
261+
---@type string
258262
local bname = utils.nvim_buf_get_name(b)
259263
if not bname:match("^%[") then
260264
bname = path.shorten(vim.fn.fnamemodify(bname, ":~:."))
@@ -606,6 +610,7 @@ M.spellcheck = function(opts)
606610

607611
if utils.mode_is_visual() then
608612
local _, sel = utils.get_visual_selection()
613+
if not sel then return end
609614
opts.start_line = opts.start_line or sel.start.line
610615
opts.end_line = opts.end_line or sel["end"].line
611616
end
@@ -655,7 +660,7 @@ M.spellcheck = function(opts)
655660
return s:gsub("^" .. word_separator .. "+", ""):gsub(word_separator .. "+$", "")
656661
end
657662
from, to = string.find(line, "%w+", from)
658-
local word = from and string.sub(line, from, to)
663+
local word = from and string.sub(line, from, to) or ""
659664
local prefix = from and string.sub(line, from - 1, from - 1) or ""
660665
local postfix = to and string.sub(line, to + 1, to + 1) or ""
661666
local valid_word = word

lua/fzf-lua/providers/colorschemes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function AsyncDownloadManager:jobstart(plugin, job_args)
314314
else
315315
-- job started successfully
316316
utils.info(string.format("%s [path:%s] [job_id:%d]...",
317-
msg, path.HOME_to_tilde(info.path), job_id))
317+
msg, path.HOME_to_tilde(assert(info.path)), job_id))
318318
self.job_ids[tostring(job_id)] = { plugin = plugin, args = job_args }
319319
self.db[plugin].job_id = job_id
320320
end

lua/fzf-lua/providers/dap.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ local utils = require "fzf-lua.utils"
55
local config = require "fzf-lua.config"
66
local make_entry = require "fzf-lua.make_entry"
77

8-
local _has_dap, _dap = nil, nil
8+
local _has_dap
9+
local _dap
910

1011
local M = {}
1112

0 commit comments

Comments
 (0)