luttje / luttje/glua-api-snippets
hook.Add should not warn upon returning value in hook with no documented return value
- Dominant language
- TypeScript
- Stars
- 45
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
This definition:
https://github.com/luttje/glua-api-snippets/blob/443fce9b1dc0306e28eac3dd4ce25b80baf70003/library/hook.lua#L182
Results in this warning:
Despite the wiki not describing a return value for [PlayerLoadout](https://wiki.facepunch.com/gmod/GM:PlayerLoadout) and similar hooks, since [hook.Run will cease calling further hooks if any not-nil value is returned](https://github.com/Facepunch/garrysmod/blob/84fce76d893ca24b7fae3b5a04df3f26f4a9de5d/garrysmod/lua/includes/modules/hook.lua#L123-L128) the code is valid and should not warn.
Perhaps if the hook has no return value on the wiki we should have it be `any` by default.
And untested, but there is likely a warning when the inverse happens, so in that case I guess we should have all returns in hooks be nillable.
Contributor guide
Research direction
Start with library/hook.lua at the linked definition around line 182 and compare its return handling with the hook.Run behavior linked in the issue. Check PlayerLoadout and similar hooks whose wiki entries document no return value, then verify that valid non-nil returns do not produce warnings and that the inverse nil-return case is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100