From 7d08321ab495bef109c7cbe80446cd9c9a14e99b Mon Sep 17 00:00:00 2001 From: devxpain <170700110+devxpain@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:57:18 +0800 Subject: [PATCH] refactor(keys): use allowlist for valid opts Instead of using a blacklist for specific keys, use an allowlist for valid keys in the `opts` function of `LazyKeysHandler`. --- lua/lazy/core/handler/keys.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/lazy/core/handler/keys.lua b/lua/lazy/core/handler/keys.lua index 57fbc18..33d2580 100644 --- a/lua/lazy/core/handler/keys.lua +++ b/lua/lazy/core/handler/keys.lua @@ -24,7 +24,18 @@ local Util = require("lazy.core.util") ---@class LazyKeysHandler:LazyHandler local M = {} -local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true } +local valid = { + remap = true, + noremap = true, + buffer = true, + silent = true, + nowait = true, + expr = true, + unique = true, + script = true, + desc = true, + replace_keycodes = true, +} ---@param value string|LazyKeysSpec ---@param mode? string @@ -94,7 +105,7 @@ function M.opts(keys) local opts = {} ---@type LazyKeysBase ---@diagnostic disable-next-line: no-unknown for k, v in pairs(keys) do - if type(k) ~= "number" and not skip[k] then + if type(k) ~= "number" and valid[k] then ---@diagnostic disable-next-line: no-unknown opts[k] = v end