Skip to content

Commit e344fd6

Browse files
authored
[refactor] Run gofumpt, enforcer in CICD (#417)
## Summary TSIA ## How was it tested?
1 parent 2487362 commit e344fd6

13 files changed

Lines changed: 35 additions & 26 deletions

File tree

.github/workflows/monorepo-go.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ jobs:
4747
- name: Build
4848
run: devbox run build
4949

50+
- name: Format
51+
run: |
52+
devbox run fmt
53+
git diff --exit-code
54+
5055
- name: Test
5156
run: devbox run test

pkg/auth/internal/tokenstore/io.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func issuerSlug(issuer string) string {
2323

2424
func ensureDir(path string) error {
2525
dir := filepath.Dir(path)
26-
return os.MkdirAll(dir, 0700)
26+
return os.MkdirAll(dir, 0o700)
2727
}
2828

2929
func writeJSONFile(path string, value storeData) error {
@@ -36,7 +36,7 @@ func writeJSONFile(path string, value storeData) error {
3636
if err != nil {
3737
return errors.WithStack(err)
3838
}
39-
return errors.WithStack(os.WriteFile(path, data, 0644))
39+
return errors.WithStack(os.WriteFile(path, data, 0o644))
4040
}
4141

4242
func readJSONFile(path string, value *storeData) error {

pkg/auth/internal/tokenstore/tokenstore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type storeData struct {
2222
func New(rootDir string) (*Store, error) {
2323
// The store contains tokens that enable a particular user to authenticate.
2424
// It's important that the directory can only be read by that user.
25-
err := os.MkdirAll(rootDir, 0700)
25+
err := os.MkdirAll(rootDir, 0o700)
2626
if err != nil {
2727
return nil, err
2828
}

pkg/filecache/filecache.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"go.jetpack.io/pkg/cachehash"
1212
)
1313

14-
var NotFound = errors.New("not found")
15-
var Expired = errors.New("expired")
14+
var (
15+
NotFound = errors.New("not found")
16+
Expired = errors.New("expired")
17+
)
1618

1719
type Cache[T any] struct {
1820
domain string
@@ -55,7 +57,7 @@ func (c *Cache[T]) Set(key string, val T, dur time.Duration) error {
5557
return errors.WithStack(err)
5658
}
5759

58-
return errors.WithStack(os.WriteFile(c.filename(key), d, 0644))
60+
return errors.WithStack(os.WriteFile(c.filename(key), d, 0o644))
5961
}
6062

6163
// SetWithTime is like Set but it allows the caller to specify the expiration
@@ -66,7 +68,7 @@ func (c *Cache[T]) SetWithTime(key string, val T, t time.Time) error {
6668
return errors.WithStack(err)
6769
}
6870

69-
return errors.WithStack(os.WriteFile(c.filename(key), d, 0644))
71+
return errors.WithStack(os.WriteFile(c.filename(key), d, 0o644))
7072
}
7173

7274
// Get retrieves a value from the cache with the given key.
@@ -142,6 +144,6 @@ func IsCacheMiss(err error) bool {
142144

143145
func (c *Cache[T]) filename(key string) string {
144146
dir := filepath.Join(c.cacheDir, c.domain)
145-
_ = os.MkdirAll(dir, 0755)
147+
_ = os.MkdirAll(dir, 0o755)
146148
return filepath.Join(dir, cachehash.Slug(key))
147149
}

pkg/runx/impl/fileutil/fileutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func EnsureDir(path string) error {
5959
if IsDir(path) {
6060
return nil
6161
}
62-
return os.MkdirAll(path, 0700 /* as suggested by xdg spec */)
62+
return os.MkdirAll(path, 0o700 /* as suggested by xdg spec */)
6363
}
6464

6565
func (p Path) EnsureDir() error {
@@ -86,5 +86,5 @@ func WriteFile(path string, data []byte) error {
8686
return err
8787
}
8888
// Write using `renameio` to ensure an atomic write:
89-
return renameio.WriteFile(path, data, 0600)
89+
return renameio.WriteFile(path, data, 0o600)
9090
}

pkg/runx/impl/registry/extract.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func contentDir(path string) string {
5757
}
5858

5959
func createSymbolicLink(src, dst, repoName string) error {
60-
if err := os.MkdirAll(dst, 0700); err != nil {
60+
if err := os.MkdirAll(dst, 0o700); err != nil {
6161
return err
6262
}
63-
if err := os.Chmod(src, 0755); err != nil {
63+
if err := os.Chmod(src, 0o755); err != nil {
6464
return err
6565
}
6666
binaryName := filepath.Base(src)

pkg/runx/impl/types/errors.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package types
22

33
import "errors"
44

5-
var ErrPackageNotFound = errors.New("package not found")
6-
var ErrReleaseNotFound = errors.New("release not found")
7-
var ErrPlatformNotSupported = errors.New("package doesn't support platform")
5+
var (
6+
ErrPackageNotFound = errors.New("package not found")
7+
ErrReleaseNotFound = errors.New("release not found")
8+
ErrPlatformNotSupported = errors.New("package doesn't support platform")
9+
)

templates/hello-go/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package main
22

33
import (
4-
"fmt"
5-
"net/http"
4+
"fmt"
5+
"net/http"
66
)
77

88
func main() {
9-
http.HandleFunc("/", HelloServer)
10-
http.ListenAndServe(":8080", nil)
9+
http.HandleFunc("/", HelloServer)
10+
http.ListenAndServe(":8080", nil)
1111
}
1212

1313
func HelloServer(w http.ResponseWriter, r *http.Request) {
14-
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
14+
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
1515
}

typeid/typeid-go/encoding.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
// TODO: Define a standardized binary encoding for typeids in the spec
88
// and use that to implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler
99

10-
var _ encoding.TextMarshaler = (*TypeID[AnyPrefix])(nil)
11-
var _ encoding.TextUnmarshaler = (*TypeID[AnyPrefix])(nil)
10+
var (
11+
_ encoding.TextMarshaler = (*TypeID[AnyPrefix])(nil)
12+
_ encoding.TextUnmarshaler = (*TypeID[AnyPrefix])(nil)
13+
)
1214

1315
// UnmarshalText implements the encoding.TextUnmarshaler interface.
1416
// It parses a TypeID from a string using the same logic as FromString()

typeid/typeid-go/typeid.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func (tid TypeID[P]) String() string {
4242
// UUIDBytes decodes the TypeID's suffix as a UUID and returns it's bytes
4343
func (tid TypeID[P]) UUIDBytes() []byte {
4444
b, err := base32.Decode(tid.Suffix())
45-
4645
// Decode only fails if the suffix cannot be decoded for one of two reasons:
4746
// 1. The suffix is not 26 characters long
4847
// 2. The suffix contains characters that are not in the base32 alphabet

0 commit comments

Comments
 (0)