Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(keys): use allowlist for valid opts#1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
devxpain wants to merge1 commit intofolke:main
base:main
Choose a base branch
Loading
fromdevxpain-fork:main

Conversation

@devxpain
Copy link

Summary

This pull request refactors theopts function inLazyKeysHandler to use an allowlist for valid options instead of a blacklist. This change enhances code clarity and maintainability by explicitly defining accepted options, reducing the risk of unintentional errors from unsupported keys.

Changes Made

  • Replaced the previous blacklist approach with an allowlist for valid keys in theopts function ofLazyKeysHandler.

Reason

I provided this pull request to allow the addition of which-key's key specifications to each plugin'skeys attribute. The previous blacklist method restricted the addition of attributes that weren't explicitly allowed, such as theicon attribute, resulting in errors from Neovim. By using an allowlist, we can avoid these issues and freely include all necessary attributes in the key specifications. Following is an example of what we can do after applying the pull request.

Innvim/lua/plugins/notify.lua

return {"rcarriga/nvim-notify",dependencies= {"nvim-telescope/telescope.nvim",  },keys= {    {"<leader>n",group="Notifications",icon="󰨄"},    {"<leader>nm",":Notifications<CR>",desc="Messages"},    {"<leader>ng",":Telescope notify<CR>",desc="Grep",icon=""},    {"<leader>nd",':lua require"notify".dismiss()<CR>',desc="Dismiss",icon="󰱝"},  },init=function()vim.notify=require("notify")end,}

Innvim/lua/plugins/which-key.lua

return {-- Provides keybindings for all your plugins"folke/which-key.nvim",event="VeryLazy",init=function()vim.o.timeout=truevim.o.timeoutlen=500end,config=function(_,opts)localwk=require("which-key")wk.setup(opts)localspecs= {-- custom specs    }---@castspecswk.Spec[]for_,plugininpairs(require("lazy.core.config").plugins)dolocalkeys=plugin.keysifkeysthenkeys=vim.deepcopy(keys)ifplugin.lazythen-- When plugin.lazy is true, we set key[2] to nil for each key mapping.-- This allows lazy.nvim to use the key mappings as triggers for loading the plugin,-- rather than executing the original RHS (right-hand side) function,-- which may not be available until the plugin is loaded.for_,keyinipairs(keys)dokey[2]=nilendendvim.list_extend(specs,keys)endendwk.add(specs)end,}

Instead of using a blacklist for specific keys, use an allowlist for valid keys in the `opts` function of `LazyKeysHandler`.
@github-actions
Copy link
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actionsgithub-actionsbot added the staleThis issue or PR has been inactive for a while labelApr 3, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

staleThis issue or PR has been inactive for a while

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@devxpain

[8]ページ先頭

©2009-2025 Movatter.jp