refactor(generator): use fmt() for string.format() more (#34528)

This commit is contained in:
zeertzjq
2025-06-17 06:50:51 +08:00
committed by GitHub
parent 24bb110588
commit 5647b45e69
2 changed files with 10 additions and 10 deletions

View File

@@ -180,7 +180,7 @@ local function api_type(t)
local a = api_type(as[1]) local a = api_type(as[1])
local count = tonumber(as[2]) local count = tonumber(as[2])
if count then if count then
return ('[%s]'):format(a:rep(count, ', ')) return fmt('[%s]', a:rep(count, ', '))
else else
return a .. '[]' return a .. '[]'
end end
@@ -220,7 +220,7 @@ local function api_type(t)
as1[#as1 + 1] = nm .. ': ' .. api_type(a1[1]) as1[#as1 + 1] = nm .. ': ' .. api_type(a1[1])
end end
return ('fun(%s)%s'):format(table.concat(as1, ', '), r and ': ' .. api_type(r) or '') return fmt('fun(%s)%s', table.concat(as1, ', '), r and ': ' .. api_type(r) or '')
end end
return API_TYPES[t] or t return API_TYPES[t] or t
@@ -617,7 +617,7 @@ local function render_eval_doc(f, fun, write)
if fun.returns ~= false then if fun.returns ~= false then
write(util.md_to_vimdoc('Return: ~', 16, 16, TEXT_WIDTH)) write(util.md_to_vimdoc('Return: ~', 16, 16, TEXT_WIDTH))
local ret = ('(`%s`)'):format((fun.returns or 'any')) local ret = fmt('(`%s`)', (fun.returns or 'any'))
ret = ret .. (fun.returns_desc and ' ' .. fun.returns_desc or '') ret = ret .. (fun.returns_desc and ' ' .. fun.returns_desc or '')
ret = util.md_to_vimdoc(ret, 18, 18, TEXT_WIDTH) ret = util.md_to_vimdoc(ret, 18, 18, TEXT_WIDTH)
write(ret) write(ret)
@@ -803,12 +803,12 @@ local function get_option_meta()
local tags_file = assert(io.open(TAGS_FILE)) local tags_file = assert(io.open(TAGS_FILE))
local tags_text = tags_file:read('*a') local tags_text = tags_file:read('*a')
tags_file:close() tags_file:close()
local map_fn = function(k, v) local map_fn = function(event_name, is_window_local)
if v then if is_window_local then
return nil return nil -- Don't include in the list of events outside window context.
end end
local tag_pat = ('\n%s\t([^\t]+)\t'):format(k) local tag_pat = fmt('\n%s\t([^\t]+)\t', event_name)
local link_text = ('|%s|'):format(k) local link_text = fmt('|%s|', event_name)
local tags_match = tags_text:match(tag_pat) --- @type string? local tags_match = tags_text:match(tag_pat) --- @type string?
return tags_match and tags_match ~= 'deprecated.txt' and link_text or nil return tags_match and tags_match ~= 'deprecated.txt' and link_text or nil
end end

View File

@@ -758,7 +758,7 @@ local function render_fun(fun, classes, cfg)
else else
local v = assert(util.version_level[since], 'invalid @since on ' .. fun.name) local v = assert(util.version_level[since], 'invalid @since on ' .. fun.name)
fun.attrs = fun.attrs or {} fun.attrs = fun.attrs or {}
table.insert(fun.attrs, ('Since: %s'):format(v)) table.insert(fun.attrs, fmt('Since: %s', v))
end end
end end
@@ -799,7 +799,7 @@ local function render_fun(fun, classes, cfg)
if fun.overloads then if fun.overloads then
table.insert(ret, '\n Overloads: ~\n') table.insert(ret, '\n Overloads: ~\n')
for _, p in ipairs(fun.overloads) do for _, p in ipairs(fun.overloads) do
table.insert(ret, (' • `%s`\n'):format(p)) table.insert(ret, fmt(' • `%s`\n', p))
end end
end end