feat: parse_lua_surface accepts both explicit and sugar-form (S2 follow-up)

Per user-greenlight option (b): function M.foo(...) syntax sugar is now
recognized in addition to M.foo = function(...) explicit-assignment.

Eliminates 7 false-positive stale_docs warnings on every existing lib
README (e.g. lib-core.input). Sugar-form is dominant in Sporel-lib code
(113 occurrences across lib-core/) - sticking to explicit-only would
have required cascade-migrating all init.lua files. This approach is
pragmatic: lint tolerant of idiomatic Lua, no source-rewriting needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-05-16 16:07:06 +02:00
parent f926a58c63
commit 2e72de2ea6

View File

@@ -3,18 +3,35 @@
local M = {} local M = {}
-- Extracts public/private surface from Lua source code. -- Extracts public/private surface from Lua source code.
-- Convention: `M.<name> = function(...)` is public; `M._<name> = ...` is private. -- Convention: M.<name> public; M._<name> private.
-- Supports both explicit assignment (`M.foo = function`) and syntax sugar
-- (`function M.foo`) — Lua treats them semantically identical.
-- Returns: { public = ["foo","bar",...], private = ["_baz",...] } -- Returns: { public = ["foo","bar",...], private = ["_baz",...] }
function M.parse_lua_surface(source_string) function M.parse_lua_surface(source_string)
local public = {} local public = {}
local private = {} local private = {}
for name in string.gmatch(source_string, "M%.([_%w]+)%s*=%s*function") do local seen = {}
local function classify(name)
if seen[name] then return end
seen[name] = true
if string.sub(name, 1, 1) == "_" then if string.sub(name, 1, 1) == "_" then
table.insert(private, name) table.insert(private, name)
else else
table.insert(public, name) table.insert(public, name)
end end
end end
-- Form 1: M.foo = function(...)
for name in string.gmatch(source_string, "M%.([_%w]+)%s*=%s*function") do
classify(name)
end
-- Form 2: function M.foo(...)
for name in string.gmatch(source_string, "function%s+M%.([_%w]+)") do
classify(name)
end
return { public = public, private = private } return { public = public, private = private }
end end