lua-users home
lua-l archive

Re: Common Lua (Logic/Style etc) Errors Detectable Through Static Analysis

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


One of the hallmarks of JetBrains (the maker of IntelliJ) is the
notion of an intelligent semantically aware text editor.
To honor this I have been creating what are called "inspections" which
find common flaws in code and either flag them, or flag them and offer
to fix them.
...
I am looking for more, so I thought I would ask the list for some suggestions.
I'm not sure how common this is for others, but sometimes I define an object method which references the implicit "self" parameter in its body but then I forget to either 1. include "self" in the parameter list or 2. define the method using the object:method() notation. The end result is of course that "self" refers to a (probably nonexistent) global variable. This could/should be pretty easy to detect using static analysis?
 - Peter Odding
--
PS. Some examples for inspections.lua:
local object = {}
-- self explicitly included in parameter list: OK
function object.goodmethod1(self) print(self) end
-- self implicitly included in parameter list: OK
function object:goodmethod2() print(self) end
-- self refers to a global, probably not what was intended!
function object.badmethod() print(self) end

AltStyle によって変換されたページ (->オリジナル) /