nilerr
nilerr copied to clipboard
use comment.Maps.IgnorePos() instead of IgnoreLine()
nilerr sometimes fails to find lint:ignore
comments. This is because
nilerr checks if this comment exists by comment.Maps.IgnoreLine()
,
which does not work well with multiple files. For example, nilerr
mistakenly ignores lint:ignore
with the following files.
-- f.go --
package main
import "errors"
func f() error {
err := errors.New("error")
if err != nil {
//lint:ignore nilerr reason
return nil
}
return nil
}
-- g.go --
package main
import "errors"
func g() error {
err := errors.New("error")
if err != nil {
// not ignored
return err
}
return nil
}
This patch changes to use IgnorePos()
that is safe to use with
multiple files.