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

Package analyzer as a library #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ifross89
Copy link

@ifross89 ifross89 commented Jun 7, 2021

Fixes #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
    new analysis package
  • report issues directly to the *analysis.Pass parameter, rather
    than collecting a list of errors
  • use token.Pos rather than a custom Location() method: the
    analysis.Pass.Reportf expects a token.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.

ifross89 added 7 commits June 7, 2021 17:07
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
 new `analysis` package
 - report issues directly to the `*analysis.Pass` parameter, rather
 than collecting a list of errors
 - use `token.Pos` rather than a custom `Location()` method: the
 `analysis.Pass.Reportf` expects a `token.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.
This removes all the files that contain the old logic from the codebase
and switches to using the new `sumtype` package's Analyzer.
This converts the old tests to a the new style of tests that can be run
with `analysisutil.Run`, reducing a bit of boilerplate.
 - ensure testdata files end in newlines
 - add full stop to comments
 - move sumTypeDecl to new file decl.go
 - remove unnecessary `return` statement
 - improve regex in TestNotSealed
also reduce line length of  call
@ifross89
Copy link
Author

@BurntSushi hey so this is the PR that I mentioned in #4.

Wondering if there is anything I can do to help with any review? Thanks

@AlekSi
Copy link

AlekSi commented Oct 25, 2023

It is now done at https://github.com/alecthomas/go-check-sumtype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package as library so gometalinter can use it
2 participants