What I do (and is a good practice), is adding behind the comment more info.
//nolint:errcheck // no need to test it, because it was tested before with stat Op maandag 6 maart 2023 om 23:05:42 UTC+1 schreef Steven Hartland: > I would use the following if I truly wanted to ignore an error, but I > would question if ignoring the error from os.Open was ever a good idea. > If you want to handle a file not found error then do so, don't just ignore > the error. > file, _ := os.Open(name) //nolint: errcheck > > On Mon, 6 Mar 2023 at 20:14, Sergei Dyshel <qyron....@gmail.com> wrote: > >> Hello all, >> I'm incorporating golangci-lint >> <https://golangci-lint.run/usage/linters/> linter aggregator in my >> codebase and facing a dilemma on how to mark false positives for these 2 >> linters: >> >> - errcheck - reports unchecked errors. >> - unparam - reports unused function parameters. >> >> The "official" way is to use special comment directives that make linter >> ignore the line: >> >> func foo( >> name string, >> //nolint:unparam >> age int, >> ) { >> //nolint:errcheck >> file, _ := os.Open(name) >> .... >> >> Another, may be more portable way, would be using special functions which >> do nothing: >> >> // defined in some library utilities package >> func IgnoreErr(err error) {} >> func Unused(a any) {} >> >> func foo( >> name string, >> age int, >> ) { >> Unused(age) >> file, err := os.Open(name) >> IgnoreErr(err) >> ... >> >> What do you think the proper/idiomatic/better way among these two? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/6fc8a933-b68c-4e07-a4ee-98c4fe01ba8dn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/6fc8a933-b68c-4e07-a4ee-98c4fe01ba8dn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/26a4f5d9-f590-4d40-a333-d0bfbe191ca3n%40googlegroups.com.