You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
functionmenu1:on_select_item(item, mouse_button) do_something_with_item(item) endfunctionmenu2: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
functionmenu1:on_select_item(item) do_something_with_item(item) endfunctionmenu2: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
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 likeThe 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
Of course this could be changed to appeal to the current
unused-local
diagnostics by changing it tobut, 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 likeitem
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 overpairs(...)
is. So something likewould also be very appreciated.
Thank you for your consideration, and of course for making LLS, it's awesome!
The text was updated successfully, but these errors were encountered: