Skip to content

Commit 2a88b17

Browse files
committed
chore: remove golangci-lint mode
1 parent 213f5ee commit 2a88b17

File tree

1 file changed

+6
-49
lines changed

1 file changed

+6
-49
lines changed

protogetter.go

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import (
1616
"golang.org/x/tools/go/ast/inspector"
1717
)
1818

19-
type Mode int
20-
21-
const (
22-
StandaloneMode Mode = iota
23-
GolangciLintMode
24-
)
25-
2619
const msgFormat = "avoid direct access to proto field %s, use %s instead"
2720

2821
func NewAnalyzer(cfg *Config) *analysis.Analyzer {
@@ -35,7 +28,7 @@ func NewAnalyzer(cfg *Config) *analysis.Analyzer {
3528
Doc: "Reports direct reads from proto message fields when getters should be used",
3629
Flags: flags(cfg),
3730
Run: func(pass *analysis.Pass) (any, error) {
38-
_, err := Run(pass, cfg)
31+
err := Run(pass, cfg)
3932
return nil, err
4033
},
4134
}
@@ -62,14 +55,13 @@ func flags(opts *Config) flag.FlagSet {
6255
}
6356

6457
type Config struct {
65-
Mode Mode // Zero value is StandaloneMode.
6658
SkipGeneratedBy []string
6759
SkipFiles []string
6860
SkipAnyGenerated bool
6961
ReplaceFirstArgInAppend bool
7062
}
7163

72-
func Run(pass *analysis.Pass, cfg *Config) ([]Issue, error) {
64+
func Run(pass *analysis.Pass, cfg *Config) error {
7365
skipGeneratedBy := make([]string, 0, len(cfg.SkipGeneratedBy)+3)
7466
// Always skip files generated by protoc-gen-go, protoc-gen-go-grpc and protoc-gen-grpc-gateway.
7567
skipGeneratedBy = append(skipGeneratedBy, "protoc-gen-go", "protoc-gen-go-grpc", "protoc-gen-grpc-gateway")
@@ -90,7 +82,7 @@ func Run(pass *analysis.Pass, cfg *Config) ([]Issue, error) {
9082

9183
compile, err := glob.Compile(s)
9284
if err != nil {
93-
return nil, fmt.Errorf("invalid glob pattern: %w", err)
85+
return fmt.Errorf("invalid glob pattern: %w", err)
9486
}
9587

9688
skipFilesGlobPatterns = append(skipFilesGlobPatterns, compile)
@@ -124,24 +116,16 @@ func Run(pass *analysis.Pass, cfg *Config) ([]Issue, error) {
124116

125117
ins := inspector.New(files)
126118

127-
var issues []Issue
128-
129119
filter := NewPosFilter()
130120
ins.Preorder(nodeTypes, func(node ast.Node) {
131121
report := analyse(pass, filter, node, cfg)
132122
if report == nil {
133123
return
134124
}
135-
136-
switch cfg.Mode {
137-
case StandaloneMode:
138-
pass.Report(report.ToDiagReport())
139-
case GolangciLintMode:
140-
issues = append(issues, report.ToIssue(pass.Fset))
141-
}
125+
pass.Report(report.ToDiagReport())
142126
})
143127

144-
return issues, nil
128+
return nil
145129
}
146130

147131
func analyse(pass *analysis.Pass, filter *PosFilter, n ast.Node, cfg *Config) *Report {
@@ -185,19 +169,6 @@ func analyse(pass *analysis.Pass, filter *PosFilter, n ast.Node, cfg *Config) *R
185169
}
186170
}
187171

188-
// Issue is used to integrate with golangci-lint's inline auto fix.
189-
type Issue struct {
190-
Pos token.Position
191-
Message string
192-
InlineFix InlineFix
193-
}
194-
195-
type InlineFix struct {
196-
StartCol int // zero-based
197-
Length int
198-
NewString string
199-
}
200-
201172
type Report struct {
202173
node ast.Node
203174
result *Result
@@ -225,27 +196,13 @@ func (r *Report) ToDiagReport() analysis.Diagnostic {
225196
}
226197
}
227198

228-
func (r *Report) ToIssue(fset *token.FileSet) Issue {
229-
msg := fmt.Sprintf(msgFormat, r.result.From, r.result.To)
230-
return Issue{
231-
Pos: fset.Position(r.node.Pos()),
232-
Message: msg,
233-
InlineFix: InlineFix{
234-
StartCol: fset.Position(r.node.Pos()).Column - 1,
235-
Length: len(r.result.From),
236-
NewString: r.result.To,
237-
},
238-
}
239-
}
240-
241199
func skipGeneratedFile(f *ast.File, prefixes []string, skipAny bool) bool {
242200
if len(f.Comments) == 0 {
243201
return false
244202
}
245203
firstComment := f.Comments[0].Text()
246204

247-
// https://golang.org/s/generatedcode
248-
if skipAny && strings.HasPrefix(firstComment, "Code generated") {
205+
if skipAny && ast.IsGenerated(f) {
249206
return true
250207
}
251208

0 commit comments

Comments
 (0)