Skip to content

Commit

Permalink
lint: mega cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
robherley committed Apr 16, 2023
1 parent 41cdd4a commit 6372b9d
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 43 deletions.
6 changes: 4 additions & 2 deletions internal/db/db_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"ariga.io/atlas/sql/migrate"
aschema "ariga.io/atlas/sql/schema"
asqlite "ariga.io/atlas/sql/sqlite"
_ "github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3" // sqlite driver
)

var (
Expand Down Expand Up @@ -269,7 +269,9 @@ func (s *Sqlite) CreateUserWithPublicKey(ctx context.Context, publickey *snips.P
if err != nil {
return nil, err
}
defer tx.Rollback()
defer func() {
_ = tx.Rollback()
}()

user := &snips.User{
ID: id.New(),
Expand Down
20 changes: 15 additions & 5 deletions internal/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ func IndexHandler(readme string, tmpl *template.Template) http.HandlerFunc {
"HTML": md,
}

tmpl.ExecuteTemplate(w, "file.go.html", vars)
err = tmpl.ExecuteTemplate(w, "file.go.html", vars)
if err != nil {
log.Error().Err(err).Msg("unable to render template")
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
}
}

func HealthHandler(w http.ResponseWriter, r *http.Request) {
func HealthHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("💚\n"))
_, _ = w.Write([]byte("💚\n"))
}

func FileHandler(cfg *config.Config, database db.DB, tmpl *template.Template) http.HandlerFunc {
Expand Down Expand Up @@ -81,7 +86,7 @@ func FileHandler(cfg *config.Config, database db.DB, tmpl *template.Template) ht
if ShouldSendRaw(r) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write(file.Content)
_, _ = w.Write(file.Content)
return
}

Expand Down Expand Up @@ -132,7 +137,12 @@ func FileHandler(cfg *config.Config, database db.DB, tmpl *template.Template) ht
"Private": file.Private,
}

tmpl.ExecuteTemplate(w, "file.go.html", vars)
err = tmpl.ExecuteTemplate(w, "file.go.html", vars)
if err != nil {
log.Error().Err(err).Msg("unable to render template")
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/renderer/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ToSyntaxHighlightedHTML(fileType string, fileContent []byte) (template.HTML

chromaHTML := bytes.NewBuffer(nil)
// using fallback style because we'll use custom prebaked CSS
formatter.Format(chromaHTML, styles.Fallback, it)
err = formatter.Format(chromaHTML, styles.Fallback, it)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/renderer/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ToSyntaxHighlightedTerm(fileType string, fileContent []byte) (string, error
formatter := formatters.Get(TermFormatter)

chromaTerm := bytes.NewBuffer(nil)
formatter.Format(chromaTerm, style, it)
err = formatter.Format(chromaTerm, style, it)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (signer *Signer) SignURL(u url.URL) url.URL {
signature := signer.computeMac(u.String())

params := u.Query()
params.Set(SignatureQueryParameter, string(base64.URLEncoding.EncodeToString(signature)))
params.Set(SignatureQueryParameter, base64.URLEncoding.EncodeToString(signature))
u.RawQuery = params.Encode()

return u
Expand Down
6 changes: 1 addition & 5 deletions internal/ssh/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,5 @@ func (df *DeleteFlags) Parse(out io.Writer, args []string) error {

df.BoolVar(&df.Force, "f", false, "force delete without confirmation")

if err := df.FlagSet.Parse(args); err != nil {
return err
}

return nil
return df.FlagSet.Parse(args)
}
2 changes: 1 addition & 1 deletion internal/ssh/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func BlockIfNoPublicKey(next ssh.Handler) ssh.Handler {
if key := sesh.PublicKey(); key == nil {
wish.Println(sesh, "❌ Unfortunately snips.sh only supports public key authentication.")
wish.Println(sesh, "🔐 Please generate a keypair and try again.")
sesh.Exit(1)
_ = sesh.Exit(1)
return
}
next(sesh)
Expand Down
4 changes: 2 additions & 2 deletions internal/ssh/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAssignUser(t *testing.T) {
},
})

session.Run("")
_ = session.Run("")
})

t.Run("matches existing user by fingerprint", func(t *testing.T) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestAssignUser(t *testing.T) {
},
})

session.Run("")
_ = session.Run("")
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ssh/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (sesh *UserSession) Error(err error, title string, f string, v ...interface
}

noti.Render(sesh)
sesh.Exit(1)
_ = sesh.Exit(1)
}

func (sesh *UserSession) IsPTY() bool {
Expand Down
12 changes: 6 additions & 6 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (t TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

if len(t.viewStack) == 1 {
return t, tea.Quit
} else {
batchedCmds = append(batchedCmds, cmds.PopView())
if t.currentView() == views.Browser {
batchedCmds = append(batchedCmds, cmds.DeselectFile())
}
return t, tea.Batch(batchedCmds...)
}

batchedCmds = append(batchedCmds, cmds.PopView())
if t.currentView() == views.Browser {
batchedCmds = append(batchedCmds, cmds.DeselectFile())
}
return t, tea.Batch(batchedCmds...)
}

// otherwise, send key msgs to the current view
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/views/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (bwsr Browser) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

if bwsr.options.focused {
return bwsr.handleOptionsNavigation(msg)
} else {
return bwsr.handleTableNavigation(msg)
}

return bwsr.handleTableNavigation(msg)
case tea.WindowSizeMsg:
bwsr.width, bwsr.height = msg.Width, msg.Height
case msgs.ReloadFiles:
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/views/browser/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func (bwsr Browser) handleOptionsNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd)
return bwsr, nil
}

func (bwser Browser) getOptions() []option {
if len(bwser.files) == 0 {
func (bwsr Browser) getOptions() []option {
if len(bwsr.files) == 0 {
return nil
}

file := bwser.files[bwser.table.index]
file := bwsr.files[bwsr.table.index]

var opts []option
for _, o := range options {
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/views/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (m *Code) renderContent(file *snips.File) string {
return ""
}

content, err := renderer.ToSyntaxHighlightedTerm(file.Type, []byte(file.Content))
content, err := renderer.ToSyntaxHighlightedTerm(file.Type, file.Content)
if err != nil {
log.Warn().Err(err).Msg("failed to render file as syntax highlighted")
content = string(file.Content)
Expand All @@ -90,7 +90,7 @@ func (m *Code) renderContent(file *snips.File) string {
Copy().
BorderRight(true).
MarginRight(1).
Render(fmt.Sprintf("%*d", int(maxDigits), i+1))
Render(fmt.Sprintf("%*d", maxDigits, i+1))

scrubbed := strings.ReplaceAll(line, "\t", " ")
renderedLines = append(renderedLines, lineNumber+scrubbed)
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/views/prompt/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (

func SetPromptKindCmd(pk Kind) tea.Cmd {
return func() tea.Msg {
return PromptKindSetMsg{
return KindSetMsg{
Kind: pk,
}
}
}

func SetPromptFeedbackCmd(feedback string, finished bool) tea.Cmd {
return func() tea.Msg {
return PromptFeedbackMsg{
return FeedbackMsg{
Feedback: feedback,
Finished: finished,
}
Expand All @@ -24,7 +24,7 @@ func SetPromptFeedbackCmd(feedback string, finished bool) tea.Cmd {

func SetPromptErrorCmd(err error) tea.Cmd {
return func() tea.Msg {
return PromptFeedbackMsg{
return FeedbackMsg{
Feedback: styles.C(styles.Colors.Red, err.Error()),
Finished: false,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/views/prompt/fileselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewExtensionSelector(width int) list.Model {
items := []list.Item{}

for _, ext := range extensions {
items = append(items, selectorItem(ext))
items = append(items, ext)
}

li := list.New(items, selectorItemDelegate{}, width, 8)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (d selectorItemDelegate) Spacing() int {
return 0
}

func (d selectorItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
func (d selectorItemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/tui/views/prompt/msgs.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package prompt

type PromptKindSetMsg struct {
type KindSetMsg struct {
Kind Kind
}

type PromptFeedbackMsg struct {
type FeedbackMsg struct {
Feedback string
Finished bool
}
7 changes: 3 additions & 4 deletions internal/tui/views/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ func (m Prompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEnter:
if msg.Type == tea.KeyEnter {
return m, m.handleSubmit()
}
case PromptFeedbackMsg:
case FeedbackMsg:
m.feedback = msg.Feedback
m.finished = msg.Finished
case PromptKindSetMsg:
case KindSetMsg:
m.pk = msg.Kind
case msgs.FileLoaded:
m.file = msg.File
Expand Down

0 comments on commit 6372b9d

Please sign in to comment.