lunarmodules / luacheck

A tool for linting and static analysis of Lua code.

Home Page:https://luacheck.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warn on pass-through functions

arichard4 opened this issue · comments

Developers who aren’t familiar with lua often don’t understand that functions are first-class citizens in lua. This results in creating functions that do nothing but call another function, passing any parameters to the outer function into the inner function.

One bit of (unlintable) complexity: sometimes, the outer function can be used to deliberately pass in fewer parameters to an inner function; ie inner function takes 3 parameters, outer function takes 2 and calls the inner function with an implicit nil third parameter, but at a call site that passes the outer function three parameters.

I think the "sometimes" caveat here is probably frequent enough and valid enough that warning on other cases is probably not worthwhile. That being said are you sure we can't lint for it? If we can track unused variables wouldn't we be able to figure out if everything being passed in was used, if there are unused args... Nevermind even in starting to write this I see why it is unlintable. Also there are other use cases such as passing additional arguments from the surrounding scope to the inside function.

I can't imagine this not throwing for too many false positives to be useful. We would need a third level of notice — something below warning.