golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.71k stars 1.39k forks source link

line directives in generated source files appear to confuse the linter when looking up the AST #403

Closed jaqx0r closed 5 years ago

jaqx0r commented 5 years ago

In the text below and also per the golangci link below, the file internal/vm/parser/parser.go is not in the cache because, I think, it's being excluded due to having the word "autogenerated" in the source text.

This is confusing the golint, goconst, and a few other linters -- several show up as not being able to find 'parser.go' in the map.

If I remove the "skip-files" section from golintci.yml, then the errors don't go away. Commit https://github.com/google/mtail/commit/de0e167e25c5f30e33d479c65d0bcd9a9953d7e3 removes it, and you can see the result is the same.

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)

golangci-lint has version 1.15.0 built from 901cf25 on 2019-02-18T08:24:43Z

  1. Config file: cat .golangci.yml

https://github.com/google/mtail/blob/master/.golangci.yml

  1. Go environment: go version && go env

$ go version
    go version go1.11.5 linux/amd64
$ go env
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/root/.cache/go-build"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/go"
    GOPROXY=""
    GORACE=""
    GOROOT="/usr/local/go"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    GOMOD=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build453916870=/tmp/go-build -gno-record-gcc-switches"
  1. Verbose output of running: golangci-lint run -v

Example output is at https://golangci.com/r/github.com/google/mtail

Here's a snippet:

