lunarmodules / luacov

LuaCov is a simple coverage analyzer for Lua code.
http://lunarmodules.github.io/luacov/
MIT License
300 stars 68 forks source link

Fix multiline function declarations #34

Closed mpeterv closed 9 years ago

mpeterv commented 9 years ago

In function declarations argument list never affects coverage. In this patch, arguments are simply removed during line simplification. Fixes exclusion rules not being properly applied when argument list spans several lines.

Follow up commit fixes an issue added in the first one - without argument lists local function noop() end matched local <IDS> exclusion rule. As a side effect function declarations with assignments to string literal indexes are properly excluded, e.g. a["b"] = function(...) is filtered out.

Added tests with samples of some of fixed issues.

mpeterv commented 9 years ago

I tested this PR a bit, without running any real tests, just by annotating source files with marker symbols showing which lines are to be filtered (https://gist.github.com/mpeterv/2f579f508eb725295d50), and comparing annotations made with different luacov versions. For LuaRocks codebase there are no changes, for other projects there are some improvements, e.g.: statements["if"] = function(state, loc) is now correctly filtered out in Luacheck and element.env.randomize = function(...) is now never filtered out in Busted (correct because one of indexing operations is pinned to the line).

hishamhm commented 9 years ago

Merged, thank you!

hishamhm commented 9 years ago

BTW, I just added you to the luacov committers team :)

mpeterv commented 9 years ago

@hishamhm great, thanks =)