Call style
Lua allows the following form of calling
local lib = require 'Module:Foo' return describe lib function() expect -- something end
The funny part is return describe lib function…
which seems almost magical. Each call eats one value argument, and it progresses until a statement is found. At that point it stops, but it might restart from that statement. To make this work the call to the left must generate a new call, typically by defining a __call()
meta function. Only one value is eaten at a time, and each time a new call must be made. Because only value arguments are eaten, all arguments that somehow is a statement must be wrapped in parentheses.
Hidden in the previous is the fact that return
is an operator, and thus defines a statement by itself, so the chaining starts at describe
.
Unfortunately the linter does not like this form, and that is why the function arguments must be wrapped in parentheses. The previous must thus be written as
local lib = require 'Module:Foo' return describe ( lib ) (function() expect -- something end)
or as a list of arguments to a common call
local lib = require 'Module:Foo' return describe(lib, function() expect :bar() :toBe( "Baz" ) end)
In some cases the parenthesized form can be more readable and more easily interpreted as a repeated call.