From 7dccf57bf98b7a774dbed9c93afc1f7d7115b6f5 Mon Sep 17 00:00:00 2001 From: Urban Cetinski Date: Wed, 7 Jul 2021 17:25:26 +0200 Subject: [PATCH] Add lint job to Github actions and fixed lint errors (#36) * Add lint job golangci/golangci-lint-action@v2.5.2 and fixed lint errors. Fixed next lint errors: internal/login/login.go:122:19: Error return value of server.Shutdown is not checked (errcheck) main.go:30:23: Error return value of viper.SafeWriteConfig is not checked (errcheck) main.go:31:20: Error return value of viper.ReadInConfig is not checked (errcheck) main.go:63:14: Error return value of root.Execute is not checked (errcheck) internal/play/play.go:52:3: ineffectual assignment to err (ineffassign) internal/common.go:51:10: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck) * Update .github/workflows/test.yml - removed name for golangci/golangci-lint-action Co-authored-by: Brian Strauch * Update internal/login/login.go -make staticcheck happy without err check Co-authored-by: Brian Strauch * Update main.go - replaced err !=nill check with cobra.CheckErr() Co-authored-by: Brian Strauch * Update main.go - removed err check for viper.ReadInConfig() because of bad UX Co-authored-by: Brian Strauch * Updated main.go - unused imports and undefined: err * Updated play/play.go - add another check in the else block and delete the check below the entire if/else because otherwise, staticcheck reports an error * Updated go.mod and go.sum - removed unused dependencies Co-authored-by: Brian Strauch --- .github/workflows/test.yml | 10 ++++++++++ internal/common.go | 4 ++-- internal/login/login.go | 2 +- internal/play/play.go | 11 +++++++---- main.go | 7 ++++--- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2575953..723a2c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,3 +25,13 @@ jobs: - name: Test run: go test -v ./... + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - uses: golangci/golangci-lint-action@v2.5.2 diff --git a/internal/common.go b/internal/common.go index 566e75b..fa0530a 100644 --- a/internal/common.go +++ b/internal/common.go @@ -48,13 +48,13 @@ func SaveToken(token *spotify.Token) error { func WaitForUpdatedPlayback(api APIInterface, isUpdated func(playback *spotify.Playback) bool) (*spotify.Playback, error) { timeout := time.After(time.Second) - tick := time.Tick(100 * time.Millisecond) + tick := time.NewTicker(100 * time.Millisecond) for { select { case <-timeout: return nil, errors.New("request timed out") - case <-tick: + case <-tick.C: playback, err := api.GetPlayback() if err != nil { return nil, err diff --git a/internal/login/login.go b/internal/login/login.go index 297c9ac..cf97f8b 100644 --- a/internal/login/login.go +++ b/internal/login/login.go @@ -119,7 +119,7 @@ func listenForCode(state string) (code string, err error) { // Use a separate thread so browser doesn't show a "No Connection" message go func() { - server.Shutdown(context.TODO()) + _ = server.Shutdown(context.TODO()) }() }) diff --git a/internal/play/play.go b/internal/play/play.go index af284f7..d24bece 100644 --- a/internal/play/play.go +++ b/internal/play/play.go @@ -50,13 +50,16 @@ func Play(api internal.APIInterface, query string) (string, error) { } err = api.Play(track.URI) + if err != nil { + return "", err + } } else { err = api.Play() - } - if err != nil { - if err.Error() == internal.ErrRestrictionViolated { - return "", errors.New(internal.ErrAlreadyPlaying) + if err != nil { + if err.Error() == internal.ErrRestrictionViolated { + return "", errors.New(internal.ErrAlreadyPlaying) + } } } diff --git a/main.go b/main.go index 379a0f2..8823953 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ func main() { viper.AddConfigPath("$HOME") viper.SetConfigName(".spotify-cli") viper.SetConfigType("json") - viper.SafeWriteConfig() - viper.ReadInConfig() + _ = viper.SafeWriteConfig() + _ = viper.ReadInConfig() root := &cobra.Command{ Use: "spotify", @@ -60,7 +60,8 @@ func main() { root.Flags().BoolP("help", "h", false, "Help for Spotify CLI.") root.Flags().BoolP("version", "v", false, "Version for Spotify CLI.") - root.Execute() + err := root.Execute() + cobra.CheckErr(err) } func promptUpdate(cmd *cobra.Command, _ []string) error {