Skip to content

Commit d065bf3

Browse files
authored
Merge pull request #13 from ldez/feat/remove-golancgi-lint-mode
feat: remove golangci-lint mode
2 parents 213f5ee + 20c6b3b commit d065bf3

File tree

4 files changed

+17
-61
lines changed

4 files changed

+17
-61
lines changed

.github/workflows/release.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@ jobs:
1212
contents: write
1313
strategy:
1414
matrix:
15-
go: [ '1.23' ]
15+
go: [ stable ]
1616

1717
steps:
1818
- name: Check out
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
22-
- run: git fetch --force --tags
2322
- name: Setup Go
24-
uses: actions/setup-go@v3
23+
uses: actions/setup-go@v5
2524
with:
2625
go-version: ${{ matrix.go }}
2726
cache: true
2827
- name: release
29-
uses: goreleaser/goreleaser-action@v4
28+
uses: goreleaser/goreleaser-action@v6
3029
with:
3130
distribution: goreleaser
3231
version: latest
3332
args: release --clean
3433
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/testing.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
go: [ '1.22', '1.23' ]
17+
go: [ stable, oldstable ]
1818

1919
steps:
2020
- name: Check out
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222
- name: Setup Go
23-
uses: actions/setup-go@v3
23+
uses: actions/setup-go@v5
2424
with:
2525
go-version: ${{ matrix.go }}
26-
cache: true
2726
- name: Test
28-
run: make test
27+
run: make test

.goreleaser.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: 2
12
before:
23
hooks:
34
- go mod tidy
@@ -21,4 +22,4 @@ changelog:
2122
exclude:
2223
- '^docs:'
2324
- '^test:'
24-
- '^ci:'
25+
- '^ci:'

protogetter.go

+6-49
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)