From c6985ddf3dcef0ac81aea08aa6de49046a59a1dd Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 5 Mar 2025 09:45:18 -0500 Subject: [PATCH] fix: lint issues --- git/tree.go | 2 +- pkg/backend/repo.go | 2 +- pkg/backend/webhooks.go | 4 ++-- pkg/daemon/daemon.go | 2 +- pkg/hooks/gen.go | 2 +- pkg/ssh/cmd/tree.go | 2 +- pkg/ssh/cmd/webhooks.go | 28 ++++++++++++------------ pkg/ui/common/utils.go | 6 ++--- pkg/ui/components/statusbar/statusbar.go | 2 +- pkg/ui/pages/repo/filesitem.go | 2 +- pkg/ui/pages/repo/logitem.go | 4 ++-- pkg/ui/pages/repo/refsitem.go | 4 ++-- pkg/ui/pages/repo/stashitem.go | 2 +- pkg/ui/pages/selection/item.go | 2 +- pkg/web/logging.go | 2 +- pkg/webhook/webhook.go | 2 +- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/git/tree.go b/git/tree.go index d5fbe96f7a1582835b49c131f10b60a59bd44967..7bf5b4d26b64007568cc1f9ae39550b470161511 100644 --- a/git/tree.go +++ b/git/tree.go @@ -170,7 +170,7 @@ func (e *TreeEntry) Mode() fs.FileMode { case git.EntryTree: return fs.ModeDir | fs.ModePerm default: - return fs.FileMode(m) + return fs.FileMode(m) //nolint:gosec } } diff --git a/pkg/backend/repo.go b/pkg/backend/repo.go index a4a087fe5a78b3ab4ed0c3a1a38b0505cb432284..bacc8993848b638d4090b79e9f50a348446aa99a 100644 --- a/pkg/backend/repo.go +++ b/pkg/backend/repo.go @@ -742,7 +742,7 @@ func (r *repo) writeLastModified(t time.Time) error { return err } - return os.WriteFile(fp, []byte(t.Format(time.RFC3339)), os.ModePerm) + return os.WriteFile(fp, []byte(t.Format(time.RFC3339)), os.ModePerm) //nolint:gosec } func readOneline(path string) (string, error) { diff --git a/pkg/backend/webhooks.go b/pkg/backend/webhooks.go index 78126b2ee84e8f49c93cba422af3c7e588f62195..e8e1fe9224f5b2bde6e7cae237599b7912fbcee4 100644 --- a/pkg/backend/webhooks.go +++ b/pkg/backend/webhooks.go @@ -54,7 +54,7 @@ func (b *Backend) Webhook(ctx context.Context, repo proto.Repository, id int64) wh = webhook.Hook{ Webhook: h, - ContentType: webhook.ContentType(h.ContentType), + ContentType: webhook.ContentType(h.ContentType), //nolint:gosec Events: make([]webhook.Event, len(events)), } for i, e := range events { @@ -105,7 +105,7 @@ func (b *Backend) ListWebhooks(ctx context.Context, repo proto.Repository) ([]we hooks[i] = webhook.Hook{ Webhook: h, - ContentType: webhook.ContentType(h.ContentType), + ContentType: webhook.ContentType(h.ContentType), //nolint:gosec Events: events, } } diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index e4e6340d91ea604a347b284ddd238d2d097e2f52..a5156355e3362162ca8f958b232a4e5709c79751 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -109,7 +109,7 @@ func (d *GitDaemon) Serve(listener net.Listener) error { } else { tempDelay *= 2 } - if max := 1 * time.Second; tempDelay > max { + if max := 1 * time.Second; tempDelay > max { //nolint:revive tempDelay = max } time.Sleep(tempDelay) diff --git a/pkg/hooks/gen.go b/pkg/hooks/gen.go index 9e445040a26207b838c6e2d7ad45a820e492f1ec..245e5eb69fe4844c19c721cd7573ff723b9b0aab 100644 --- a/pkg/hooks/gen.go +++ b/pkg/hooks/gen.go @@ -48,7 +48,7 @@ func GenerateHooks(_ context.Context, cfg *config.Config, repo string) error { hp := filepath.Join(hooksPath, hook) // Write the hooks primary script - if err := os.WriteFile(hp, []byte(hookTemplate), os.ModePerm); err != nil { + if err := os.WriteFile(hp, []byte(hookTemplate), os.ModePerm); err != nil { //nolint:gosec return err } diff --git a/pkg/ssh/cmd/tree.go b/pkg/ssh/cmd/tree.go index aec94e9165d6375058fa800a9474c6576579baf2..e5fc5fe5e05bf8164665654d28fbdf5cbf145b1f 100644 --- a/pkg/ssh/cmd/tree.go +++ b/pkg/ssh/cmd/tree.go @@ -92,7 +92,7 @@ func treeCommand() *cobra.Command { if size == 0 { ssize = "-" } else { - ssize = humanize.Bytes(uint64(size)) + ssize = humanize.Bytes(uint64(size)) //nolint:gosec } cmd.Printf("%s\t%s\t %s\n", ent.Mode(), ssize, common.UnquoteFilename(ent.Name())) } diff --git a/pkg/ssh/cmd/webhooks.go b/pkg/ssh/cmd/webhooks.go index 0b894a58e63ec4b5fcb74616c03850f96d7f1720..e7409ebbaeafd43b2ad37c48695d2ab1729bccf7 100644 --- a/pkg/ssh/cmd/webhooks.go +++ b/pkg/ssh/cmd/webhooks.go @@ -361,34 +361,34 @@ func webhookDeliveriesGetCommand() *cobra.Command { } out := cmd.OutOrStdout() - fmt.Fprintf(out, "ID: %s\n", del.ID) - fmt.Fprintf(out, "Event: %s\n", del.Event) - fmt.Fprintf(out, "Request URL: %s\n", del.RequestURL) - fmt.Fprintf(out, "Request Method: %s\n", del.RequestMethod) - fmt.Fprintf(out, "Request Error: %s\n", del.RequestError.String) - fmt.Fprintf(out, "Request Headers:\n") + fmt.Fprintf(out, "ID: %s\n", del.ID) //nolint:errcheck + fmt.Fprintf(out, "Event: %s\n", del.Event) //nolint:errcheck + fmt.Fprintf(out, "Request URL: %s\n", del.RequestURL) //nolint:errcheck + fmt.Fprintf(out, "Request Method: %s\n", del.RequestMethod) //nolint:errcheck + fmt.Fprintf(out, "Request Error: %s\n", del.RequestError.String) //nolint:errcheck + fmt.Fprintf(out, "Request Headers:\n") //nolint:errcheck reqHeaders := strings.Split(del.RequestHeaders, "\n") for _, h := range reqHeaders { - fmt.Fprintf(out, " %s\n", h) + fmt.Fprintf(out, " %s\n", h) //nolint:errcheck } - fmt.Fprintf(out, "Request Body:\n") + fmt.Fprintf(out, "Request Body:\n") //nolint:errcheck reqBody := strings.Split(del.RequestBody, "\n") for _, b := range reqBody { - fmt.Fprintf(out, " %s\n", b) + fmt.Fprintf(out, " %s\n", b) //nolint:errcheck } - fmt.Fprintf(out, "Response Status: %d\n", del.ResponseStatus) - fmt.Fprintf(out, "Response Headers:\n") + fmt.Fprintf(out, "Response Status: %d\n", del.ResponseStatus) //nolint:errcheck + fmt.Fprintf(out, "Response Headers:\n") //nolint:errcheck resHeaders := strings.Split(del.ResponseHeaders, "\n") for _, h := range resHeaders { - fmt.Fprintf(out, " %s\n", h) + fmt.Fprintf(out, " %s\n", h) //nolint:errcheck } - fmt.Fprintf(out, "Response Body:\n") + fmt.Fprintf(out, "Response Body:\n") //nolint:errcheck resBody := strings.Split(del.ResponseBody, "\n") for _, b := range resBody { - fmt.Fprintf(out, " %s\n", b) + fmt.Fprintf(out, " %s\n", b) //nolint:errcheck } return nil diff --git a/pkg/ui/common/utils.go b/pkg/ui/common/utils.go index dac9ac2f07fb2cd49c2ad92ffe2b0ee03f7c491a..d5b9c91e0a78ed746fa09ddffe6b82909578ffae 100644 --- a/pkg/ui/common/utils.go +++ b/pkg/ui/common/utils.go @@ -9,11 +9,11 @@ import ( ) // TruncateString is a convenient wrapper around truncate.TruncateString. -func TruncateString(s string, max int) string { +func TruncateString(s string, max int) string { //nolint:revive if max < 0 { - max = 0 + max = 0 //nolint:revive } - return truncate.StringWithTail(s, uint(max), "…") + return truncate.StringWithTail(s, uint(max), "…") //nolint:gosec } // RepoURL returns the URL of the repository. diff --git a/pkg/ui/components/statusbar/statusbar.go b/pkg/ui/components/statusbar/statusbar.go index 2b9e18849df6682813756940e01d666608c3199c..20a5735e12da1729616ea9ead98ccfcadfda6a47 100644 --- a/pkg/ui/components/statusbar/statusbar.go +++ b/pkg/ui/components/statusbar/statusbar.go @@ -75,7 +75,7 @@ func (s *Model) View() string { } branch := st.StatusBarBranch.Render(s.extra) maxWidth := s.common.Width - w(key) - w(info) - w(branch) - w(help) - v := truncate.StringWithTail(s.value, uint(maxWidth-st.StatusBarValue.GetHorizontalFrameSize()), "…") + v := truncate.StringWithTail(s.value, uint(maxWidth-st.StatusBarValue.GetHorizontalFrameSize()), "…") //nolint:gosec value := st.StatusBarValue. Width(maxWidth). Render(v) diff --git a/pkg/ui/pages/repo/filesitem.go b/pkg/ui/pages/repo/filesitem.go index a32fcea615308bb8696fc3739533be5107c91807..ca399fa1b74986f152d7005919048f2ab79762e0 100644 --- a/pkg/ui/pages/repo/filesitem.go +++ b/pkg/ui/pages/repo/filesitem.go @@ -101,7 +101,7 @@ func (d FileItemDelegate) Render(w io.Writer, m list.Model, index int, listItem s := d.common.Styles.Tree name := i.Title() - size := humanize.Bytes(uint64(i.entry.Size())) + size := humanize.Bytes(uint64(i.entry.Size())) //nolint:gosec size = strings.ReplaceAll(size, " ", "") sizeLen := lipgloss.Width(size) if i.entry.IsTree() { diff --git a/pkg/ui/pages/repo/logitem.go b/pkg/ui/pages/repo/logitem.go index ecdc4f1878c46ad9bc3869b81c69978571b5e3b6..0ff4da6814fd62c8be3fe4e9f4a741ace3cda6ca 100644 --- a/pkg/ui/pages/repo/logitem.go +++ b/pkg/ui/pages/repo/logitem.go @@ -130,7 +130,7 @@ func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l } who += styles.Desc.Render("on ") + styles.Keyword.Render(date) who = common.TruncateString(who, m.Width()-horizontalFrameSize) - fmt.Fprint(w, + fmt.Fprint(w, //nolint:errcheck d.common.Zone.Mark( i.ID(), styles.Base.Render( @@ -138,7 +138,7 @@ func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l truncate.String(fmt.Sprintf("%s%s", title, hash, - ), uint(m.Width()-horizontalFrameSize)), + ), uint(m.Width()-horizontalFrameSize)), //nolint:gosec who, ), ), diff --git a/pkg/ui/pages/repo/refsitem.go b/pkg/ui/pages/repo/refsitem.go index 7d109de0c277251d6798b1a6aac8cfdfed082bc3..7bb10d6e94fb4013789f6c4f4c4dfd7935d8d09d 100644 --- a/pkg/ui/pages/repo/refsitem.go +++ b/pkg/ui/pages/repo/refsitem.go @@ -191,13 +191,13 @@ func (d RefItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l PaddingLeft(1). Render(sha) } - fmt.Fprint(w, + fmt.Fprint(w, //nolint:errcheck d.common.Zone.Mark( i.ID(), st.Base.Render( lipgloss.JoinHorizontal(lipgloss.Top, truncate.String(selector+ref+desc+hash, - uint(m.Width()-horizontalFrameSize)), + uint(m.Width()-horizontalFrameSize)), //nolint:gosec ), ), ), diff --git a/pkg/ui/pages/repo/stashitem.go b/pkg/ui/pages/repo/stashitem.go index cc2d3f3a0f107bad5642452a88e5ce53ab6e1b7b..e6b6a9a822f12310c28b12d7be33e4ce4f517e92 100644 --- a/pkg/ui/pages/repo/stashitem.go +++ b/pkg/ui/pages/repo/stashitem.go @@ -93,7 +93,7 @@ func (d StashItemDelegate) Render(w io.Writer, m list.Model, index int, listItem selector = s.Selector.Render(selector) title := st.Render(item.Title()) - fmt.Fprint(w, d.common.Zone.Mark( + fmt.Fprint(w, d.common.Zone.Mark( //nolint:errcheck item.ID(), common.TruncateString(fmt.Sprintf("%s%s", selector, diff --git a/pkg/ui/pages/selection/item.go b/pkg/ui/pages/selection/item.go index 4cd12a91dbbf0aa5b4cfa563c41dc2fe9e3a983c..1842d7243ac18ac997861a130d5ffc9efb34d51e 100644 --- a/pkg/ui/pages/selection/item.go +++ b/pkg/ui/pages/selection/item.go @@ -212,7 +212,7 @@ func (d *ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem lis } cmd = common.TruncateString(cmd, m.Width()-styles.Base.GetHorizontalFrameSize()) s.WriteString(cmdStyler(cmd)) - fmt.Fprint(w, + fmt.Fprint(w, //nolint:errcheck d.common.Zone.Mark(i.ID(), styles.Base.Render(s.String()), ), diff --git a/pkg/web/logging.go b/pkg/web/logging.go index 956ad9e9c160e2e411b7a4510c431ba0c880484d..63b6d35e5b5fcf22308fffc7caefe729832d90d5 100644 --- a/pkg/web/logging.go +++ b/pkg/web/logging.go @@ -81,7 +81,7 @@ func NewLoggingMiddleware(next http.Handler, logger *log.Logger) http.Handler { elapsed := time.Since(start) logger.Debug("response", "status", fmt.Sprintf("%d %s", writer.code, http.StatusText(writer.code)), - "bytes", humanize.Bytes(uint64(writer.bytes)), + "bytes", humanize.Bytes(uint64(writer.bytes)), //nolint:gosec "time", elapsed) }) } diff --git a/pkg/webhook/webhook.go b/pkg/webhook/webhook.go index 8bd28e9c19663e3f7034a99213c3009f3486e391..15d93bb1db3a16485dad1558f516e4a652ae3bb6 100644 --- a/pkg/webhook/webhook.go +++ b/pkg/webhook/webhook.go @@ -59,7 +59,7 @@ func SendWebhook(ctx context.Context, w models.Webhook, event Event, payload int dbx := db.FromContext(ctx) datastore := store.FromContext(ctx) - contentType := ContentType(w.ContentType) + contentType := ContentType(w.ContentType) //nolint:gosec switch contentType { case ContentTypeJSON: if err := json.NewEncoder(&buf).Encode(payload); err != nil {