SpacemanDMM icon indicating copy to clipboard operation
SpacemanDMM copied to clipboard

[Feature Request] Add a warning that the function should be in a if() if it has a return FALSE/TRUE

Open redmoogle opened this issue 3 years ago • 5 comments

Basically when you have a function say

/proc/foo(var/bar)
  if(bar)
    return TRUE
  return FALSE

and you do

/proc/main()
  foo(TRUE)

it should emit a warning that it should be in a check.

Why I'm inquiring about this, is that I've caught a few bugs because the output of the function isnt checked

redmoogle avatar Jan 28 '21 15:01 redmoogle

Might be tricky, remember these just evaluate to 1/0.

Maybe a more generic lint that return values of tagged function are "checked."

Cyberboss avatar Jan 28 '21 19:01 Cyberboss

yeah, I mean if it specifically has a return in the function, all calls should be in some sort of assignment or check/if

redmoogle avatar Jan 28 '21 20:01 redmoogle

This definitely shouldn't be default behavior though. There are many functions that return a value that doesn't necessarily need to be checked.

Cyberboss avatar Jan 28 '21 20:01 Cyberboss

seems like it should imo. if theres specifically a return in there it seems like it should be checked. Could I see some code where this wouldnt apply?

redmoogle avatar Jan 28 '21 20:01 redmoogle

Most of the functionality for this already exists with purity lint, I can add a code standards config option or a lint to enable it without having to use the purity lint @redmoogle

spookydonut avatar Mar 10 '21 08:03 spookydonut