selene icon indicating copy to clipboard operation
selene copied to clipboard

new lint: redundant pcall wrapper

Open Ozzypig opened this issue 2 years ago • 1 comments

Passing an anonymous function to pcall with just a return statement calling a function can be simplified into one call to pcall with the function directly, and whatever arguments it was sent.

local success, result = pcall(function ()
   return callThisFunction(...)
end)

local success, result = pcall(callThisFunction, ...)

More commonly, in Roblox development, when calling member functions of objects:

local success, result = pcall(function ()
   return LocalizationService:GetCoungryRegionForPlayerAsync(player)
end)

local success, result = pcall(LocalizationService.GetCountryRegionForPlayerAsync, LocalizationService, player)

Ozzypig avatar Mar 15 '22 22:03 Ozzypig

I wouldn't want this to be on by default for colon-methods, I find them to be significantly harder to read, but doing it for the former and having the latter be configurable seems reasonable to me.

Kampfkarren avatar Mar 16 '22 00:03 Kampfkarren