deadcode icon indicating copy to clipboard operation
deadcode copied to clipboard

Wrong line numbers reported breaking nolint

Open stevenh opened this issue 8 years ago • 0 comments

If you have an unused constant which is tagged with // nolint: deadcode a warning is still generated

package main
  
import (
        "fmt"
)

const (
        Valid   = iota
        Invalid // nolint: deadcode
        Another
)

func SetState(s int) {
        switch s {
        case Valid:
                fmt.Println("valid")
        default:
                fmt.Println("unknown state %v", s)
        }
}
gometalinter.v1 --disable-all --enable deadcode --debug .
DEBUG: PATH=/data/go/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin:/usr/local/go/bin:/data/go/bin:/data/go/bin
DEBUG: GOPATH=/data/go
DEBUG: GOBIN=/data/go/bin
DEBUG: linting path .
DEBUG: linting with deadcode: deadcode {path} (on .)
DEBUG: executing /data/go/bin/deadcode ["."]
DEBUG: warning: deadcode . returned exit status 2
DEBUG: deadcode hits 2: ^deadcode: (?P<path>.*?\.go):(?P<line>\d+):(?P<col>\d+):\s*(?P<message>.*)$
DEBUG: nolint: parsing job.go for directives
DEBUG: deadcode linter took 11.886236ms
DEBUG: nolint: parsing job.go took 226.93µs
job.go:7:1:warning: Invalid is unused (deadcode)
job.go:12:1:warning: SetState is unused (deadcode)
DEBUG: total elapsed time 22.532206ms

Ignore the fact that SetState is unused, that's just a side effect of the simplified example.

The issue is caused by the fact that deadcode is reporting the issue for line 7 when in fact it should report line 9.

stevenh avatar Jul 06 '17 17:07 stevenh