diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f3ceda3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,82 @@ +linters: + disable-all: true + enable: + - gofmt + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - gocritic + - bodyclose + - gosec + - prealloc + - unconvert + - unused + +linters-settings: + gocritic: + # Which checks should be enabled; can't be combined with 'disabled-checks'; + # See https://go-critic.github.io/overview#checks-overview + # To check which checks are enabled run `GL_DEBUG=gocritic ./build/bin/golangci-lint run` + # By default list of stable checks is used. + enabled-checks: + - ruleguard + - truncateCmp + + # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + disabled-checks: + - captLocal + - assignOp + - paramTypeCombine + - importShadow + - commentFormatting + + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - performance + - diagnostic + - opinionated + disabled-tags: + - experimental + settings: + hugeParam: + # size in bytes that makes the warning trigger (default 80) + sizeThreshold: 1000 + rangeValCopy: + sizeThreshold: 1024 + rangeExprCopy: + # size in bytes that makes the warning trigger (default 512) + sizeThreshold: 512 + # whether to check test functions (default true) + skipTestFuncs: true + truncateCmp: + # whether to skip int/uint/uintptr types (default true) + skipArchDependent: true + underef: + # whether to skip (*x).method() calls where x is a pointer receiver (default true) + skipRecvDeref: true + + govet: + disable: + - deepequalerrors + - fieldalignment + - shadow + - unsafeptr + goconst: + min-len: 2 + min-occurrences: 2 + +issues: + exclude-rules: + - linters: + - golint + text: "should be" + - linters: + - errcheck + text: "not checked" + - linters: + - staticcheck + text: "SA(1019|1029|5011)" + diff --git a/src/components/cli/cli.go b/src/components/cli/cli.go index 02f2e81..5bc65d1 100644 --- a/src/components/cli/cli.go +++ b/src/components/cli/cli.go @@ -16,12 +16,6 @@ import ( var Version = "dev" func Run(c *commands.Commander, s fx.Shutdowner) { - defer func() { - err := s.Shutdown() - if err != nil { - c.Log.Error("SHUTDOWN", "error shutting down", err) - } - }() app := &cli.App{ Name: "gspot", EnableBashCompletion: true, @@ -347,6 +341,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { } if err := app.Run(os.Args); err != nil { c.Log.Error("COMMANDER", "run error", err) - os.Exit(1) + s.Shutdown(fx.ExitCode(1)) } + s.Shutdown() } diff --git a/src/components/tui/main.go b/src/components/tui/main.go index e5f0ec7..1fe0ae4 100644 --- a/src/components/tui/main.go +++ b/src/components/tui/main.go @@ -267,34 +267,34 @@ func (m *mainModel) CopyToClipboard() error { switch converted := item.(type) { case spotify.SimplePlaylist: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case *spotify.FullPlaylist: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case spotify.SimpleAlbum: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case *spotify.FullAlbum: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case spotify.SimpleArtist: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case *spotify.FullArtist: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case spotify.SimpleTrack: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case spotify.PlaylistTrack: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.Track.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.Track.ExternalURLs["spotify"]) case spotify.SavedTrack: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) case spotify.FullTrack: go m.SendMessage("Copying link to "+m.list.SelectedItem().(mainItem).Title(), 2*time.Second) - clipboard.WriteAll(converted.ExternalURLs["spotify"]) + return clipboard.WriteAll(converted.ExternalURLs["spotify"]) } return nil } @@ -746,7 +746,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if msg.String() == "c" { err := m.CopyToClipboard() if err != nil { - return m, tea.Quit + go m.SendMessage(err.Error(), 5*time.Second) } } if msg.String() == ">" { @@ -837,12 +837,12 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // handle mouse - case tea.MouseMsg: - if msg.Type == 5 { + case tea.MouseButton: + if msg == 5 { m.list.CursorUp() } - if msg.Type == 6 { - m.list.CursorDown() + if msg == 6 { + m.list.CursorUp() } // window size -1 to handle search bar