Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 21, 2023
1 parent 904a846 commit 31a737e
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 34 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ linters:
- goimports
- goprintffuncname
- gosec
- ifshort
- misspell
- prealloc
- revive
Expand Down
6 changes: 4 additions & 2 deletions client/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ func (cc *Client) SyncEncryptKeys() error {
return cc.deleteUserData()
}

// TODO find a better place for this, or do something more sophisticated than
// just wiping it out.
func (cc *Client) deleteUserData() error {
// nolint: godox
// TODO find a better place for this, or do something more sophisticated than
// just wiping it out.
dd, err := cc.DataPath()
if err != nil {
return err
}
// nolint: godox
// TODO add any other directories that need wiping
kvd := fmt.Sprintf("%s/kv", dd)
return os.RemoveAll(kvd)
Expand Down
8 changes: 4 additions & 4 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ var CompletionCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
cmd.Root().GenBashCompletion(os.Stdout) // nolint: errcheck
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
cmd.Root().GenZshCompletion(os.Stdout) // nolint: errcheck
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
cmd.Root().GenFishCompletion(os.Stdout, true) // nolint: errcheck
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
cmd.Root().GenPowerShellCompletion(os.Stdout) // nolint: errcheck
}
},
}
6 changes: 5 additions & 1 deletion cmd/import_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ var (
}
if !empty && !forceImportOverwrite {
if common.IsTTY() {
return newImportConfirmationTUI(cmd.InOrStdin(), path, dd).Start()
p := newImportConfirmationTUI(cmd.InOrStdin(), path, dd)
if _, err := p.Run(); err != nil {
return err
}
return nil
}
return fmt.Errorf("not overwriting the existing keys in %s; to force, use -f", dd)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ var KeysCmd = &cobra.Command{
}
defer f.Close() // nolint:errcheck
}
return keys.NewProgram(cfg).Start()
p := keys.NewProgram(cfg)
if _, err := p.Run(); err != nil {
return err
}
return nil
}
cc := initCharmClient()

Expand Down
11 changes: 7 additions & 4 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ func LinkCmd(parentName string) *cobra.Command {
defer f.Close() //nolint:errcheck
}

