Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Run gofumpt, enforcer in CICD #417

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/monorepo-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ jobs:
- name: Build
run: devbox run build

- name: Format
run: |
devbox run fmt
git diff --exit-code

- name: Test
run: devbox run test
4 changes: 2 additions & 2 deletions pkg/auth/internal/tokenstore/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func issuerSlug(issuer string) string {

func ensureDir(path string) error {
dir := filepath.Dir(path)
return os.MkdirAll(dir, 0700)
return os.MkdirAll(dir, 0o700)
}

func writeJSONFile(path string, value storeData) error {
Expand All @@ -36,7 +36,7 @@ func writeJSONFile(path string, value storeData) error {
if err != nil {
return errors.WithStack(err)
}
return errors.WithStack(os.WriteFile(path, data, 0644))
return errors.WithStack(os.WriteFile(path, data, 0o644))
}

func readJSONFile(path string, value *storeData) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/internal/tokenstore/tokenstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type storeData struct {
func New(rootDir string) (*Store, error) {
// The store contains tokens that enable a particular user to authenticate.
// It's important that the directory can only be read by that user.
err := os.MkdirAll(rootDir, 0700)
err := os.MkdirAll(rootDir, 0o700)
if err != nil {
return nil, err
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"go.jetpack.io/pkg/cachehash"
)

var NotFound = errors.New("not found")
var Expired = errors.New("expired")
var (
NotFound = errors.New("not found")
Expired = errors.New("expired")
)

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

return errors.WithStack(os.WriteFile(c.filename(key), d, 0644))
return errors.WithStack(os.WriteFile(c.filename(key), d, 0o644))
}

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

return errors.WithStack(os.WriteFile(c.filename(key), d, 0644))
return errors.WithStack(os.WriteFile(c.filename(key), d, 0o644))
}

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

func (c *Cache[T]) filename(key string) string {
dir := filepath.Join(c.cacheDir, c.domain)
_ = os.MkdirAll(dir, 0755)
_ = os.MkdirAll(dir, 0o755)
return filepath.Join(dir, cachehash.Slug(key))
}
4 changes: 2 additions & 2 deletions pkg/runx/impl/fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func EnsureDir(path string) error {
if IsDir(path) {
return nil
}
return os.MkdirAll(path, 0700 /* as suggested by xdg spec */)
return os.MkdirAll(path, 0o700 /* as suggested by xdg spec */)
}

func (p Path) EnsureDir() error {
Expand All @@ -86,5 +86,5 @@ func WriteFile(path string, data []byte) error {
return err
}
// Write using `renameio` to ensure an atomic write:
return renameio.WriteFile(path, data, 0600)
return renameio.WriteFile(path, data, 0o600)
}
4 changes: 2 additions & 2 deletions pkg/runx/impl/registry/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func contentDir(path string) string {
}

func createSymbolicLink(src, dst, repoName string) error {
if err := os.MkdirAll(dst, 0700); err != nil {
if err := os.MkdirAll(dst, 0o700); err != nil {
return err
}
if err := os.Chmod(src, 0755); err != nil {
if err := os.Chmod(src, 0o755); err != nil {
return err
}
binaryName := filepath.Base(src)
Expand Down
8 changes: 5 additions & 3 deletions pkg/runx/impl/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package types

import "errors"

var ErrPackageNotFound = errors.New("package not found")
var ErrReleaseNotFound = errors.New("release not found")
var ErrPlatformNotSupported = errors.New("package doesn't support platform")
var (
ErrPackageNotFound = errors.New("package not found")
ErrReleaseNotFound = errors.New("release not found")
ErrPlatformNotSupported = errors.New("package doesn't support platform")
)
10 changes: 5 additions & 5 deletions templates/hello-go/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import (
"fmt"
"net/http"
"fmt"
"net/http"
)

func main() {
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
6 changes: 4 additions & 2 deletions typeid/typeid-go/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
// TODO: Define a standardized binary encoding for typeids in the spec
// and use that to implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler

var _ encoding.TextMarshaler = (*TypeID[AnyPrefix])(nil)
var _ encoding.TextUnmarshaler = (*TypeID[AnyPrefix])(nil)
var (
_ encoding.TextMarshaler = (*TypeID[AnyPrefix])(nil)
_ encoding.TextUnmarshaler = (*TypeID[AnyPrefix])(nil)
)

// UnmarshalText implements the encoding.TextUnmarshaler interface.
// It parses a TypeID from a string using the same logic as FromString()
Expand Down
1 change: 0 additions & 1 deletion typeid/typeid-go/typeid.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (tid TypeID[P]) String() string {
// UUIDBytes decodes the TypeID's suffix as a UUID and returns it's bytes
func (tid TypeID[P]) UUIDBytes() []byte {
b, err := base32.Decode(tid.Suffix())

// Decode only fails if the suffix cannot be decoded for one of two reasons:
// 1. The suffix is not 26 characters long
// 2. The suffix contains characters that are not in the base32 alphabet
Expand Down
1 change: 0 additions & 1 deletion tyson/api/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

func Eval(inputPath string) ([]byte, error) {
v, err := interpreter.Eval(inputPath)

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tyson/internal/interpreter/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func findImplicitExport(data []byte) int {
tokenizer.Init(buf)
tokenizer.Error = func(_ *scanner.Scanner, _ string) {} // ignore errors

var offset = -1
offset := -1
nestingLevel := 0
existingObject := false
for tok := tokenizer.Scan(); tok != scanner.EOF; tok = tokenizer.Scan() {
Expand Down
2 changes: 1 addition & 1 deletion tyson/internal/tsembed/tsembed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestEval(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "input.ts")
err := os.WriteFile(path, []byte(tt.input), 0644)
err := os.WriteFile(path, []byte(tt.input), 0o644)
assert.NoError(t, err)
val, err := Eval(path, Options{})
assert.NoError(t, err)
Expand Down
Loading