Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 31a737e

Browse files
committed
fix: lint
1 parent 904a846 commit 31a737e

File tree

16 files changed

+59
-34
lines changed

16 files changed

+59
-34
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ linters:
2323
- goimports
2424
- goprintffuncname
2525
- gosec
26-
- ifshort
2726
- misspell
2827
- prealloc
2928
- revive

client/link.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ func (cc *Client) SyncEncryptKeys() error {
145145
return cc.deleteUserData()
146146
}
147147

148-
// TODO find a better place for this, or do something more sophisticated than
149-
// just wiping it out.
150148
func (cc *Client) deleteUserData() error {
149+
// nolint: godox
150+
// TODO find a better place for this, or do something more sophisticated than
151+
// just wiping it out.
151152
dd, err := cc.DataPath()
152153
if err != nil {
153154
return err
154155
}
156+
// nolint: godox
155157
// TODO add any other directories that need wiping
156158
kvd := fmt.Sprintf("%s/kv", dd)
157159
return os.RemoveAll(kvd)

cmd/completion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ var CompletionCmd = &cobra.Command{
5555
Run: func(cmd *cobra.Command, args []string) {
5656
switch args[0] {
5757
case "bash":
58-
cmd.Root().GenBashCompletion(os.Stdout)
58+
cmd.Root().GenBashCompletion(os.Stdout) // nolint: errcheck
5959
case "zsh":
60-
cmd.Root().GenZshCompletion(os.Stdout)
60+
cmd.Root().GenZshCompletion(os.Stdout) // nolint: errcheck
6161
case "fish":
62-
cmd.Root().GenFishCompletion(os.Stdout, true)
62+
cmd.Root().GenFishCompletion(os.Stdout, true) // nolint: errcheck
6363
case "powershell":
64-
cmd.Root().GenPowerShellCompletion(os.Stdout)
64+
cmd.Root().GenPowerShellCompletion(os.Stdout) // nolint: errcheck
6565
}
6666
},
6767
}

cmd/import_keys.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ var (
6868
}
6969
if !empty && !forceImportOverwrite {
7070
if common.IsTTY() {
71-
return newImportConfirmationTUI(cmd.InOrStdin(), path, dd).Start()
71+
p := newImportConfirmationTUI(cmd.InOrStdin(), path, dd)
72+
if _, err := p.Run(); err != nil {
73+
return err
74+
}
75+
return nil
7276
}
7377
return fmt.Errorf("not overwriting the existing keys in %s; to force, use -f", dd)
7478
}

cmd/keys.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ var KeysCmd = &cobra.Command{
3333
}
3434
defer f.Close() // nolint:errcheck
3535
}
36-
return keys.NewProgram(cfg).Start()
36+
p := keys.NewProgram(cfg)
37+
if _, err := p.Run(); err != nil {
38+
return err
39+
}
40+
return nil
3741
}
3842
cc := initCharmClient()
3943

cmd/link.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ func LinkCmd(parentName string) *cobra.Command {
3030
defer f.Close() //nolint:errcheck
3131
}
3232

33+
var p *tea.Program
3334
switch len(args) {
3435
case 0:
3536
// Initialize a linking session
36-
p := linkgen.NewProgram(cfg, parentName)
37-
return p.Start()
37+
p = linkgen.NewProgram(cfg, parentName)
3838
default:
3939
// Join in on a linking session
40-
p := link.NewProgram(cfg, args[0])
41-
return p.Start()
40+
p = link.NewProgram(cfg, args[0])
4241
}
42+
if _, err := p.Run(); err != nil {
43+
return err
44+
}
45+
return nil
4346
},
4447
}
4548
}

