-
Notifications
You must be signed in to change notification settings - Fork 886
chore: Add linter rule to catch missing return after http writes #2702
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm stoked for this linter!
m.Match(` | ||
if $*_ { | ||
httpapi.Write($*a) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought: Does this, or should we, handle the else
case as well? How about switch
? Is there any way we can express that httapi.Write
is inside a block vs function body?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that is a good question. This is definitely the common case, but you are right about more possible situations.
I am unsure if I can match if
OR else
🤔. This does not work for example
$*_ {
httpapi.Write($*a)
}
I think I will merge this in as is for now. But expanding it would be nice, I just don't think ruleguard can match different AST nodes very well aside from enumerating all cases. Another idea I had was trying to match the correct case like this:
m.Match(`
httpapi.Write($*a)
$r
`).Where(!m["r"].Text.Matches("return"))
So the next line must be return
. This is different than how I've used ruleguard in the past, but might be feasible? I was not able to get it to work with some quick tinkering. It's hard to match for the negative case (missing "return"), and when I've done similar match stuff in the past, the linter starts to become incredibly slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, thanks for checking into it. Yup feel free to merge as-is, fixing the other cases is more of a nice-to-have anyway, def. don't want it becoming slow.
Found a missing return again, figured I'd just write a linter rule to catch these going forward.