dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.13k stars 373 forks source link

lint: cgo breaks linter directives #212

Open dominikh opened 6 years ago

dominikh commented 6 years ago

go/loader supports cgo by processing CgoFiles with go tool cgo and parsing the resulting files, similar to how go build works. Unfortunately, go tool cgo does not preserve comments, stripping our directives.

One way around this is to parse the original file, extract the linter directives and transplant them to the generated file. While we do rely on CommentMaps and the association of comments to nodes, linter directives are still line-based, and we extract the line number as soon as possible. Combined with //line directives in the cgo generated file, we can transplant our directives.

It would be nice to do this in our own loader, but in the meantime we can reparse the files we know are part of CgoFiles.

dominikh commented 6 years ago

Demoting this to no milestone. It's not really worth fixing now when we're about to overhaul the loader, anyway.