Add static analysis tool for Lua code

Bug #1385831 reported by GunChleoc
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Won't Fix
Undecided
Unassigned

Bug Description

Following from the discussion in this bug: https://bugs.launchpad.net/widelands/+bug/1378339

Start digging from https://github.com/mpeterv/luacheck which seems mature and maintained. More links & info in the other bug.

See also https://bugs.launchpad.net/widelands/+bug/1502678

Tags: lua
Revision history for this message
GunChleoc (gunchleoc) wrote :

I had a look at luacheck. The problem with it is that it parses each file separately, so I get a lot of false positives for functions defined in helper scripts. We might be able to solve this problem by defining a rockspec http://www.luarocks.org/en/Rockspec_format

tags: added: lua
Revision history for this message
SirVer (sirver) wrote :

maybe just using grep -v to remove the undefined functions warnings? We do not care about this (as much).

Alternatively we could hack it to understand our "include" function.

Revision history for this message
Peter Melnichenko (mpeterval) wrote :

Hello, I hope you don't mind me, I'm curious to see how luacheck is used and how I can improve it.

It looks like helper functions are defined as globals in helper scripts. You can use `-d` and `--no-unused-globals` options to remove warnings about them. It will leave warnings about accessing globals which are never set anywhere. You can also define globals provided by the game engine using `--globals` options.

I played around on trunk and it seems that optimal options are `luacheck . -q -r -a -d --no-unused-globals --globals path __file__ include wl set_textdomain ngettext` which produces only 18 warnings. There are still a bunch of false positives for unused variables in multi-assignments, e.g. `a, b = foo()` and a is then unused. There is a practice to name such ignored variables with `_` but it seems that `_` is already globally used for something.

You can ditch detection of unused values altogether with `luacheck . -q -r -u -d --no-unused-globals --globals path __file__ include wl set_textdomain ngettext`, which produces 4 warnings, 3 of which seem to point to bugs.

Of course, it is possible to use a config file instead of typing all these options. Documentation isn't perfect by far but it should help: http://luacheck.readthedocs.org/en/latest/config.html . And if you have any questions, please open an issue on github: https://github.com/mpeterv/luacheck/issues .

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for your imput! I'll have a look next week - I don't have my development machine at the moment.

GunChleoc (gunchleoc)
description: updated
GunChleoc (gunchleoc)
Changed in widelands:
milestone: none → build20-rc1
GunChleoc (gunchleoc)
Changed in widelands:
milestone: build20-rc1 → build21-rc1
Revision history for this message
GunChleoc (gunchleoc) wrote :
Changed in widelands:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.