Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous "Not all code paths return a value" when using return invalid for early exits #135

Open
addison-adler opened this issue Oct 14, 2024 · 0 comments

Comments

@addison-adler
Copy link

addison-adler commented Oct 14, 2024

  • 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

Link to the linter code/line that throws this warning/error

Example of early-return pattern:

' early-exit pattern using 'sub'
' passes lint
' this will NOT throw "not all code paths return a value"
sub myFunc (arg)
  if arg = invalid then return

  ' do something with arg
  ' this function does not return anything
end function

' early-exit pattern using 'function'
' fails lint
' this will throw "not all code paths return a value"
function myFunc (arg)
  if arg = invalid then return invalid

  ' 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 lint
function myFunc (arg)
  if arg = invalid then return invalid

  ' do something with arg
  ' this function does not return anything (it is equivalent to a sub call definition)
  
  return invalid ' adding superfluous 'return invalid' makes lint happy
end 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant