Skip to content

Commit

Permalink
Merge pull request #71 from bzimmer/upgrades
Browse files Browse the repository at this point in the history
update go version; lint fixes
  • Loading branch information
bzimmer authored May 31, 2024
2 parents ad7d85c + 703f303 commit 79eb7a6
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ linters:
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
Expand Down Expand Up @@ -242,6 +241,7 @@ linters:
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks unused constants, variables, functions and types
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
- whitespace # detects leading and trailing whitespace
Expand Down
15 changes: 15 additions & 0 deletions Taskfile-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ tasks:
cmds:
- goimports -w -local "{{.module}}/" .

docs:generate:
desc: Statically generate the commands documentation
deps: [build]
vars:
cmd:
sh: go mod edit -json | jq -r '.Module.Path | split("/") | last'
cmds:
- |
if [[ -d {{.ROOT_DIR}}/docs/commands ]];
then
{{.ROOT_DIR}}/dist/{{.cmd}} manual {{.ROOT_DIR}}/docs/commands > {{.ROOT_DIR}}/docs/commands.md
fi
docs:build:
desc: Statically generate the documentation
deps: [dist]
Expand All @@ -107,6 +121,7 @@ tasks:

docs:serve:
desc: Serve the documentation
deps: [docs:generate]
cmds:
- "{{.ROOT_DIR}}/env/bin/mkdocs serve"

