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
checker: add defer at the end of function checker #901
Conversation
792624d
to
9f83419
Compare
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.
SGTM, @quasilyte ?
checkers/deferAtTheEnd_checker.go
Outdated
if fnlit.Body.List == nil { | ||
s += "{}" | ||
} else { | ||
s += "{…}" |
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.
TBH I would like to omit Unicode characters as stick to simple ASCII.
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.
OK, I'll fix it
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.
Fixed
fnlit, ok := deferStmt.Call.Fun.(*ast.FuncLit) | ||
if ok { | ||
// To avoid long and multi-line warning messages, | ||
// collapse the function literals. |
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.
sounds reasonable
} | ||
}() | ||
return | ||
} |
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.
Looks good, I'm curious, will it handle defer
inside if
? :)
Even if no - it can be marked as a TODO comment.
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'll add a test
9f83419
to
f099cf7
Compare
Detects uneeded defer at the end of function.
f099cf7
to
486d4e1
Compare
thanks! |
Detects uneeded defer at the end of function.