$ GOLANGCI_COM_RUN=1 golangci-lint run --out-format=json --issues-exit-code=0 --deadline=5m --new=false --new-from-rev= --new-from-patch=
    level=warning msg="[runner] Can't run linter golint: no AST for file /go/src/github.com/google/mtail/internal/vm/parser/parser.go in cache: {m:map[/go/src/github.com/google/mtail/internal/mtail/golden/reader.go:0xc01160c5a0 /go/src/github.com/google/mtail/internal/vm/vm_test.go:0xc01160c900 /go/src/github.com/google/mtail/internal/vm/parser/lexer_test.go:0xc01160cd80 /go/src/github.com/google/mtail/internal/vm/types/types_test.go:0xc01160cf00 /go/src/github.com/google/mtail/internal/vm/codegen/codegen.go:0xc011651890 /go/src/github.com/google/mtail/internal/metrics/metric_test.go:0xc011651dd0 /go/src/github.com/google/mtail/internal/mtail/mtail_test.go:0xc01160c1b0 /go/src/github.com/google/mtail/internal/mtail/compile_only_integration_test.go:0xc01160c2d0 /go/src/github.com/google/mtail/internal/vm/checker/checker.go:0xc011651830 /go/src/github.com/google/mtail/internal/metrics/store_test.go:0xc011651e30 /go/src/github.com/google/mtail/internal/metrics/datum/string.go:0xc011651f80 /go/src/github.com/google/mtail/internal/watcher/log_watcher.go:0xc01160cf90 /go/src/github.com/google/mtail/internal/mtail/logo.ico.go:0xc01160c060 /go/src/github.com/google/mtail/internal/mtail/permission_denied_integration_test.go:0xc01160c510 /go/src/github.com/google/mtail/internal/tailer/file.go:0xc01160c630 /go/src/github.com/google/mtail/internal/tailer/tail.go:0xc01160c6c0 /go/src/github.com/google/mtail/internal/testutil/err.go:0xc0116515f0 /go/src/github.com/google/mtail/internal/vm/object/object.go:0xc011651860 /go/src/github.com/google/mtail/cmd/mdot/main.go:0xc0116518c0 /go/src/github.com/google/mtail/internal/metrics/datum/int.go:0xc011651f50 /go/src/github.com/google/mtail/internal/tailer/file_test.go:0xc01160c6f0 /go/src/github.com/google/mtail/internal/watcher/fake_watcher.go:0xc01160cf30 /go/src/github.com/google/mtail/internal/testutil/fs.go:0xc0116516b0 /go/src/github.com/google/mtail/internal/metrics/datum/int_test.go:0xc01160c030 /go/src/github.com/google/mtail/internal/mtail/examples_integration_test.go:0xc01160c300 /go/src/github.com/google/mtail/internal/vm/ast/walk_test.go:0xc01160c990 /go/src/github.com/google/mtail/internal/testutil/file.go:0xc011651620 /go/src/github.com/google/mtail/cmd/mgen/main.go:0xc0116518f0 /go/src/github.com/google/mtail/internal/exporter/varz.go:0xc011651b60 /go/src/github.com/google/mtail/internal/vm/loader_test.go:0xc01160c870 /go/src/github.com/google/mtail/internal/exporter/prometheus_test.go:0xc011651c80 /go/src/github.com/google/mtail/internal/mtail/benchmarks_test.go:0xc01160c240 /go/src/github.com/google/mtail/internal/watcher/log_watcher_test.go:0xc01160d080 /go/src/github.com/google/mtail/internal/watcher/watcher.go:0xc01160cff0 /go/src/github.com/google/mtail/internal/watcher/fake_watcher_test.go:0xc01160d020 /go/src/github.com/google/mtail/internal/mtail/basic_tail_integration_test.go:0xc01160c1e0 /go/src/github.com/google/mtail/internal/mtail/glob_relative_after_start_integration_test.go:0xc01160c360 /go/src/github.com/google/mtail/internal/vm/checker/checker_test.go:0xc01160c9f0 /go/src/github.com/google/mtail/internal/vm/code/opcodes_test.go:0xc01160cab0 /go/src/github.com/google/mtail/internal/vm/parser/driver.go:0xc01160cba0 /go/src/github.com/google/mtail/internal/vm/parser/parser_test.go:0xc01160cde0 /go/src/github.com/google/mtail/internal/vm/symbol/symtab_test.go:0xc01160cea0 /go/src/github.com/google/mtail/internal/vm/types/types.go:0xc01160ced0 /go/src/github.com/google/mtail/internal/testutil/diff.go:0xc0116515c0 /go/src/github.com/google/mtail/internal/testutil/flag.go:0xc011651680 /go/src/github.com/google/mtail/internal/exporter/prometheus.go:0xc011651ad0 /go/src/github.com/google/mtail/internal/mtail/log_glob_integration_test.go:0xc01160c3c0 /go/src/github.com/google/mtail/internal/mtail/new_prog_integration_test.go:0xc01160c480 /go/src/github.com/google/mtail/internal/mtail/read_pipe_integration_test.go:0xc01160c540 /go/src/github.com/google/mtail/internal/vm/code/opcodes.go:0xc01160ca80 /go/src/github.com/google/mtail/internal/vm/parser/tokens_test.go:0xc01160ce40 /go/src/github.com/google/mtail/internal/mtail/testing.go:0xc01160c180 /go/src/github.com/google/mtail/internal/vm/code/instr_test.go:0xc01160cb10 /go/src/github.com/google/mtail/internal/vm/parser/parser.y:0xc01160cc60 /go/src/github.com/google/mtail/internal/vm/parser/sexp.go:0xc01160ccc0 /go/src/github.com/google/mtail/internal/logline/logline.go:0xc011651590 /go/src/github.com/google/mtail/internal/vm/ast/walk.go:0xc011651740 /go/src/github.com/google/mtail/internal/metrics/store.go:0xc011651d40 /go/src/github.com/google/mtail/internal/mtail/options.go:0xc01160c0f0 /go/src/github.com/google/mtail/internal/vm/position/position.go:0xc0116516e0 /go/src/github.com/google/mtail/internal/mtail/golden/reader_test.go:0xc01160c600 /go/src/github.com/google/mtail/internal/tailer/tail_test.go:0xc01160c780 /go/src/github.com/google/mtail/internal/vm/parser/unparser.go:0xc01160cd50 /go/src/github.com/google/mtail/internal/mtail/truncate_integration_test.go:0xc01160c570 /go/src/github.com/google/mtail/cmd/mtail/main.go:0xc011651950 /go/src/github.com/google/mtail/internal/exporter/export.go:0xc0116519b0 /go/src/github.com/google/mtail/internal/metrics/metric.go:0xc011651d10 /go/src/github.com/google/mtail/internal/metrics/datum/datum_test.go:0xc011651fb0 /go/src/github.com/google/mtail/internal/vm/code/instr.go:0xc01160ca20 /go/src/github.com/google/mtail/internal/exporter/json.go:0xc011651a10 /go/src/github.com/google/mtail/internal/exporter/statsd.go:0xc011651b30 /go/src/github.com/google/mtail/internal/mtail/log_rotation_integration_test.go:0xc01160c3f0 /go/src/github.com/google/mtail/internal/vm/vm.go:0xc01160c810 /go/src/github.com/google/mtail/internal/metrics/datum/float.go:0xc011651f20 /go/src/github.com/google/mtail/internal/mtail/mtail.go:0xc01160c0c0 /go/src/github.com/google/mtail/internal/vm/compiler.go:0xc01160c7b0 /go/src/github.com/google/mtail/internal/exporter/collectd.go:0xc011651980 /go/src/github.com/google/mtail/internal/exporter/graphite.go:0xc0116519e0 /go/src/github.com/google/mtail/internal/exporter/export_test.go:0xc011651bf0 /go/src/github.com/google/mtail/internal/exporter/json_test.go:0xc011651c50 /go/src/github.com/google/mtail/internal/exporter/varz_test.go:0xc011651cb0 /go/src/github.com/google/mtail/internal/metrics/datum/datum.go:0xc011651e60 /go/src/github.com/google/mtail/internal/vm/compiler_test.go:0xc01160c930 /go/src/github.com/google/mtail/internal/vm/parser/tokens.go:0xc01160cd20 /go/src/github.com/google/mtail/internal/vm/loader.go:0xc01160c7e0 /go/src/github.com/google/mtail/internal/vm/codegen/codegen_test.go:0xc01160cb70 /go/src/github.com/google/mtail/internal/vm/parser/lexer.go:0xc01160cc30 /go/src/github.com/google/mtail/internal/vm/symbol/symtab.go:0xc01160ce70 /go/src/github.com/google/mtail/internal/vm/ast/ast.go:0xc011651710 /go/src/github.com/google/mtail/internal/vm/errors/errors.go:0xc0116517d0 /go/src/github.com/google/mtail/internal/mtail/multiple_lines_integration_test.go:0xc01160c450 /go/src/github.com/google/mtail/internal/mtail/partial_line_integration_test.go:0xc01160c4e0] s:[0xc01160c3f0 0xc01160c810 0xc01160ca20 0xc011651a10 0xc011651b30 0xc011651bf0 0xc011651c50 0xc011651f20 0xc01160c0c0 0xc01160c7b0 0xc011651980 0xc0116519e0 0xc01160c930 0xc01160cd20 0xc011651cb0 0xc011651e60 0xc01160c450 0xc01160c4e0 0xc01160c7e0 0xc01160cb70 0xc01160cc30 0xc01160ce70 0xc011651710 0xc0116517d0 0xc01160c1b0 0xc01160c2d0 0xc01160c5a0 0xc01160c900 0xc01160cd80 0xc01160cf00 0xc011651890 0xc011651dd0 0xc011651f80 0xc01160cf90 0xc011651830 0xc011651e30 0xc0116518c0 0xc011651f50 0xc01160c060 0xc01160c510 0xc01160c630 0xc01160c6c0 0xc0116515f0 0xc011651860 0xc01160c6f0 0xc01160c300 0xc01160c990 0xc01160cf30 0xc0116516b0 0xc01160c030 0xc011651b60 0xc01160c870 0xc011651620 0xc0116518f0 0xc01160d080 0xc011651c80 0xc01160c240 0xc01160c9f0 0xc01160cab0 0xc01160cff0 0xc01160d020 0xc01160c1e0 0xc01160c360 0xc011651ad0 0xc01160c3c0 0xc01160cba0 0xc01160cde0 0xc01160cea0 0xc01160ced0 0xc0116515c0 0xc011651680 0xc01160ca80 0xc01160ce40 0xc01160c480 0xc01160c540 0xc011651d40 0xc01160c0f0 0xc01160c180 0xc01160cb10 0xc01160cc60 0xc01160ccc0 0xc011651590 0xc011651740 0xc01160c780 0xc01160cd50 0xc0116516e0 0xc01160c600 0xc011651d10 0xc011651fb0 0xc01160c570 0xc011651950 0xc0116519b0] log:{rd:0xc000216120 tags:[loader astcache] origLog:0xc011663740}}"
ldez commented 5 years ago

I have the same issue, I think it's related to https://github.com/golangci/golangci-lint/commit/96af9582052f62722593d4085f2357df508a6310

In my case, the source is on a symlink:

# GOPATH=/home/workspace/
/home/workspace/src/github.com/foo/bar -> /home/runner/bar/
dmhilly commented 5 years ago

I'm also having this issue. However, when I delete the line directive above the package declaration in my auto-generated file, I no longer get the error. My guess is that when the auto-generated file contains this line, golangci-lint puts an entry in the AST cache for the source file rather than the generated file.

tpounds commented 5 years ago

FYI this issue may be fixed by https://github.com/golangci/golangci-lint/pull/417 which updates the AST cache to always use the normalized file path for all loads/stores.

jirfag commented 5 years ago

hi! yes, it was fixed in #417

tpounds commented 5 years ago

Resolving as #417 was merged some time ago.