chore: Add linter rule to catch missing return after http writes#2702
Conversation
| m.Match(` | ||
| if $*_ { | ||
| httpapi.Write($*a) | ||
| } |
There was a problem hiding this comment.
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.
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.
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.