Skip to content

result/processors: treat all non-Go source as special autogenerated files #1544

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

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

kortschak
Copy link
Contributor

Prior to this change golangci-lint would attempt to follow //line directives into generation description files unless they were in a small set of fake files used by goyacc. Now we consider all non-Go source as special.

Fixes #1543

…iles

Prior to this change golangci-lint would attempt to follow //line
directives into generation description files unless they were in a small
set of fake files used by goyacc. Now we consider all non-Go source as
special.
@kortschak kortschak requested a review from jirfag December 8, 2020 21:37
@bombsimon
Copy link
Member

I don't know the history behind this but it surprises me why the old implementation only skips some files. It feels very obvious to skip every non Go file. I can't get Go code without .go extension to work either by themselves or in a package so I guess it's mandatory.

It would be interesting to see why those files are picked up since it would make sense if every non Go file was filtered out by the analysis package.

I will approve this but would love more insight in how this actually works. I know for a fact when helping out with gochecknoglobals I had to manually skip non Go files since the analyzer picks up generated code created by analysistest. I wonder why these get's passed to the analyzer at all.

// fake files to which //line points to for goyacc generated files
return fileName == "yacctab" || fileName == "yaccpar" || fileName == "NONE"
// fake files or generation definitions to which //line points to for generated files
return filepath.Ext(fileName) != ".go"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe filepath.Ext(filePath) != ".go" is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if we are comparing the full path we can avoid filepath and skip calling into OS specific code and just do strings.HaveSuffix(filePath, ".go"). Maybe we can save a microsecond or three? 😄

@kortschak
Copy link
Contributor Author

I wonder why these get's passed to the analyzer at all.

I imagine that it's because the //line directives are trusted to only be talking about Go code.

@kortschak kortschak merged commit 33fe87b into golangci:master Dec 11, 2020
@kortschak kortschak deleted the nolint-gen branch December 11, 2020 06:37
@ldez ldez added this to the v1.34 milestone Mar 6, 2024
@ldez ldez added the area: cgo Related to CGO or line directives label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cgo Related to CGO or line directives
Projects
None yet
Development

Successfully merging this pull request may close these issues.

golangci-lint attempts to follow //line directives into non-Go source
4 participants