-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add protogetter linter #4069
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
add protogetter linter #4069
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ec43156
add testcase
ghostiam 6510799
add protogolint
ghostiam 7befebe
protogolint: add "--fix" support
ghostiam 36d67ec
protogolint: fix linter order in manager
ghostiam 4164452
protogolint: upd version
ghostiam 79d651f
protogolint: go mod tidy
ghostiam 6bb8eb1
protogolint: rename to protogetter
ghostiam aef8208
protogetter: update version
ghostiam 969ed83
protogetter: update version
ghostiam 66247e7
protogetter: update tests
ghostiam 0a84704
review: fix copy-paste
ldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package golinters | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/ghostiam/protogetter" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
"github.com/golangci/golangci-lint/pkg/lint/linter" | ||
"github.com/golangci/golangci-lint/pkg/result" | ||
) | ||
|
||
func NewProtoGetter() *goanalysis.Linter { | ||
var mu sync.Mutex | ||
var resIssues []goanalysis.Issue | ||
|
||
a := protogetter.NewAnalyzer() | ||
a.Run = func(pass *analysis.Pass) (any, error) { | ||
pgIssues := protogetter.Run(pass, protogetter.GolangciLintMode) | ||
|
||
issues := make([]goanalysis.Issue, len(pgIssues)) | ||
for i, issue := range pgIssues { | ||
report := &result.Issue{ | ||
FromLinter: a.Name, | ||
Pos: issue.Pos, | ||
Text: issue.Message, | ||
Replacement: &result.Replacement{ | ||
Inline: &result.InlineFix{ | ||
StartCol: issue.InlineFix.StartCol, | ||
Length: issue.InlineFix.Length, | ||
NewString: issue.InlineFix.NewString, | ||
}, | ||
}, | ||
} | ||
|
||
issues[i] = goanalysis.NewIssue(report, pass) | ||
} | ||
|
||
if len(issues) == 0 { | ||
return nil, nil | ||
} | ||
|
||
mu.Lock() | ||
resIssues = append(resIssues, issues...) | ||
mu.Unlock() | ||
|
||
return nil, nil | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
nil, | ||
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { | ||
return resIssues | ||
}).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module protogetter | ||
|
||
go 1.19 | ||
|
||
require ( | ||
google.golang.org/grpc v1.57.0 | ||
google.golang.org/protobuf v1.31.0 | ||
) | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
golang.org/x/net v0.9.0 // indirect | ||
golang.org/x/sys v0.7.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package proto | ||
|
||
func (x *Embedded) CustomMethod() interface{} { | ||
return nil | ||
} | ||
|
||
type Other struct { | ||
} | ||
|
||
func (x *Other) MyMethod(certs *Test) *Embedded { | ||
return nil | ||
} | ||
|
||
func (x *Test) Equal(v *Test) bool { | ||
return false | ||
} | ||
|
||
func (x *Embedded) SetS(s string) { | ||
x.S = s | ||
} | ||
|
||
func (x *Embedded) SetMap(_ map[string]string) { | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.