Skip to content

Commit

Permalink
fix: Address new linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kinbiko committed Jun 28, 2024
1 parent 69dd83b commit d4a206f
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 34 deletions.
14 changes: 5 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats:
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand Down Expand Up @@ -78,7 +79,7 @@ linters-settings:

govet:
# report about shadowed variables
check-shadowing: true
shadow: true

# enable or disable analyzers by name
# enable:
Expand Down Expand Up @@ -225,12 +226,6 @@ linters:
- godot
- nlreturn

# These are apparently disabled but still yell at you if you don't disable them
- golint
- scopelint
- maligned
- interfacer

# This won't shut up about using errors.As which doesn't make sense in
# general in this package.
- errorlint
Expand Down Expand Up @@ -272,7 +267,6 @@ issues:
- funlen
- gocognit
- gocyclo
- gomnd
- lll
- paralleltest
- staticcheck
Expand All @@ -282,7 +276,9 @@ issues:
- path: \.go
linters:
- goerr113
- err113
- exhaustruct
- mnd

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
Expand Down
3 changes: 2 additions & 1 deletion builds/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -37,7 +38,7 @@ type Publisher struct {
// Publish sends the request to Bugsnag's Build API.
func (p *Publisher) Publish(req *JSONBuildRequest) error {
if p.endpoint == "" {
return fmt.Errorf("publisher created incorrectly; please use NewPublisher or DefaultPublisher to construct your builds.Publisher")
return errors.New("publisher created incorrectly; please use NewPublisher or DefaultPublisher to construct your builds.Publisher")
}

jsonBody, err := json.Marshal(req)
Expand Down
7 changes: 4 additions & 3 deletions builds/validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builds

import (
"errors"
"fmt"
"regexp"
"strings"
Expand All @@ -14,18 +15,18 @@ func (r *JSONBuildRequest) Validate() error {
}

if strings.TrimSpace(r.AppVersion) == "" {
return fmt.Errorf(`AppVersion must be present`)
return errors.New(`AppVersion must be present`)
}

if r.SourceControl == nil {
return nil
}

if r.SourceControl.Repository == "" {
return fmt.Errorf(`SourceControl.Repository must be present when SourceControl is set`)
return errors.New(`SourceControl.Repository must be present when SourceControl is set`)
}
if r.SourceControl.Revision == "" {
return fmt.Errorf(`SourceControl.Revision must be present when SourceControl is set`)
return errors.New(`SourceControl.Revision must be present when SourceControl is set`)
}
if provider := r.SourceControl.Provider; provider != "" {
if err := validateSourceControlProvider(provider); err != nil {
Expand Down
11 changes: 5 additions & 6 deletions cmd/bugsnag/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -26,11 +25,11 @@ func TestRelease(t *testing.T) {
defer ts.Close()

t.Run("small payload", func(t *testing.T) {
cmd := fmt.Sprintf(`release
cmd := `release
--api-key=1234abcd1234abcd1234abcd1234abcd
--app-version=2.5.2
--release-stage=
--endpoint=%s`, ts.URL)
--endpoint=` + ts.URL
err := run(strings.Split(cmd, "\n"), map[string]string{})
if err != nil {
t.Fatal(err)
Expand All @@ -51,7 +50,7 @@ func TestRelease(t *testing.T) {
})

t.Run("big payload", func(t *testing.T) {
cmd := fmt.Sprintf(`release
cmd := `release
--api-key=1234abcd1234abcd1234abcd1234abcd
--app-version=2.5.2
--release-stage=staging
Expand All @@ -63,7 +62,7 @@ func TestRelease(t *testing.T) {
--auto-assign-release=true
--app-version-code=1234
--app-bundle-version=5.2
--endpoint=%s`, ts.URL)
--endpoint=` + ts.URL
err := run(strings.Split(cmd, "\n"), map[string]string{})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -97,7 +96,7 @@ func TestRelease(t *testing.T) {
})

t.Run("uses defaults", func(t *testing.T) {
cmd := fmt.Sprintf(`release --endpoint=%s`, ts.URL)
cmd := `release --endpoint=` + ts.URL
err := run(strings.Split(cmd, " "), map[string]string{
"BUGSNAG_API_KEY": "1234abcd1234abcd1234abcd1234abcd",
"APP_VERSION": "2.5.2",
Expand Down
5 changes: 3 additions & 2 deletions cmd/bugsnag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package main

import (
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -36,7 +37,7 @@ func run(args []string, envvars map[string]string) error {
app := application{releaseFlags: newReleaseFlags(releaseCmd)}

if len(args) == 0 {
return fmt.Errorf(usage)
return errors.New(usage)
}
if args[0] == "release" {
err := releaseCmd.Parse(args[1:])
Expand All @@ -45,5 +46,5 @@ func run(args []string, envvars map[string]string) error {
}
return app.runRelease(envvars)
}
return fmt.Errorf(usage)
return errors.New(usage)
}
5 changes: 3 additions & 2 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bugsnag

import (
"context"
"errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -100,11 +101,11 @@ func (cfg *Configuration) validate() error {
return fmt.Errorf(`sessions endpoint be a valid URL, got "%s"`, cfg.EndpointSessions)
}
if cfg.ReleaseStage == "" {
return fmt.Errorf("release stage must be set")
return errors.New("release stage must be set")
}
semverRegex := `v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?`
if r := regexp.MustCompile(semverRegex); !r.MatchString(cfg.AppVersion) {
return fmt.Errorf("app version must be valid semver")
return errors.New("app version must be valid semver")
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func TestConfigurationValidation(t *testing.T) {
expMsg: `app version must be valid semver`,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.cfg.validate()
if err == nil {
Expand Down
1 change: 0 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestContextWithMethods(t *testing.T) {
{"WithMetadatum", func() { n.WithMetadatum(ctx, "whatever", "foo", "bar") }},
{"WithUser", func() { n.WithUser(ctx, User{}) }},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
defer func() {
Expand Down
2 changes: 0 additions & 2 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestSeverityReasonType(t *testing.T) {
{exp: "userSpecifiedSeverity", err: Error{Severity: SeverityError}},
{exp: "userSpecifiedSeverity", err: Error{Severity: SeverityError, Unhandled: true, Panic: true}},
} {
tc := tc
t.Run(tc.exp, func(t *testing.T) {
t.Parallel()
if got := severityReasonType(&tc.err); got != tc.exp {
Expand Down Expand Up @@ -101,7 +100,6 @@ func TestWrap(t *testing.T) {
{ctx: nil, err: err, msg: fmtBase, args: args, expErrString: wrappedFmtMsg, name: "all args but ctx"},
{ctx: ctx, err: err, msg: fmtBase, args: args, expErrString: wrappedFmtMsg, name: "all args"},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
if tc.msg != "" || tc.args != nil {
Expand Down
4 changes: 2 additions & 2 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func TestIntegration(t *testing.T) {
reports := make(chan string, 1)

ntfServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ntfServer := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
payload, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
Expand All @@ -30,7 +30,7 @@ func TestIntegration(t *testing.T) {
}))
defer ntfServer.Close()

sessionServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
sessionServer := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
defer sessionServer.Close()

ntf, _ := bugsnag.New(bugsnag.Configuration{
Expand Down
6 changes: 3 additions & 3 deletions notifier_panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package bugsnag

import (
"context"
"fmt"
"errors"
"strings"
"testing"
)
Expand Down Expand Up @@ -34,7 +34,7 @@ func TestNoPanicsWhenShuttingDown(t *testing.T) {
t.Fatal(err)
}
ctx := n.StartSession(context.Background())
n.Notify(ctx, fmt.Errorf("oooi"))
n.Notify(ctx, errors.New("oooi"))
n.Close()
})

Expand All @@ -57,7 +57,7 @@ func TestNoPanicsWhenShuttingDown(t *testing.T) {
t.Fatal(err)
}
n.Close()
n.Notify(context.Background(), fmt.Errorf("oops"))
n.Notify(context.Background(), errors.New("oops"))

if got == nil {
t.Fatal("expected error but got none")
Expand Down
1 change: 0 additions & 1 deletion notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestApp(t *testing.T) {
exp: `{ "duration": 5000, "releaseStage": "staging", "version": "1.5.2" }`,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
tc.cfg.appStartTime = time.Now().Add(-5 * time.Second)
Expand Down
1 change: 0 additions & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestSessionAndContext(t *testing.T) {
{expUnhandledCount: 1, expHandledCount: 0, name: "unhandled", unhandled: true},
{expUnhandledCount: 0, expHandledCount: 1, name: "handled", unhandled: false},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
n, err := New(Configuration{APIKey: "abcd1234abcd1234abcd1234abcd1234", ReleaseStage: "dev", AppVersion: "1.2.3"})
Expand Down

0 comments on commit d4a206f

Please sign in to comment.