Skip to content

Commit e77be3c

Browse files
committed
fix(spec): Plugin.opts is now always a table. Fixes #351
1 parent ef87c24 commit e77be3c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

lua/lazy/core/loader.lua

+2-5
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ end
234234
-- Merges super opts or runs the opts function to override opts or return new ones
235235
---@param plugin LazyPlugin
236236
function M.opts(plugin)
237+
---@type table
237238
local opts = plugin._.super and M.opts(plugin._.super) or {}
238239
---@type PluginOpts?
239240
local plugin_opts = rawget(plugin, "opts")
@@ -273,11 +274,7 @@ function M.config(plugin)
273274
end
274275
if #mods == 1 then
275276
fn = function()
276-
local opts = M.opts(plugin)
277-
if next(opts) == nil then
278-
opts = nil
279-
end
280-
require(mods[1]).setup(opts)
277+
require(mods[1]).setup(M.opts(plugin))
281278
end
282279
else
283280
return Util.error(

lua/lazy/core/util.lua

+3
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ end
295295
--- Values will me merged in-place in the first left-most table. If you want the result to be in
296296
--- a new table, then simply pass an empty table as the first argument `vim.merge({}, ...)`
297297
--- Supports clearing values by setting a key to `vim.NIL`
298+
---@generic T
299+
---@param ... T
300+
---@return T
298301
function M.merge(...)
299302
local values = { ... }
300303
local ret = values[1]

tests/core/plugin_spec.lua

+8
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ describe("plugin opts", function()
298298
spec = { { "foo/foo", config = { a = 1, b = 1 } }, { "foo/foo", config = { a = vim.NIL } } },
299299
opts = { b = 1 },
300300
},
301+
{
302+
spec = { { "foo/foo", config = { a = 1, b = 1 } }, { "foo/foo" } },
303+
opts = { a = 1, b = 1 },
304+
},
305+
{
306+
spec = { { "foo/foo" }, { "foo/foo" } },
307+
opts = {},
308+
},
301309
}
302310

303311
for _, test in ipairs(tests) do

0 commit comments

Comments
 (0)