fix(parse_readme_api): support namespace-less function names
The previous single-pattern approach used a greedy `[^.\x60]*` segment that mis-captured H3 headers without a namespace prefix (e.g. test-lib entrypoints documented as `### \`run_tests(ctx)\``). Replace with a two-pass match: pattern 1 captures `### \`ns.func(...)\`` (namespaced) and pattern 2 captures `### \`func(...)\`` (no namespace). A seen-set prevents the namespace-less pass from re-matching names already collected by the namespaced pass. Enables test-libs to declare a public surface in their READMEs and satisfy --lint's missing-docs check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
22
init.lua
22
init.lua
@@ -50,6 +50,8 @@ end
|
|||||||
-- Returns: { documented = ["bind","unbind",...] }
|
-- Returns: { documented = ["bind","unbind",...] }
|
||||||
function M.parse_readme_api(markdown_string)
|
function M.parse_readme_api(markdown_string)
|
||||||
local documented = {}
|
local documented = {}
|
||||||
|
local seen = {}
|
||||||
|
|
||||||
-- Find "## API" section start (allow trailing whitespace/content)
|
-- Find "## API" section start (allow trailing whitespace/content)
|
||||||
local api_start = string.find(markdown_string, "\n## API[%s\n]")
|
local api_start = string.find(markdown_string, "\n## API[%s\n]")
|
||||||
if not api_start then
|
if not api_start then
|
||||||
@@ -59,10 +61,24 @@ function M.parse_readme_api(markdown_string)
|
|||||||
local api_end = string.find(markdown_string, "\n## ", api_start + 5)
|
local api_end = string.find(markdown_string, "\n## ", api_start + 5)
|
||||||
local section = string.sub(markdown_string, api_start, api_end or #markdown_string)
|
local section = string.sub(markdown_string, api_start, api_end or #markdown_string)
|
||||||
|
|
||||||
-- Match H3 headers: "### `[namespace.]name(...)`" — capture name portion
|
-- Two-pass matching to handle both namespace-prefixed and namespace-less
|
||||||
for line in string.gmatch(section, "###%s+`[^.`]*%.?([_%w]+)%s*[%(`]") do
|
-- function-names in H3 headers.
|
||||||
table.insert(documented, line)
|
-- Pattern 1: namespaced — "### `ns.func(...)`" -> capture "func"
|
||||||
|
for name in string.gmatch(section, "###%s+`[%w_]+%.([_%w]+)") do
|
||||||
|
if not seen[name] then
|
||||||
|
seen[name] = true
|
||||||
|
table.insert(documented, name)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
-- Pattern 2: namespace-less — "### `func(...)`" -> capture "func"
|
||||||
|
-- The seen-set prevents re-matching names already captured by pattern 1.
|
||||||
|
for name in string.gmatch(section, "###%s+`([_%w]+)%s*[%(`]") do
|
||||||
|
if not seen[name] then
|
||||||
|
seen[name] = true
|
||||||
|
table.insert(documented, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return { documented = documented }
|
return { documented = documented }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user