Skip to content

Commit c2e0763

Browse files
SpollaLclaude
andcommitted
feat: validate setup() options and report clear errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7e37c2c commit c2e0763

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

lua/datasight/config.lua

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,54 @@ M.defaults = {
1414
-- Start with a copy of defaults. setup() will merge user options into this.
1515
M.options = vim.deepcopy(M.defaults)
1616

17+
local VALID_BORDERS = { rounded=true, single=true, double=true, solid=true, shadow=true, none=true }
18+
19+
local function validate(opts)
20+
local errors = {}
21+
22+
if opts.binary_path ~= nil and type(opts.binary_path) ~= "string" then
23+
table.insert(errors, "binary_path must be a string")
24+
end
25+
26+
if opts.width ~= nil then
27+
if type(opts.width) ~= "number" or opts.width <= 0 or opts.width > 1 then
28+
table.insert(errors, "width must be a number between 0 and 1 (e.g. 0.85)")
29+
end
30+
end
31+
32+
if opts.height ~= nil then
33+
if type(opts.height) ~= "number" or opts.height <= 0 or opts.height > 1 then
34+
table.insert(errors, "height must be a number between 0 and 1 (e.g. 0.85)")
35+
end
36+
end
37+
38+
if opts.border ~= nil and not VALID_BORDERS[opts.border] then
39+
table.insert(errors, "border must be one of: rounded, single, double, solid, shadow, none")
40+
end
41+
42+
if opts.auto_open ~= nil and type(opts.auto_open) ~= "boolean" then
43+
table.insert(errors, "auto_open must be a boolean")
44+
end
45+
46+
if opts.keymaps ~= nil then
47+
if type(opts.keymaps) ~= "table" then
48+
table.insert(errors, "keymaps must be a table")
49+
elseif opts.keymaps.open ~= nil
50+
and opts.keymaps.open ~= false
51+
and type(opts.keymaps.open) ~= "string" then
52+
table.insert(errors, "keymaps.open must be a string or false")
53+
end
54+
end
55+
56+
if #errors > 0 then
57+
error("datasight.nvim: invalid config:\n - " .. table.concat(errors, "\n - "), 2)
58+
end
59+
end
60+
1761
function M.setup(opts)
18-
M.options = vim.tbl_deep_extend("force", M.defaults, opts or {})
62+
opts = opts or {}
63+
validate(opts)
64+
M.options = vim.tbl_deep_extend("force", M.defaults, opts)
1965
end
2066

2167
return M

0 commit comments

Comments
 (0)