LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.29k stars 305 forks source link

Two Rule Suggestions: multiple returns in function calls / table definitions and string concatenation #2699

Open chrisgrieser opened 3 months ago

chrisgrieser commented 3 months ago

multiple returns in function calls / table definitions

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

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.)