cmd/migrate_account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ var (
4747
lc := make(chan string)
4848
go func() {
4949
lh := &linkHandler{desc: "link-gen", linkChan: lc}
50-
rsaClient.LinkGen(lh)
50+
_ = rsaClient.LinkGen(lh)
5151
}()
5252
tok := <-lc
5353
lh := &linkHandler{desc: "link-request", linkChan: lc}
54-
ed25519Client.Link(lh, tok)
54+
_ = ed25519Client.Link(lh, tok)
5555
if verbose {
5656
log.Info("link-gen sync encrypt keys")
5757
}

cmd/where.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9+
// WhereCmd is a command to find the absolute path to your charm data folder.
910
var WhereCmd = &cobra.Command{
1011
Use: "where",
1112
Short: "Find where your cloud.charm.sh folder resides on your machine",

kv/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (kv *KV) restoreSeq(seq uint64) error {
9999
return err
100100
}
101101
defer r.Close() // nolint:errcheck
102+
// nolint: godox
102103
// TODO DB.Load() should be called on a database that is not running any
103104
// other concurrent transactions while it is running.
104105
return kv.DB.Load(r, 1)

main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
)
1818

1919
var (
20-
Version = ""
20+
// Version is the version of the charm CLI.
21+
Version = ""
22+
// CommitSHA is the commit SHA of the charm CLI.
2123
CommitSHA = ""
2224

2325
styles = common.DefaultStyles()
@@ -46,10 +48,13 @@ var (
4648
log.SetOutput(f)
4749
log.SetPrefix("charm")
4850

49-
defer f.Close()
51+
defer f.Close() // nolint: errcheck
5052
}
5153

52-
return ui.NewProgram(cfg).Start()
54+
p := ui.NewProgram(cfg)
55+
if _, err := p.Run(); err != nil {
56+
return err
57+
}
5358
}
5459

5560
return cmd.Help()

proto/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package proto
22

33
import (
4-
"crypto/sha1"
4+
"crypto/sha1" // nolint: gosec
55
"fmt"
66
"time"
77
)
@@ -32,5 +32,5 @@ func (pk *PublicKey) Sha() string {
3232

3333
// PublicKeySha returns the SHA for a public key in hex format.
3434
func PublicKeySha(key string) string {
35-
return fmt.Sprintf("%x", sha1.Sum([]byte(key)))
35+
return fmt.Sprintf("%x", sha1.Sum([]byte(key))) // nolint: gosec
3636
}

server/db/sqlite/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (me *DB) SetUserName(charmID string, name string) (*charm.User, error) {
9191
var u *charm.User
9292
log.Debug("Setting name for user", "name", name, "id", charmID)
9393
err := me.WrapTransaction(func(tx *sql.Tx) error {
94+
// nolint: godox
9495
// TODO: this should be handled with unique constraints in the database instead.
9596
var err error
9697
r := me.selectUserWithName(tx, name)
@@ -254,6 +255,7 @@ func (me *DB) UnlinkUserKey(user *charm.User, key string) error {
254255
}
255256
if count == 0 {
256257
log.Debug("Removing last key for account, deleting", "id", user.CharmID)
258+
// nolint: godox
257259
// TODO: Where to put glow stuff
258260
// err := me.deleteUserStashMarkdown(tx, user.ID)
259261
// if err != nil {

server/http.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"strconv"
1313
"strings"
14+
"time"
1415

1516
"github.com/charmbracelet/log"
1617

@@ -55,9 +56,10 @@ func NewHTTPServer(cfg *Config) (*HTTPServer, error) {
5556
fmt.Fprintf(w, "We live!")
5657
}))
5758
health := &http.Server{
58-
Addr: fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.HealthPort),
59-
Handler: healthMux,
60-
ErrorLog: cfg.errorLog,
59+
Addr: fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.HealthPort),
60+
Handler: healthMux,
61+
ErrorLog: cfg.errorLog,
62+
ReadHeaderTimeout: time.Minute,
6163
}
6264
mux := goji.NewMux()
6365
s := &HTTPServer{
@@ -66,9 +68,10 @@ func NewHTTPServer(cfg *Config) (*HTTPServer, error) {
6668
httpScheme: "http",
6769
}
6870
s.server = &http.Server{
69-
Addr: fmt.Sprintf("%s:%d", s.cfg.BindAddr, s.cfg.HTTPPort),
70-
Handler: mux,
71-
ErrorLog: s.cfg.errorLog,
71+
Addr: fmt.Sprintf("%s:%d", s.cfg.BindAddr, s.cfg.HTTPPort),
72+
Handler: mux,
73+
ErrorLog: s.cfg.errorLog,
74+
ReadHeaderTimeout: time.Minute,
7275
}
7376
if cfg.UseTLS {
7477
s.httpScheme = "https"
@@ -180,16 +183,18 @@ func (s *HTTPServer) handleOpenIDConfig(w http.ResponseWriter, r *http.Request)
180183
_ = json.NewEncoder(w).Encode(pj)
181184
}
182185

183-
// TODO do we need this since you can only get the authed user?
184186
func (s *HTTPServer) handleGetUserByID(w http.ResponseWriter, r *http.Request) {
187+
// nolint: godox
188+
// TODO do we need this since you can only get the authed user?
185189
u := s.charmUserFromRequest(w, r)
186190
w.Header().Set("Content-Type", "application/json")
187191
_ = json.NewEncoder(w).Encode(u)
188192
s.cfg.Stats.GetUserByID()
189193
}
190194

191-
// TODO do we need this since you can only get the authed user?
192195
func (s *HTTPServer) handleGetUser(w http.ResponseWriter, r *http.Request) {
196+
// nolint: godox
197+
// TODO do we need this since you can only get the authed user?
193198
u := s.charmUserFromRequest(w, r)
194199
w.Header().Set("Content-Type", "application/json")
195200
_ = json.NewEncoder(w).Encode(u)

ui/keys/keyview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func (m Model) newStyledKey(styles common.Styles, key charm.PublicKey, active bo
6161
}
6262
}
6363

64-
// Selected state
64+
// Selected state.
6565
func (k *styledKey) selected() {
6666
k.gutter = common.VerticalLine(common.StateSelected)
6767
k.keyLabel = k.styles.Label.Render("Key:")
6868
k.dateLabel = k.styles.Label.Render("Added:")
6969
}
7070

71-
// Deleting state
71+
// Deleting state.
7272
func (k *styledKey) deleting() {
7373
k.gutter = common.VerticalLine(common.StateDeleting)
7474
k.keyLabel = k.styles.Delete.Render("Key:")

ui/linkgen/linkgen.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Model struct {
6666
}
6767

6868
// acceptRequest rejects the current linking request.
69-
func (m Model) acceptRequest() (Model, tea.Cmd) {
69+
func (m Model) acceptRequest() (Model, tea.Cmd) { // nolint: unparam
7070
m.lh.response <- true
7171
return m, nil
7272
}
@@ -321,8 +321,7 @@ func InitLinkGen(m Model) tea.Cmd {
321321
// HandleLinkRequest returns a bunch of blocking commands that resolve on link
322322
// request states. As a Tea command, this should be treated as batch:
323323
//
324-
// tea.Batch(HandleLinkRequest(model)...)
325-
//
324+
// tea.Batch(HandleLinkRequest(model)...)
326325
func HandleLinkRequest(m Model) []tea.Cmd {
327326
go func() {
328327
if err := m.cc.LinkGen(m.lh); err != nil {

ui/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s status) String() string {
6767
// menuChoice represents a chosen menu item.
6868
type menuChoice int
6969

70-
// menu choices
70+
// menu choices.
7171
const (
7272
linkChoice menuChoice = iota
7373
keysChoice

0 commit comments

Comments
 (0)