sqlclosecheck icon indicating copy to clipboard operation
sqlclosecheck copied to clipboard

Documentation Request for deferring Close()

Open Zamiell opened this issue 3 years ago • 7 comments

Hello, and thanks for the linter.

sqlclosecheck complains that rows.Close() should use defer. Can you explain why this is? For example, I don't see a difference between:

rows := db.Query("SELECT username FROM users")
for rows.Next() {
	// Do something
}
rows.Close()
return

and

rows := db.Query("SELECT username FROM users")
for rows.Next() {
	// Do something
}
defer rows.Close()
return

Putting defer here just seems confusing / a mistake / superfluous.

Zamiell avatar Sep 08 '20 22:09 Zamiell