Expand Down
8 changes: 4 additions & 4 deletions activity/cyclinganalytics/cyclinganalytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAthlete(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/me", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/me", func(w http.ResponseWriter, _ *http.Request) {
ath := &api.User{}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(ath))
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestActivity(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/ride/77282721", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/ride/77282721", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(api.Ride{
LocalDatetime: api.Datetime{Time: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.Local)},
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestBefore(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
cmd := func(t *testing.T, baseURL string) *cli.Command {
cmd := func(_ *testing.T, _ string) *cli.Command {
return &cli.Command{Name: tt.Name, Flags: cyclinganalytics.AuthFlags(), Action: tt.Action}
}
internal.Run(t, tt, nil, cmd)
Expand All @@ -136,7 +136,7 @@ func TestActivities(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/me/rides", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/me/rides", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
Rides []*api.Ride `json:"rides"`
Expand Down
2 changes: 1 addition & 1 deletion activity/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestDateRange(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
command := func(t *testing.T, baseURL string) *cli.Command {
command := func(_ *testing.T, _ string) *cli.Command {
return &cli.Command{
Name: tt.Name,
Flags: activity.DateRangeFlags(),
Expand Down
2 changes: 1 addition & 1 deletion activity/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestOAuth(t *testing.T) {
}
})
grp.Go(func() error {
internal.RunContext(ctx, t, tt, nil, func(_ *testing.T, baseURL string) *cli.Command {
internal.RunContext(ctx, t, tt, nil, func(_ *testing.T, _ string) *cli.Command {
return activity.OAuthCommand(cfg)
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion activity/qp/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"path/filepath"

"github.com/armon/go-metrics"
"github.com/bzimmer/activity"
"github.com/hashicorp/go-metrics"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion activity/qp/qp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strconv"
"time"

"github.com/armon/go-metrics"
api "github.com/bzimmer/activity"
"github.com/hashicorp/go-metrics"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"github.com/urfave/cli/v2"
Expand Down
14 changes: 7 additions & 7 deletions activity/rwgps/rwgps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestAthlete(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/users/current.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/users/current.json", func(w http.ResponseWriter, _ *http.Request) {
type res struct {
User *api.User `json:"user"`
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestBefore(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
cmd := func(t *testing.T, baseURL string) *cli.Command {
cmd := func(_ *testing.T, _ string) *cli.Command {
return &cli.Command{Name: tt.Name, Flags: rwgps.AuthFlags(), Action: tt.Action}
}
internal.Run(t, tt, nil, cmd)
Expand All @@ -92,7 +92,7 @@ func TestTrip(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/routes/90288724.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/routes/90288724.json", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
Type string `json:"type"`
Expand All @@ -104,7 +104,7 @@ func TestTrip(t *testing.T) {
},
}))
})
mux.HandleFunc("/trips/7728201.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/trips/7728201.json", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
Type string `json:"type"`
Expand Down Expand Up @@ -141,15 +141,15 @@ func TestTrips(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/users/current.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/users/current.json", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
User *api.User `json:"user"`
}{
User: &api.User{ID: 82877292},
}))
})
mux.HandleFunc("/users/82877292/trips.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/users/82877292/trips.json", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
Results []*api.Trip `json:"results"`
Expand All @@ -162,7 +162,7 @@ func TestTrips(t *testing.T) {
ResultsCount: 2,
}))
})
mux.HandleFunc("/users/82877292/routes.json", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/users/82877292/routes.json", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(struct {
Results []*api.Trip `json:"results"`
Expand Down
5 changes: 3 additions & 2 deletions activity/strava/strava.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func evaluator(c *cli.Context, evaluation string) (eval.Evaluator, error) {
}
return ev, nil
}
//nolint:nilnil // no evaluation
return nil, nil
}

Expand All @@ -84,7 +85,7 @@ func filter(c *cli.Context) (func(ctx context.Context, act *strava.Activity) (bo
return nil, err
}
if ev == nil {
return func(ctx context.Context, act *strava.Activity) (bool, error) { return true, nil }, nil
return func(_ context.Context, _ *strava.Activity) (bool, error) { return true, nil }, nil
}
return ev.Bool, nil
}
Expand All @@ -95,7 +96,7 @@ func attributer(c *cli.Context) (func(ctx context.Context, act *strava.Activity)
return nil, err
}
if ev == nil {
return func(ctx context.Context, act *strava.Activity) (any, error) { return act, nil }, nil
return func(_ context.Context, act *strava.Activity) (any, error) { return act, nil }, nil
}
return ev.Eval, nil
}
Expand Down
36 changes: 18 additions & 18 deletions activity/strava/strava_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAthlete(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/athlete", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/athlete", func(w http.ResponseWriter, _ *http.Request) {
ath := &api.Athlete{}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(ath))
Expand All @@ -66,12 +66,12 @@ func TestActivity(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/activities/12345", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/12345", func(w http.ResponseWriter, _ *http.Request) {
act := &api.Activity{}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(act))
})
mux.HandleFunc("/activities/12345/streams/", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/12345/streams/", func(w http.ResponseWriter, _ *http.Request) {
sms := &api.Streams{}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(sms))
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestActivities(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/athlete/activities", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/athlete/activities", func(w http.ResponseWriter, _ *http.Request) {
acts := []*api.Activity{{Type: "Hike"}, {Type: "Run"}, {Type: "Hike"}}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(acts))
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestRoute(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/routes/77282721", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/routes/77282721", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(api.Route{}))
})
Expand All @@ -194,7 +194,7 @@ func TestStreams(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/activities/77282721/streams/", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/77282721/streams/", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode(api.Streams{}))
})
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestPhotos(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/activities/26627201/photos", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/26627201/photos", func(w http.ResponseWriter, _ *http.Request) {
enc := json.NewEncoder(w)
a.NoError(enc.Encode([]*api.Photo{{}, {}}))
})
Expand All @@ -247,12 +247,12 @@ func TestRoutes(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/athlete", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/athlete", func(w http.ResponseWriter, _ *http.Request) {
ath := &api.Athlete{ID: 8542982}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(ath))
})
mux.HandleFunc("/athletes/8542982/routes", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/athletes/8542982/routes", func(w http.ResponseWriter, _ *http.Request) {
rtes := []*api.Route{{}, {}, {}}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(rtes))
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestBefore(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
cmd := func(t *testing.T, baseURL string) *cli.Command {
cmd := func(_ *testing.T, _ string) *cli.Command {
return &cli.Command{Name: tt.Name, Flags: strava.AuthFlags(), Action: tt.Action}
}
internal.Run(t, tt, nil, cmd)
Expand All @@ -308,7 +308,7 @@ func TestRefresh(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/token", func(w http.ResponseWriter, _ *http.Request) {
n, err := w.Write([]byte(`{
"access_token":"90d64460d14870c08c81352a05dedd3465940a7c",
"token_type":"bearer",
Expand Down Expand Up @@ -345,39 +345,39 @@ func TestUpdate(t *testing.T) {
}

mux := http.NewServeMux()
mux.HandleFunc("/activities/101", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/101", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.True(*act.Hidden)
})
mux.HandleFunc("/activities/102", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/102", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.False(*act.Hidden)
})
mux.HandleFunc("/activities/103", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/103", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.Equal("foobar", *act.Description)
})
mux.HandleFunc("/activities/104", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/104", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.Equal("foobaz", *act.Name)
})
mux.HandleFunc("/activities/105", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/105", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.Equal("gravel", *act.SportType)
a.Equal("99181", *act.GearID)
})
mux.HandleFunc("/activities/106", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/106", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.True(*act.Commute)
a.True(*act.Trainer)
})
mux.HandleFunc("/activities/107", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/activities/107", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodPut, r.Method)
act := decoder(r)
a.False(*act.Commute)
Expand Down
8 changes: 4 additions & 4 deletions activity/strava/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ func TestWebhookUnsubscribe(t *testing.T) {
a := assert.New(t)

mux := http.NewServeMux()
mux.HandleFunc("/push_subscriptions/334455", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/push_subscriptions/334455", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodDelete, r.Method)
// no response
})
mux.HandleFunc("/push_subscriptions/10", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/push_subscriptions/10", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodDelete, r.Method)
// no response
})
mux.HandleFunc("/push_subscriptions/20", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/push_subscriptions/20", func(_ http.ResponseWriter, r *http.Request) {
a.Equal(http.MethodDelete, r.Method)
// no response
})
mux.HandleFunc("/push_subscriptions", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/push_subscriptions", func(w http.ResponseWriter, _ *http.Request) {
res := []*strava.WebhookSubscription{{ID: 10}, {ID: 20}}
enc := json.NewEncoder(w)
a.NoError(enc.Encode(res))
Expand Down
Loading

0 comments on commit 79eb7a6

Please sign in to comment.