From 1360be5fda9c67338331abfcd80de2afbb395bcd Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Fri, 30 Aug 2024 17:09:56 -0700 Subject: [PATCH] lint: stricter type checking --- .luarc.json | 9 +++++++++ lua/oil/adapters/files.lua | 5 +++++ lua/oil/adapters/ssh.lua | 2 ++ lua/oil/adapters/ssh/connection.lua | 1 + lua/oil/adapters/ssh/sshfs.lua | 1 + lua/oil/adapters/trash/freedesktop.lua | 1 + lua/oil/adapters/trash/windows/powershell-connection.lua | 1 + lua/oil/layout.lua | 7 ++++--- lua/oil/mutator/trie.lua | 1 + 9 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .luarc.json diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..68da2f2 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,9 @@ +{ + "runtime": { + "version": "LuaJIT", + "pathStrict": true + }, + "type": { + "checkTableShape": true + } +} diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index f65cbf7..593cfce 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -34,6 +34,9 @@ local function read_link_data(path, cb) ) end +---@class (exact) oil.FilesAdapter: oil.Adapter +---@field to_short_os_path fun(path: string, entry_type: nil|oil.EntryType): string + ---@param path string ---@param entry_type nil|oil.EntryType ---@return string @@ -284,6 +287,7 @@ end ---@param column_defs string[] ---@param cb fun(err?: string, entries?: oil.InternalEntry[], fetch_more?: fun()) local function list_windows_drives(url, column_defs, cb) + ---@cast M oil.FilesAdapter local fetch_meta = columns.get_metadata_fetcher(M, column_defs) local stdout = "" local jid = vim.fn.jobstart({ "wmic", "logicaldisk", "get", "name" }, { @@ -341,6 +345,7 @@ M.list = function(url, column_defs, cb) return list_windows_drives(url, column_defs, cb) end local dir = fs.posix_to_os_path(path) + ---@cast M oil.Adapter local fetch_meta = columns.get_metadata_fetcher(M, column_defs) ---@diagnostic disable-next-line: param-type-mismatch, discard-returns diff --git a/lua/oil/adapters/ssh.lua b/lua/oil/adapters/ssh.lua index c52f5a9..0b619ae 100644 --- a/lua/oil/adapters/ssh.lua +++ b/lua/oil/adapters/ssh.lua @@ -50,6 +50,7 @@ M.parse_url = function(oil_url) error(string.format("Malformed SSH url: %s", oil_url)) end + ---@cast ret oil.sshUrl return ret end @@ -440,6 +441,7 @@ M.goto_file = function() url.path = vim.fs.dirname(fullpath) local parurl = url_to_str(url) + ---@cast M oil.Adapter util.adapter_list_all(M, parurl, {}, function(err, entries) if err then vim.notify(string.format("Error finding file '%s': %s", fname, err), vim.log.levels.ERROR) diff --git a/lua/oil/adapters/ssh/connection.lua b/lua/oil/adapters/ssh/connection.lua index 146b140..6a47c07 100644 --- a/lua/oil/adapters/ssh/connection.lua +++ b/lua/oil/adapters/ssh/connection.lua @@ -176,6 +176,7 @@ function SSHConnection.new(url) end end) + ---@cast self oil.sshConnection return self end diff --git a/lua/oil/adapters/ssh/sshfs.lua b/lua/oil/adapters/ssh/sshfs.lua index 3b9faf3..341834c 100644 --- a/lua/oil/adapters/ssh/sshfs.lua +++ b/lua/oil/adapters/ssh/sshfs.lua @@ -70,6 +70,7 @@ end ---@param url oil.sshUrl ---@return oil.sshFs function SSHFS.new(url) + ---@type oil.sshFs return setmetatable({ conn = SSHConnection.new(url), }, { diff --git a/lua/oil/adapters/trash/freedesktop.lua b/lua/oil/adapters/trash/freedesktop.lua index c6221ab..4a65885 100644 --- a/lua/oil/adapters/trash/freedesktop.lua +++ b/lua/oil/adapters/trash/freedesktop.lua @@ -210,6 +210,7 @@ local function read_trash_info(info_file, cb) cb(".trashinfo file points to non-existant file") else trash_info.stat = trash_stat + ---@cast trash_info oil.TrashInfo cb(nil, trash_info) end end) diff --git a/lua/oil/adapters/trash/windows/powershell-connection.lua b/lua/oil/adapters/trash/windows/powershell-connection.lua index f16c346..a296a7e 100644 --- a/lua/oil/adapters/trash/windows/powershell-connection.lua +++ b/lua/oil/adapters/trash/windows/powershell-connection.lua @@ -22,6 +22,7 @@ function PowershellConnection.new(init_command) self:_init(init_command) + ---@type oil.PowershellConnection return self end diff --git a/lua/oil/layout.lua b/lua/oil/layout.lua index fef5f43..f22d26a 100644 --- a/lua/oil/layout.lua +++ b/lua/oil/layout.lua @@ -98,7 +98,7 @@ M.calculate_height = function(desired_height, opts) ) end ----@class (exact) conform.WinLayout +---@class (exact) oil.WinLayout ---@field width integer ---@field height integer ---@field row integer @@ -139,14 +139,15 @@ end ---@param winid integer ---@param direction "above"|"below"|"left"|"right"|"auto" ---@param gap integer ----@return conform.WinLayout root_dim New dimensions of the original window ----@return conform.WinLayout new_dim New dimensions of the new window +---@return oil.WinLayout root_dim New dimensions of the original window +---@return oil.WinLayout new_dim New dimensions of the new window M.split_window = function(winid, direction, gap) if direction == "auto" then direction = vim.o.splitright and "right" or "left" end local float_config = vim.api.nvim_win_get_config(winid) + ---@type oil.WinLayout local dim_root = { width = float_config.width, height = float_config.height, diff --git a/lua/oil/mutator/trie.lua b/lua/oil/mutator/trie.lua index ea39266..7bac161 100644 --- a/lua/oil/mutator/trie.lua +++ b/lua/oil/mutator/trie.lua @@ -7,6 +7,7 @@ local Trie = {} ---@return oil.Trie Trie.new = function() + ---@type oil.Trie return setmetatable({ root = { values = {}, children = {} }, }, {