go-sumtype
go-sumtype copied to clipboard
Package analyzer as a library
Fixes https://github.com/BurntSushi/go-sumtype/issues/4
Convert the go-sumtype linting logic to use the
golang.org/x/tools/go/analysis
package and export an analysis.Analyzer
from the new sumtype
package.
This required a bit more of an invasive change than initially thought. The main changes were:
- move from
packages.Packages
package for loading the files to the newanalysis
package - report issues directly to the
*analysis.Pass
parameter, rather than collecting a list of errors - use
token.Pos
rather than a customLocation()
method: theanalysis.Pass.Reportf
expects atoken.Pos
An effort was taken to do this change with the minimum amount of logic changes as possible, to reduce the chance of regression.
There is, however, a minor regression: due to manually searching the go
files for the comment directive, we do not have an accurate token.Pos
. We
instead use the Pos
of the whole file which will report at the top
of the file. It may be possible to craft a custom token.Pos
here,
but I do not currently know how to do this.
@BurntSushi hey so this is the PR that I mentioned in https://github.com/BurntSushi/go-sumtype/issues/4.
Wondering if there is anything I can do to help with any review? Thanks
It is now done at https://github.com/alecthomas/go-check-sumtype