feat(lua): vim.tbl_contains supports general tables and predicates (#23040)

* feat(lua): vim.tbl_contains supports general tables and predicates

Problem: `vim.tbl_contains` only works for list-like tables (integer
keys without gaps) and primitive values (in particular, not for nested
tables).

Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new
`vim.tbl_contains` that works for general tables and optionally allows
`value` to be a predicate function that is checked for every key.
This commit is contained in:
Christian Clason
2023-04-14 10:39:57 +02:00
committed by GitHub
parent 72a327cad2
commit 4d04feb662
14 changed files with 110 additions and 23 deletions

View File

@@ -88,7 +88,7 @@ local function validate_commit(commit_message)
-- Check if type is correct
local type = vim.split(before_colon, "(", {plain = true})[1]
local allowed_types = {'build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'test', 'vim-patch'}
if not vim.tbl_contains(allowed_types, type) then
if not vim.list_contains(allowed_types, type) then
return string.format(
[[Invalid commit type "%s". Allowed types are:
%s.