Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve generated files detection #1083

Closed
3 tasks done
rayjlinden opened this issue May 13, 2020 · 3 comments · Fixed by #1161
Closed
3 tasks done

Improve generated files detection #1083

rayjlinden opened this issue May 13, 2020 · 3 comments · Fixed by #1161
Labels
bug Something isn't working

Comments

@rayjlinden
Copy link

golangci-lint is not ignoring auto generated files like it is supposed to. The autogenerated files are made by open-api generator. Here is a part of the top of one of the generated files:

/*
 * webhooksio client
 *
 * Hack because Ray is too lazy to write a client by hand.
 *
 * API version: 1.0.0
 */

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

Thank you for creating the issue!

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
# golangci-lint has version 1.26.0 built from 6bd10d0 on 2020-05-01T15:33:57Z
Config file
$ golangci-lint run --fix --no-config --disable-all -E gofmt -E govet -E errcheck -E staticcheck -E unused -E gosimple -E structcheck -E varcheck -E ineffassign -E deadcode -E typecheck -E gosec ./...
Go environment
$ go version && go env
go version go1.13 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rayj/.cache/go-build"
GOENV="/home/rayj/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="github.com/lindenlab/*"
GONOSUMDB="github.com/lindenlab/*"
GOOS="linux"
GOPATH="/var/tmp/rayj/gocode"
GOPRIVATE="github.com/lindenlab/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/rayj/.gvm/gos/go1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/rayj/.gvm/gos/go1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/var/tmp/rayj/gocode/src/github.com/lindenlab/ecom-webhooks/go.mod"
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-build126193616=/tmp/go-build -gno-record-gcc-switches"```

</details>

<details><summary>Verbose output of running</summary>

```console
$ golangci-lint cache clean
$ golangci-lint run -v
DEBU [autogen_exclude] doc of len 0 doesn't contain any of markers: [code generated do not edit autogenerated file]
DEBU [autogen_exclude] file "webhooksio/api_default.go" is generated: false
DEBU [autogen_exclude] doc of len 0 doesn't contain any of markers: [code generated do not edit autogenerated file]
DEBU [autogen_exclude] file "webhooksio/client.go" is generated: false
DEBU [autogen_exclude] doc of len 0 doesn't contain any of markers: [code generated do not edit autogenerated file]
DEBU [autogen_exclude] file "lambda/main.go" is generated: false
webhooksio/client.go:241:18: Error return value of `w.WriteField` is not checked (errcheck)
					w.WriteField(k, iv)
					            ^
webhooksio/client.go:75:6: `atoi` is unused (deadcode)
func atoi(in string) (int, error) {
     ^
webhooksio/client.go:114:6: `typeCheckParameter` is unused (deadcode)
func typeCheckParameter(obj interface{}, expected string, name string) error {
     ^
webhooksio/client.go:152:6: `parameterToJson` is unused (deadcode)
func parameterToJson(obj interface{}) (string, error) {
     ^
webhooksio/client.go:402:6: `reportError` is unused (deadcode)
func reportError(format string, a ...interface{}) error {
     ^
webhooksio/client.go:508:6: `strlen` is unused (deadcode)
func strlen(s string) int {
     ^
webhooksio/client.go:106:6: SA6005: should use strings.EqualFold(a, b) instead of strings.ToLower(a) == strings.ToLower(b) (staticcheck)
		if strings.ToLower(a) == strings.ToLower(needle) {
		   ^
@rayjlinden rayjlinden added the bug Something isn't working label May 13, 2020
@rayjlinden
Copy link
Author

Looking through how golangci-lint looks for auto-generated code - it appears the C style comment block above the code gen line is the issue. This causse the loop to break and it never sees the auto-gen line. In fact, if I removed that first comment from the generated file - it golangci-lint correctly determined it was an auto-generated file.

It is this code here that seems to be the problem:

for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(line, "//") {
text := strings.TrimSpace(strings.TrimPrefix(line, "//"))
docLines = append(docLines, text)
} else if line == "" || strings.HasPrefix(line, "package") {
// go to next line
} else {
break
}

@ernado
Copy link
Member

ernado commented May 18, 2020

As mentioned in golang/go#13560 (comment):

The text may appear anywhere in the file.

So your file is correct and we should improve detection logic.
Thank you for your report, I'll just slightly adjust issue title.

@ernado ernado changed the title golangci-lint not ignoring auto-gen'd files from openapi-generator Improve generated files detection May 18, 2020
@ldez
Copy link
Member

ldez commented Dec 21, 2020

Fixed by #1161

@ldez ldez closed this as completed Dec 21, 2020
@ldez ldez linked a pull request Dec 21, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants