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
Luacheck allows finding coding errors in Lua source code. I found it quite useful for Lua development. However, coding errors is only a part of possible bugs that can be found in a real projects. It would be nice to find other types of bugs automatically: suspicious constructions in code, using incorrect methods Lua, warnings specific for Lua interpreter (for example highlight things that not implemented in LuaJIT for performance purpose). Unfortunately, Luacheck doesn't allow adding custom checks or rules and limited by a constant number of warnings and errors.
Luacheck already has a Lua API, but it is lack of methods to connect custom checkers. I think it is worth to enhance API that allow to add custom checks.
I think that if the "use semgrep" approach is used, that wouldn't be part of luacheck.
Can you elaborate on what you are looking for a bit? Luacheck goes through a number of stages, which you can view in src/luacheck/stages/init.lua. The way to extend luacheck in practice would be to add additional modules in there. There are potentially two places people might want to add modules:
(1) After "unwrap_parens". At this point, the starting lua code has been parsed into an AST and any simplifications have been applied to the AST.
(2) After "resolve_locals". (At any point, possibly including at the absolute end.) At this point, luacheck has "linearized" the AST, i.e. converted into a linear representation of items, and analyzed out scope and variable information.
Seems like the natural way to handle this is to expose callbacks in the Lua API to register additional callbacks to run after those two stages. However, I'm not sure if that actually makes any sense, presumably it's about as easy to just add the stage manually and fork luacheck?
Problem description
Luacheck allows finding coding errors in Lua source code. I found it quite useful for Lua development. However, coding errors is only a part of possible bugs that can be found in a real projects. It would be nice to find other types of bugs automatically: suspicious constructions in code, using incorrect methods Lua, warnings specific for Lua interpreter (for example highlight things that not implemented in LuaJIT for performance purpose). Unfortunately, Luacheck doesn't allow adding custom checks or rules and limited by a constant number of warnings and errors.
Possible solutions
Use semgrep. There is a static analysis tool named semgrep that allows to describe your own rules in declarative format and among other supported programming languages semgrep has Lua support too (in experimental mode). Seems semgrep uses tree-sitter parser for Lua.
Luacheck already has a Lua API, but it is lack of methods to connect custom checkers. I think it is worth to enhance API that allow to add custom checks.
Additional information
Similar requests in Peter's Luacheck repository- How do add Custom Rules and Q: Can I add custom operators? (adjust syntax).
Requests for new checkers: #19, mpeterv#190, mpeterv#167, mpeterv#64, mpeterv#63, mpeterv#128, mpeterv#129.
The text was updated successfully, but these errors were encountered: