You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing code in the 'Early return' style/pattern and using return invalid, linter flags an error "not all code paths return a value"
This happens because there is not another return invalid at the end of the function.
Given that return invalid is the default return value (whether specified or not), I'm wondering/hoping if this lint rule can be updated to accommodate the early exit pattern without requiring us to add return invalid at the end of all our functions
Note: if you use this pattern with a sub function definition instead of function, the linter does not throw any warnings/errors
I prefer to write these kind of early-exit functions using sub, but in projects with named-function-style: "no-sub" that isn't possible
' early-exit pattern using 'sub'' passes lint' this will NOT throw "not all code paths return a value"sub myFunc (arg)
ifarg=invalidthenreturn' do something with arg' this function does not return anythingend function' early-exit pattern using 'function'' fails lint' this will throw "not all code paths return a value"function myFunc (arg)
ifarg=invalidthenreturninvalid' do something with arg' this function does not return anything (it is equivalent to a sub call definition)end function' early-exit pattern using 'function' with extra return' passes lintfunction myFunc (arg)
ifarg=invalidthenreturninvalid' do something with arg' this function does not return anything (it is equivalent to a sub call definition)returninvalid' adding superfluous 'return invalid' makes lint happyend function
If I can find the time and the bslint devs are open to changes to support this, I will try to submit a PR if I can get the time to do so
The text was updated successfully, but these errors were encountered:
return invalid
, linter flags an error "not all code paths return a value"return invalid
at the end of the function.return invalid
is the default return value (whether specified or not), I'm wondering/hoping if this lint rule can be updated to accommodate the early exit pattern without requiring us to addreturn invalid
at the end of all our functionssub
function definition instead offunction
, the linter does not throw any warnings/errorssub
, but in projects withnamed-function-style: "no-sub"
that isn't possibleLink to the linter code/line that throws this warning/error
Example of early-return pattern:
If I can find the time and the bslint devs are open to changes to support this, I will try to submit a PR if I can get the time to do so
The text was updated successfully, but these errors were encountered: