Skip to content

Commit

Permalink
Add lint job to Github actions and fixed lint errors (#36)
Browse files Browse the repository at this point in the history
* Add lint job golangci/[email protected] 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 <[email protected]>

* Update internal/login/login.go -make staticcheck happy without err check

Co-authored-by: Brian Strauch <[email protected]>

* Update main.go - replaced err !=nill check with cobra.CheckErr()

Co-authored-by: Brian Strauch <[email protected]>

* Update main.go - removed err check for viper.ReadInConfig() because of bad UX

Co-authored-by: Brian Strauch <[email protected]>

* 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 <[email protected]>
  • Loading branch information
urbanc and brianstrauch authored Jul 7, 2021
1 parent 8d5d257 commit 7dccf57
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
4 changes: 2 additions & 2 deletions internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}()
})

Expand Down
11 changes: 7 additions & 4 deletions internal/play/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7dccf57

Please sign in to comment.