From e322fbb80b0be5e885268c91ab29cbfe0143cd5b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 1 Jan 2023 13:27:05 +1100 Subject: [PATCH] chore: remove diagnostic suppressions after tidying nits --- .luarc.json | 9 --------- lua/nvim-tree/actions/reloaders/reloaders.lua | 4 ++-- lua/nvim-tree/explorer/filters.lua | 4 ++-- lua/nvim-tree/git/runner.lua | 2 +- lua/nvim-tree/legacy.lua | 10 +++++----- lua/nvim-tree/log.lua | 10 ++++++---- lua/nvim-tree/utils.lua | 17 ++++------------- lua/nvim-tree/view.lua | 8 ++++---- 8 files changed, 24 insertions(+), 40 deletions(-) diff --git a/.luarc.json b/.luarc.json index 173b5845..0400ee52 100644 --- a/.luarc.json +++ b/.luarc.json @@ -4,15 +4,6 @@ "diagnostics": { "globals": [ "vim" - ], - "disable": [ - "cast-local-type", - "lowercase-global", - "missing-parameter", - "missing-return", - "missing-return-value", - "need-check-nil", - "param-type-mismatch" ] } } diff --git a/lua/nvim-tree/actions/reloaders/reloaders.lua b/lua/nvim-tree/actions/reloaders/reloaders.lua index 63bf4896..b69cf4a0 100644 --- a/lua/nvim-tree/actions/reloaders/reloaders.lua +++ b/lua/nvim-tree/actions/reloaders/reloaders.lua @@ -30,8 +30,8 @@ function M.reload_node_status(parent_node, projects) end local event_running = false ----@param _ table unused node passed by action ----@param unloaded_bufnr number optional bufnr recently unloaded via BufUnload event +---@param _ table|nil unused node passed by action +---@param unloaded_bufnr number|nil optional bufnr recently unloaded via BufUnload event function M.reload_explorer(_, unloaded_bufnr) if event_running or not core.get_explorer() or vim.v.exiting ~= vim.NIL then return diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index 8af47e1f..366a8e5b 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -91,8 +91,8 @@ local function custom(path) end ---Prepare arguments for should_filter. This is done prior to should_filter for efficiency reasons. ----@param git_status table results of git.load_project_status(...) ----@param unloaded_bufnr number optional bufnr recently unloaded via BufUnload event +---@param git_status table|nil optional results of git.load_project_status(...) +---@param unloaded_bufnr number|nil optional bufnr recently unloaded via BufUnload event ---@return table --- git_status: reference --- unloaded_bufnr: copy diff --git a/lua/nvim-tree/git/runner.lua b/lua/nvim-tree/git/runner.lua index a03c72e4..7a12894d 100644 --- a/lua/nvim-tree/git/runner.lua +++ b/lua/nvim-tree/git/runner.lua @@ -45,7 +45,7 @@ function Runner:_handle_incoming_data(prev_output, incoming) self._parse_status_output(line) end - return nil + return "" end function Runner:_getopts(stdout_handle, stderr_handle) diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index c3a72c3c..a98a919d 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -14,16 +14,16 @@ local function refactored(opts) end -- 2022/06/20 - utils.move_missing_val(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root") - utils.move_missing_val(opts, "", "update_cwd", opts, "", "sync_root_with_cwd") + utils.move_missing_val(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root", true) + utils.move_missing_val(opts, "", "update_cwd", opts, "", "sync_root_with_cwd", true) -- 2022/11/07 utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "open", false) - utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "close") - utils.move_missing_val(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore") + utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "close", true) + utils.move_missing_val(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore", true) -- 2022/11/22 - utils.move_missing_val(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label") + utils.move_missing_val(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true) end local function removed(opts) diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index c307d7bc..9f035bad 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -14,9 +14,11 @@ function M.raw(typ, fmt, ...) local line = string.format(fmt, ...) local file = io.open(M.path, "a") - io.output(file) - io.write(line) - io.close(file) + if file then + io.output(file) + io.write(line) + io.close(file) + end end --- Write to log file via M.line @@ -24,7 +26,7 @@ end --- @return number nanos to pass to profile_end function M.profile_start(fmt, ...) if not M.path or not M.config.types.profile and not M.config.types.all then - return + return 0 end M.line("profile", "START " .. (fmt or "???"), ...) return vim.loop.hrtime() diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index b1c62889..433fef6f 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -197,12 +197,8 @@ end -- Create empty sub-tables if not present -- @param tbl to create empty inside of -- @param path dot separated string of sub-tables --- @return deepest sub-table +-- @return table deepest sub-table function M.table_create_missing(tbl, path) - if tbl == nil then - return nil - end - local t = tbl for s in string.gmatch(path, "([^%.]+)%.*") do if t[s] == nil then @@ -222,12 +218,8 @@ end --- @param dst table to copy to --- @param dst_path string dot separated string of sub-tables, created when missing --- @param dst_pos string value pos ---- @param remove boolean default true +--- @param remove boolean function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remove) - if remove == nil then - remove = true - end - local ok, err = pcall(vim.validate, { src = { src, "table" }, src_path = { src_path, "string" }, @@ -246,11 +238,10 @@ function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remo if src[pos] and type(src[pos]) == "table" then src = src[pos] else - src = nil - break + return end end - local src_val = src and src[src_pos] + local src_val = src[src_pos] if src_val == nil then return end diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 4ffa3905..f9e1ad1c 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -389,8 +389,8 @@ function M.restore_tab_state() end --- Returns the window number for nvim-tree within the tabpage specified ----@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage. ----@return number +---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage. +---@return number|nil function M.get_winnr(tabpage) tabpage = tabpage or vim.api.nvim_get_current_tabpage() local tabinfo = M.View.tabpages[tabpage] @@ -406,8 +406,8 @@ function M.get_bufnr() end --- Checks if nvim-tree is displaying the help ui within the tabpage specified ----@param tabpage number: (optional) the number of the chosen tabpage. Defaults to current tabpage. ----@return number +---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage. +---@return number|nil function M.is_help_ui(tabpage) tabpage = tabpage or vim.api.nvim_get_current_tabpage() local tabinfo = M.View.tabpages[tabpage]