Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Faulty detection of generated code comment #412

Closed
CodingMinds opened this issue Aug 31, 2018 · 1 comment
Closed

Faulty detection of generated code comment #412

CodingMinds opened this issue Aug 31, 2018 · 1 comment

Comments

@CodingMinds
Copy link

What version of Go are you using (go version)?

go version go1.11 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/Users/geek/go/bin"
GOCACHE="/Users/geek/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/geek/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sc/wbf2w58d7vdgdyynnfvbdygm0000gn/T/go-build176577365=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I've hit an edge case for the implementation in a5f4a24 which should fix #239

If the comment appears after very long lines (local reproduced with round about 65535 characters) it's not detected.

The following

a_b := `...`
// Code generated by some tool. DO NOT EDIT.

leads to an error. ... represents 65527 null bytes. This also appears with more complete go files and real world content (e.g. static assets like minified JS).

Short program to generate test files

package main

import (
  "flag"
  "os"
)

var count = flag.Int("count", 0, "Length of variable content")

func check(e error) {
  if e != nil {
    panic(e)
  }
}

func main() {
  flag.Parse()

  head := []byte("a_b := `")
  bottom := []byte("`\n// Code generated by some tool. DO NOT EDIT.")
  f, err := os.Create("test.go")
  check(err)
  defer f.Close()

  content := make([]byte, *count, *count)

  _, err = f.Write(head)
  check(err)
  _, err = f.Write(content)
  check(err)
  _, err = f.Write(bottom)
  check(err)
  f.Sync()
}

Used like

$ for i in 65526 65527; do echo ${i}; ./writer -count ${i}; golint -set_exit_status test.go || abort; done
65526
65527
test.go:1:1: expected 'package', found a_b (and 65527 more errors)

What did you expect to see?

No error

What did you see instead?

test.go:1:1: expected 'package', found a_b (and 65527 more errors)

@mvdan
Copy link
Member

mvdan commented May 8, 2021

Thank you for submitting this issue! As per golang/go#38968, we are freezing and deprecating golint. There's no drop-in replacement to golint per se, but you should find that Staticcheck works well in encouraging good Go code, much like golint did in the past, since it also includes style checks. There's always gofmt and go vet too, of course.

If you would like to contribute further, I'd encourage you to engage Staticcheck's issue tracker or look at vet's open issues, as they are both actively maintained. If you have an idea that doesn't fit into either of those tools, you could look at other Go linters, or write your own - these days it's fairly straightforward with go/analysis.

To help avoid confusion, I'm closing all issues before we freeze the repository. If you have any feedback, you can leave a comment on the proposal thread where it was decided to deprecate golint - though note that the proposal has been accepted for nearly a year. Thanks!

@mvdan mvdan closed this as completed May 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants