Skip to content

Conversation

@Cr4xy
Copy link
Contributor

@Cr4xy Cr4xy commented Oct 25, 2021

This patch adds a diagnostic for unnecessary return statements.

Examples:
examples

@sumneko
Copy link
Collaborator

sumneko commented Oct 25, 2021

Please add tests here: https://github.com/sumneko/lua-language-server/blob/master/test/diagnostics/init.lua
Including positive and negative examples

@sumneko
Copy link
Collaborator

sumneko commented Oct 25, 2021

I don't think that return nil is a redundant return value. Not returning any value is different from returning a nil in Lua.
Please consider the following:

function f() if XXX then return something end return nil end
function f() if XXX then return something end return nil, 'errormessage' end
function f() return a, nil, b end
@Cr4xy
Copy link
Contributor Author

Cr4xy commented Oct 25, 2021

This is how it currently looks:
image

I can change it to only mark a 'return' without any return values:
image

@Cr4xy
Copy link
Contributor Author

Cr4xy commented Oct 25, 2021

Is this ok? I will try to add the tests later today.

@sumneko
Copy link
Collaborator

sumneko commented Oct 25, 2021

Yes, thank you!

@sumneko sumneko merged commit 40c8d31 into LuaLS:master Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants