LuaLS / LuaLS/lua-language-server
Two Rule Suggestions: multiple returns in function calls / table definitions and string concatenation
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### multiple returns in function calls / table definitions
```lua
local a = { "one", "two", "three" }
local b = { unpack(a), "four" }
local c = { "four", unpack(a) }
print(#b) -- 2
print(#c) -- 4
```
`unpack`'s behavior is quite unintuitive; when the output is not in the last position of a table definition, only the first element is actually included in the new table. (In fact, this not only applies to `unpack`, but to every function that returns multiple values – only happens most often with `unpack` that will people will notice, I assume.)
see explainer in the docs: https://www.lua.org/manual/5.3/manual.html#3.4
I think a diagnostic that reminds one of such cases would be very useful, since it's a common gotcha in lua.
## string concatenation
```lua
print("foo" + "bar")
```
Common mistake to not use `..` for string concatenation. Even though I am used to lua, it still happens to me all the time after coming back from writing in a different language. A diagnostic here would be useful. (And I am actually a bit surprised that there isn't one yet.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Lua 5.3 manual section linked in the issue, especially the multiple-return rules illustrated by the table examples. Then locate the language-server diagnostic entry points for multiple-return expressions in table definitions and for using + with strings. Done means both examples produce useful diagnostics without incorrectly flagging valid Lua code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100