-
-
Notifications
You must be signed in to change notification settings - Fork 87
Description
I'm using immutable datatypes a lot recently, and being able to tag custom function return values for the must_use lint would be very helpful. While there is a @mustuse rfc in progress for the core luau language, I've found selene to be so much faster than the analysis engine that I end up using it as the quick validation step on larger (+1000 scripts) projects.
Based on the existing syntax I'd imagine it'd work like this:
type Item= {
read Color: Color3
}
-- selene: deny(must_use)
function setColor(item: Item, color: Color3): Item
if item.Color:ToHex() == color:ToHex() then
return item
end
local out = table.clone(item)
out.Color = color
table.freeze(out)
return out
end
item = setColor(item, Color3.new(1,0,0)) -- pass
setColor(item, Color3.new(1,0,0)) -- fail
If we don't want to reuse the filter syntax, I think -- selene: muse_use
also works great. Whatever would allow for protecting against troublesome functions. I'm alright trying to implement it myself so long as it this design change is approved - all I can say is that currently working with immutable datatypes is just risky due to a lack of any real way to catch dropped returns like these.