Skip to content

Commit

Permalink
feat: check repository with gopls check
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoeinride committed Feb 14, 2025
1 parent ea6326b commit 2291542
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .sage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package main

import (
"context"
"fmt"
"io/fs"
"path/filepath"
"strings"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/tools/sgbackstage"
Expand All @@ -11,6 +15,7 @@ import (
"go.einride.tech/sage/tools/sggolangcilint"
"go.einride.tech/sage/tools/sggolicenses"
"go.einride.tech/sage/tools/sggolines"
"go.einride.tech/sage/tools/sggopls"
"go.einride.tech/sage/tools/sgmdformat"
"go.einride.tech/sage/tools/sgyamlfmt"
)
Expand Down Expand Up @@ -46,6 +51,15 @@ func GoLint(ctx context.Context) error {
return sggolangcilint.Run(ctx)
}

func GoPls(ctx context.Context) error {
sg.Logger(ctx).Println("Linting Go files with gopls...")
filePaths, err := goFilePaths()
if err != nil {
return err
}
return sggopls.Check(ctx, filePaths).Run()
}

func GoLintFix(ctx context.Context) error {
sg.Logger(ctx).Println("fixing Go files...")
return sggolangcilint.Fix(ctx)
Expand Down Expand Up @@ -85,3 +99,24 @@ func GitVerifyNoDiff(ctx context.Context) error {
sg.Logger(ctx).Println("verifying that git has no diff...")
return sggit.VerifyNoDiff(ctx)
}

func goFilePaths() ([]string, error) {
var goFilePaths []string
err := filepath.WalkDir(sg.FromGitRoot(), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}
goFilePaths = append(goFilePaths, path)
return nil
})
if err != nil {
return nil, fmt.Errorf("gathering list of go files: %w", err)
}
return goFilePaths, nil
}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ go-lint-fix: $(sagefile)
go-mod-tidy: $(sagefile)
@$(sagefile) GoModTidy

.PHONY: go-pls
go-pls: $(sagefile)
@$(sagefile) GoPls

.PHONY: go-test
go-test: $(sagefile)
@$(sagefile) GoTest

0 comments on commit 2291542

Please sign in to comment.