LuaLS / LuaLS/lua-language-server

Feature Request: Do not diagnose unused-local for function parameters

Open
#3,166 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

This is a feature request for a new setting for LLS which would not diagnose unused-local for variables which are parameters of a function. Something like

"Lua.diagnostics.unusedLocalExcludeFuncParam": true

The reason I'd like this feature is because we have a Lua codebase that heavily relies on something similar to virtual functions, where there are many tables that have functions defined that share the same name and list of parameters, but some of these functions don't need to use all of the parameters. Think of something like this

function menu1:on_select_item(item, mouse_button) do_something_with_item(item) end
function menu2:on_select_item(item, mouse_button) do_something_with_mouse_button(mouse_button) end

Of course this could be changed to appeal to the current unused-local diagnostics by changing it to

function menu1:on_select_item(item) do_something_with_item(item) end
function menu2:on_select_item(_, mouse_button) do_something_with_mouse_button(mouse_button) end

but, besides doing the fixup being a lot of work, it makes maintenance of the code base worse because a programmer can't easily know anymore what those _ parmeters are supposed to be. Another alternative would be to add all known function parameter names to "Lua.diagnostics.unusedLocalExclude" (introduced via #619) but of course that also would be sub-optimal, because ignoring generic names like item could defeat the purpose of the diagnostic.

Besides function parameters, having an option to ignore for-loop variables would also be very neat. It's often easier there to substitute the name for _ but still, sometimes that loses important information on what the key/value of a for-loop over pairs(...) is. So something like

"Lua.diagnostics.unusedLocalExcludeForLoopVars": true

would also be very appreciated.

Thank you for your consideration, and of course for making LLS, it's awesome!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the unused-local diagnostic and the existing Lua.diagnostics.unusedLocalExclude setting. Determine how function parameters and for-loop variables are identified, then define and test the two requested options so enabled settings suppress only those diagnostics while other unused locals remain reported.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.