-
Notifications
You must be signed in to change notification settings - Fork 22
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
ifross89
wants to merge
7
commits into
BurntSushi:master
Choose a base branch
from
ifross89:convert-to-library
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@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 |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4
Convert the go-sumtype linting logic to use the
golang.org/x/tools/go/analysis
package and export ananalysis.Analyzer
from the new
sumtype
package.This required a bit more of an invasive change than initially thought.
The main changes were:
packages.Packages
package for loading the files to thenew
analysis
package*analysis.Pass
parameter, ratherthan collecting a list of errors
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
. Weinstead use the
Pos
of the whole file which will report at the topof the file. It may be possible to craft a custom
token.Pos
here,but I do not currently know how to do this.