From 2a88b17995131447f9bc6bd24c72703febada9c3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 22 Dec 2024 22:36:09 +0100 Subject: [PATCH 1/2] chore: remove golangci-lint mode --- protogetter.go | 55 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/protogetter.go b/protogetter.go index 31eee85..c1c42c7 100644 --- a/protogetter.go +++ b/protogetter.go @@ -16,13 +16,6 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -type Mode int - -const ( - StandaloneMode Mode = iota - GolangciLintMode -) - const msgFormat = "avoid direct access to proto field %s, use %s instead" func NewAnalyzer(cfg *Config) *analysis.Analyzer { @@ -35,7 +28,7 @@ func NewAnalyzer(cfg *Config) *analysis.Analyzer { Doc: "Reports direct reads from proto message fields when getters should be used", Flags: flags(cfg), Run: func(pass *analysis.Pass) (any, error) { - _, err := Run(pass, cfg) + err := Run(pass, cfg) return nil, err }, } @@ -62,14 +55,13 @@ func flags(opts *Config) flag.FlagSet { } type Config struct { - Mode Mode // Zero value is StandaloneMode. SkipGeneratedBy []string SkipFiles []string SkipAnyGenerated bool ReplaceFirstArgInAppend bool } -func Run(pass *analysis.Pass, cfg *Config) ([]Issue, error) { +func Run(pass *analysis.Pass, cfg *Config) error { skipGeneratedBy := make([]string, 0, len(cfg.SkipGeneratedBy)+3) // Always skip files generated by protoc-gen-go, protoc-gen-go-grpc and protoc-gen-grpc-gateway. 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) { compile, err := glob.Compile(s) if err != nil { - return nil, fmt.Errorf("invalid glob pattern: %w", err) + return fmt.Errorf("invalid glob pattern: %w", err) } skipFilesGlobPatterns = append(skipFilesGlobPatterns, compile) @@ -124,24 +116,16 @@ func Run(pass *analysis.Pass, cfg *Config) ([]Issue, error) { ins := inspector.New(files) - var issues []Issue - filter := NewPosFilter() ins.Preorder(nodeTypes, func(node ast.Node) { report := analyse(pass, filter, node, cfg) if report == nil { return } - - switch cfg.Mode { - case StandaloneMode: - pass.Report(report.ToDiagReport()) - case GolangciLintMode: - issues = append(issues, report.ToIssue(pass.Fset)) - } + pass.Report(report.ToDiagReport()) }) - return issues, nil + return nil } 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 } } -// Issue is used to integrate with golangci-lint's inline auto fix. -type Issue struct { - Pos token.Position - Message string - InlineFix InlineFix -} - -type InlineFix struct { - StartCol int // zero-based - Length int - NewString string -} - type Report struct { node ast.Node result *Result @@ -225,27 +196,13 @@ func (r *Report) ToDiagReport() analysis.Diagnostic { } } -func (r *Report) ToIssue(fset *token.FileSet) Issue { - msg := fmt.Sprintf(msgFormat, r.result.From, r.result.To) - return Issue{ - Pos: fset.Position(r.node.Pos()), - Message: msg, - InlineFix: InlineFix{ - StartCol: fset.Position(r.node.Pos()).Column - 1, - Length: len(r.result.From), - NewString: r.result.To, - }, - } -} - func skipGeneratedFile(f *ast.File, prefixes []string, skipAny bool) bool { if len(f.Comments) == 0 { return false } firstComment := f.Comments[0].Text() - // https://golang.org/s/generatedcode - if skipAny && strings.HasPrefix(firstComment, "Code generated") { + if skipAny && ast.IsGenerated(f) { return true } From 20c6b3bd745ae5fba98e71d9c7439993c4ee5023 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 22 Dec 2024 22:36:36 +0100 Subject: [PATCH 2/2] chore: update workflows --- .github/workflows/release.yaml | 11 +++++------ .github/workflows/testing.yaml | 9 ++++----- .goreleaser.yaml | 3 ++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4a2df01..3bf7ad7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,24 +12,23 @@ jobs: contents: write strategy: matrix: - go: [ '1.23' ] + go: [ stable ] steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - - run: git fetch --force --tags - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} cache: true - name: release - uses: goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest args: release --clean env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 3d57925..93c226f 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -14,15 +14,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.22', '1.23' ] + go: [ stable, oldstable ] steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - cache: true - name: Test - run: make test \ No newline at end of file + run: make test diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a70d0fb..cc5d4cf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,3 +1,4 @@ +version: 2 before: hooks: - go mod tidy @@ -21,4 +22,4 @@ changelog: exclude: - '^docs:' - '^test:' - - '^ci:' \ No newline at end of file + - '^ci:'