var p *tea.Program
switch len(args) {
case 0:
// Initialize a linking session
p := linkgen.NewProgram(cfg, parentName)
return p.Start()
p = linkgen.NewProgram(cfg, parentName)
default:
// Join in on a linking session
p := link.NewProgram(cfg, args[0])
return p.Start()
p = link.NewProgram(cfg, args[0])
}
if _, err := p.Run(); err != nil {
return err
}
return nil
},
}
}
4 changes: 2 additions & 2 deletions cmd/migrate_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ var (
lc := make(chan string)
go func() {
lh := &linkHandler{desc: "link-gen", linkChan: lc}
rsaClient.LinkGen(lh)
_ = rsaClient.LinkGen(lh)
}()
tok := <-lc
lh := &linkHandler{desc: "link-request", linkChan: lc}
ed25519Client.Link(lh, tok)
_ = ed25519Client.Link(lh, tok)
if verbose {
log.Info("link-gen sync encrypt keys")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"
)

// WhereCmd is a command to find the absolute path to your charm data folder.
var WhereCmd = &cobra.Command{
Use: "where",
Short: "Find where your cloud.charm.sh folder resides on your machine",
Expand Down
1 change: 1 addition & 0 deletions kv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (kv *KV) restoreSeq(seq uint64) error {
return err
}
defer r.Close() // nolint:errcheck
// nolint: godox
// TODO DB.Load() should be called on a database that is not running any
// other concurrent transactions while it is running.
return kv.DB.Load(r, 1)
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
)

var (
Version = ""
// Version is the version of the charm CLI.
Version = ""
// CommitSHA is the commit SHA of the charm CLI.
CommitSHA = ""

styles = common.DefaultStyles()
Expand Down Expand Up @@ -46,10 +48,13 @@ var (
log.SetOutput(f)
log.SetPrefix("charm")

defer f.Close()
defer f.Close() // nolint: errcheck
}

return ui.NewProgram(cfg).Start()
p := ui.NewProgram(cfg)
if _, err := p.Run(); err != nil {
return err
}
}

return cmd.Help()
Expand Down
4 changes: 2 additions & 2 deletions proto/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package proto

import (
"crypto/sha1"
"crypto/sha1" // nolint: gosec
"fmt"
"time"
)
Expand Down Expand Up @@ -32,5 +32,5 @@ func (pk *PublicKey) Sha() string {

// PublicKeySha returns the SHA for a public key in hex format.
func PublicKeySha(key string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(key)))
return fmt.Sprintf("%x", sha1.Sum([]byte(key))) // nolint: gosec
}
2 changes: 2 additions & 0 deletions server/db/sqlite/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (me *DB) SetUserName(charmID string, name string) (*charm.User, error) {
var u *charm.User
log.Debug("Setting name for user", "name", name, "id", charmID)
err := me.WrapTransaction(func(tx *sql.Tx) error {
// nolint: godox
// TODO: this should be handled with unique constraints in the database instead.
var err error
r := me.selectUserWithName(tx, name)
Expand Down Expand Up @@ -254,6 +255,7 @@ func (me *DB) UnlinkUserKey(user *charm.User, key string) error {
}
if count == 0 {
log.Debug("Removing last key for account, deleting", "id", user.CharmID)
// nolint: godox
// TODO: Where to put glow stuff
// err := me.deleteUserStashMarkdown(tx, user.ID)
// if err != nil {
Expand Down
21 changes: 13 additions & 8 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/charmbracelet/log"

Expand Down Expand Up @@ -55,9 +56,10 @@ func NewHTTPServer(cfg *Config) (*HTTPServer, error) {
fmt.Fprintf(w, "We live!")
}))
health := &http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.HealthPort),
Handler: healthMux,
ErrorLog: cfg.errorLog,
Addr: fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.HealthPort),
Handler: healthMux,
ErrorLog: cfg.errorLog,
ReadHeaderTimeout: time.Minute,
}
mux := goji.NewMux()
s := &HTTPServer{
Expand All @@ -66,9 +68,10 @@ func NewHTTPServer(cfg *Config) (*HTTPServer, error) {
httpScheme: "http",
}
s.server = &http.Server{
Addr: fmt.Sprintf("%s:%d", s.cfg.BindAddr, s.cfg.HTTPPort),
Handler: mux,
ErrorLog: s.cfg.errorLog,
Addr: fmt.Sprintf("%s:%d", s.cfg.BindAddr, s.cfg.HTTPPort),
Handler: mux,
ErrorLog: s.cfg.errorLog,
ReadHeaderTimeout: time.Minute,
}
if cfg.UseTLS {
s.httpScheme = "https"
Expand Down Expand Up @@ -180,16 +183,18 @@ func (s *HTTPServer) handleOpenIDConfig(w http.ResponseWriter, r *http.Request)
_ = json.NewEncoder(w).Encode(pj)
}

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

// TODO do we need this since you can only get the authed user?
func (s *HTTPServer) handleGetUser(w http.ResponseWriter, r *http.Request) {
// nolint: godox
// TODO do we need this since you can only get the authed user?
u := s.charmUserFromRequest(w, r)
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(u)
Expand Down
4 changes: 2 additions & 2 deletions ui/keys/keyview.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func (m Model) newStyledKey(styles common.Styles, key charm.PublicKey, active bo
}
}

// Selected state
// Selected state.
func (k *styledKey) selected() {
k.gutter = common.VerticalLine(common.StateSelected)
k.keyLabel = k.styles.Label.Render("Key:")
k.dateLabel = k.styles.Label.Render("Added:")
}

// Deleting state
// Deleting state.
func (k *styledKey) deleting() {
k.gutter = common.VerticalLine(common.StateDeleting)
k.keyLabel = k.styles.Delete.Render("Key:")
Expand Down
5 changes: 2 additions & 3 deletions ui/linkgen/linkgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Model struct {
}

// acceptRequest rejects the current linking request.
func (m Model) acceptRequest() (Model, tea.Cmd) {
func (m Model) acceptRequest() (Model, tea.Cmd) { // nolint: unparam
m.lh.response <- true
return m, nil
}
Expand Down Expand Up @@ -321,8 +321,7 @@ func InitLinkGen(m Model) tea.Cmd {
// HandleLinkRequest returns a bunch of blocking commands that resolve on link
// request states. As a Tea command, this should be treated as batch:
//
// tea.Batch(HandleLinkRequest(model)...)
//
// tea.Batch(HandleLinkRequest(model)...)
func HandleLinkRequest(m Model) []tea.Cmd {
go func() {
if err := m.cc.LinkGen(m.lh); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s status) String() string {
// menuChoice represents a chosen menu item.
type menuChoice int

// menu choices
// menu choices.
const (
linkChoice menuChoice = iota
keysChoice
Expand Down

0 comments on commit 31a737e

Please sign in to comment.