Skip to content

Commit

Permalink
addressed linting issues (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzimmer authored Oct 15, 2021
1 parent 4cfdd42 commit da6e32f
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 113 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand All @@ -14,16 +14,14 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Install Task
uses: arduino/setup-task@v1
- name: Test
run: go test ./...
if: matrix.os == 'macos-latest' || matrix.os == 'windows-latest'
- name: Test Coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
if: matrix.os == 'ubuntu-latest'
run: task test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
files: ./dist/coverage.txt
verbose: true
if: matrix.os == 'ubuntu-latest'
31 changes: 31 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint
on: [push, pull_request]
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: -v

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
119 changes: 119 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable:
- gomnd
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- exportloopref
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- goconst
# - gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# issues:
# # Excluding configuration per-path, per-linter, per-text and per-source
# exclude-rules:
# - path: _test\.go
# linters:
# - gomnd

# # https://github.com/go-critic/go-critic/issues/926
# - linters:
# - gocritic
# text: "unnecessaryDefer:"

# run:
# skip-dirs:
# - test/testdata_etc
# - internal/cache
# - internal/renameio
# - internal/robustio

# # golangci.com configuration
# # https://github.com/golangci/golangci/wiki/Configuration
# service:
# golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
# prepare:
# - echo "here I can run custom commands, but no preparation needed for this repo"
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ tasks:
desc: Run code generation
cmds:
- go generate ./...

lint:
desc: Runs the linter
cmds:
- go vet ./...
- golangci-lint -v run
14 changes: 8 additions & 6 deletions cyclinganalytics/cyclinganalytics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cyclinganalytics

//go:generate genwith --do --client --endpoint --config --token --ratelimit --package cyclinganalytics
//go:generate genwith --do --client --endpoint-func --config --token --ratelimit --package cyclinganalytics

import (
"context"
Expand All @@ -16,7 +16,7 @@ import (

const baseURL = "https://www.cyclinganalytics.com/api"

// Client .
// Client for accessing Cycling Analytics' API
type Client struct {
config oauth2.Config
token *oauth2.Token
Expand All @@ -27,10 +27,12 @@ type Client struct {
}

// Endpoint is CyclingAnalytics's OAuth 2.0 endpoint
var Endpoint = oauth2.Endpoint{
AuthURL: "https://www.cyclinganalytics.com/api/auth",
TokenURL: "https://www.cyclinganalytics.com/api/token",
AuthStyle: oauth2.AuthStyleAutoDetect,
func Endpoint() oauth2.Endpoint {
return oauth2.Endpoint{
AuthURL: "https://www.cyclinganalytics.com/api/auth",
TokenURL: "https://www.cyclinganalytics.com/api/token",
AuthStyle: oauth2.AuthStyleAutoDetect,
}
}

func withServices() Option {
Expand Down
4 changes: 2 additions & 2 deletions cyclinganalytics/cyclinganalytics_with.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 28 additions & 29 deletions cyclinganalytics/rides.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,15 @@ func (s *RidesService) StatusWithUser(ctx context.Context, userID UserID, upload
return res, nil
}

// AvailableStreams returns the list of valid stream names
// StreamSets returns the list of valid stream names
func (s *RidesService) StreamSets() map[string]string {
q := make(map[string]string)
for k, v := range streamsets {
q[k] = v
}
return q
return streamsets()
}

func validateStreams(streams []string) error {
x := streamsets()
for i := range streams {
_, ok := streamsets[streams[i]]
_, ok := x[streams[i]]
if !ok {
return fmt.Errorf("invalid stream '%s'", streams[i])
}
Expand All @@ -186,26 +183,28 @@ func validateStreams(streams []string) error {
}

// https://www.cyclinganalytics.com/developer/api#/ride/ride_id
var streamsets = map[string]string{
"cadence": "",
"distance": "The sequence of distance values for this stream, in kilometers [float]",
"elevation": "The sequence of elevation values for this stream, in meters [float]",
"gears": "",
"gradient": "The sequence of grade values for this stream, as percents of a grade [float]",
"heart_rate_variability": "",
"heartrate": "The sequence of heart rate values for this stream, in beats per minute [integer]",
"latitude": "",
"longitude": "",
"lrbalance": "",
"pedal_smoothness": "",
"platform_center_offset": "",
"power_direction": "",
"power_phase": "",
"power": "",
"respiration_rate": "",
"smo2": "",
"speed": "The sequence of speed values for this stream, in meters per second [float]",
"temperature": "The sequence of temperature values for this stream, in celsius degrees [float]",
"thb": "",
"torque_effectiveness": "",
func streamsets() map[string]string {
return map[string]string{
"cadence": "",
"distance": "The sequence of distance values for this stream, in kilometers [float]",
"elevation": "The sequence of elevation values for this stream, in meters [float]",
"gears": "",
"gradient": "The sequence of grade values for this stream, as percents of a grade [float]",
"heart_rate_variability": "",
"heartrate": "The sequence of heart rate values for this stream, in beats per minute [integer]",
"latitude": "",
"longitude": "",
"lrbalance": "",
"pedal_smoothness": "",
"platform_center_offset": "",
"power_direction": "",
"power_phase": "",
"power": "",
"respiration_rate": "",
"smo2": "",
"speed": "The sequence of speed values for this stream, in meters per second [float]",
"temperature": "The sequence of temperature values for this stream, in celsius degrees [float]",
"thb": "",
"torque_effectiveness": "",
}
}
17 changes: 6 additions & 11 deletions rwgps/rwgps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ import (
"github.com/bzimmer/httpwares"
)

var (
tests = map[string]string{
"apikey": "fooKey",
"version": "2",
"auth_token": "barToken",
}
)

func newClient(status int, filename string) (*rwgps.Client, error) {
return rwgps.NewClient(
rwgps.WithTransport(&httpwares.TestDataTransport{
Expand All @@ -27,12 +19,15 @@ func newClient(status int, filename string) (*rwgps.Client, error) {
Requester: func(req *http.Request) error {
var body map[string]interface{}
decoder := json.NewDecoder(req.Body)
err := decoder.Decode(&body)
if err != nil {
if err := decoder.Decode(&body); err != nil {
return err
}
// confirm the body has the expected key:value pairs
for key, value := range tests {
for key, value := range map[string]string{
"apikey": "fooKey",
"version": "2",
"auth_token": "barToken",
} {
v := body[key]
if v != value {
return fmt.Errorf("expected %s == '%v', not '%v'", key, value, v)
Expand Down
Loading

0 comments on commit da6e32f

Please sign in to comment.