nilerr icon indicating copy to clipboard operation
nilerr copied to clipboard

use comment.Maps.IgnorePos() instead of IgnoreLine()

Open daichimukai opened this issue 2 years ago • 0 comments

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.

daichimukai avatar Aug 27 '22 21:08 daichimukai