Skip to content

Commit

Permalink
Update linters
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Dec 22, 2023
1 parent 2ba4565 commit 1ba965e
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 53 deletions.
70 changes: 42 additions & 28 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
linters:
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- depguard
- gochecknoinits
- gocritic
- gocyclo
- gofmt
- goimports
- misspell
- nakedret
- prealloc
- exportloopref
- stylecheck
- unconvert
- unparam
- gosec
- revive
- gochecknoglobals
enable-all: true
disable:
- musttag
- maintidx
- exhaustruct
- wrapcheck
- nolintlint
- wastedassign
- varnamelen
- forcetypeassert
- goerr113
- exhaustivestruct
- ireturn
- funlen
- forbidigo
- godot
- godox
- cyclop
- prealloc
- dupl
- lll
- maligned
- goconst
- depguard
- exhaustive
- wsl
- unparam
- gomoddirectives
- gofumpt
- nestif
- paralleltest
- testpackage
- gocognit
- gomnd
- tagliatelle
- nlreturn
# deprecated
- deadcode
- scopelint
- nosnakecase
- golint
- interfacer
- structcheck
- ifshort
- varcheck

linters-settings:
errcheck:
ignore: fmt:.*

run:
modules-download-mode: vendor
modules-download-mode: vendor
timeout: 3m
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif

.PHONY: lint
lint:
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.51.1 golangci-lint run -c .golangci.yaml
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -c .golangci.yaml

.PHONY: tests
tests:
Expand Down
2 changes: 1 addition & 1 deletion alert/queries/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestProjectCanBeConfigured(t *testing.T) {
req := require.New(t)

project := "some-gcp-project-id"

query := Delta("A", "some metric", Project(project))
Expand Down
1 change: 0 additions & 1 deletion alert/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/K-Phoen/grabana/alert/queries/stackdriver"

"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (client *Client) AddAlert(ctx context.Context, namespace string, alertDefin
alertDefinition.HookDatasourceUID(datasourceUID)

// Before we can add this alert, we need to delete any other alert that might exist for this dashboard and panel
if err := client.DeleteAlertGroup(ctx, namespace, alertDefinition.Builder.Name); err != nil && err != ErrAlertNotFound {
if err := client.DeleteAlertGroup(ctx, namespace, alertDefinition.Builder.Name); err != nil && !errors.Is(err, ErrAlertNotFound) {
return fmt.Errorf("could not delete existing alerts: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func ExternalLinks(links ...ExternalLink) Option {

// DashboardLinks adds a dashboard-level links to other dashboards.
// See https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/manage-dashboard-links/#dashboard-links
func DashboardLinks(links ...DashboardLink) Option {
func DashboardLinks(links ...DashboardLink) Option { //nolint:revive
return func(builder *Builder) error {
for _, link := range links {
builder.board.Links = append(builder.board.Links, link.asSdk())
Expand Down
2 changes: 2 additions & 0 deletions dashboard/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func requireJSON(t *testing.T, payload []byte) {
t.Helper()

var receiver map[string]interface{}
if err := json.Unmarshal(payload, &receiver); err != nil {
t.Fatalf("invalid json: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (link ExternalLink) asSdk() sdk.Link {

// DashboardLink describes dashboard-level links to other dashboards.
// See https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/manage-dashboard-links/#dashboard-links
type DashboardLink struct {
type DashboardLink struct { //nolint:revive
Title string
Tags []string

Expand Down
6 changes: 2 additions & 4 deletions dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (
"strings"
"testing"

"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"

"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/text"
"github.com/K-Phoen/grabana/timeseries"
"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"
)

func TestADashboardCanBeFoundByTitle(t *testing.T) {
Expand Down Expand Up @@ -132,7 +131,6 @@ func TestFetchingAnUnknownDashboardByUIDFailsCleanly(t *testing.T) {
req := require.New(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)

}))
defer ts.Close()

Expand Down
2 changes: 1 addition & 1 deletion datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (client *Client) UpsertDatasource(ctx context.Context, datasource datasourc
}

id, err := client.getDatasourceIDByName(ctx, datasource.Name())
if err != nil && err != ErrDatasourceNotFound {
if err != nil && !errors.Is(err, ErrDatasourceNotFound) {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions decoder/alert_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t AlertPrometheus) toOptions() (alert.Option, error) {
if t.Lookback != "" {
from, err := time.ParseDuration(t.Lookback)
if err != nil {
return nil, fmt.Errorf("%s: %w", err, ErrInvalidLookback)
return nil, fmt.Errorf("%w: %w", err, ErrInvalidLookback)
}

opts = append(opts, prometheus.TimeRange(from, 0))
Expand Down Expand Up @@ -85,7 +85,7 @@ func (t AlertLoki) toOptions() (alert.Option, error) {
if t.Lookback != "" {
from, err := time.ParseDuration(t.Lookback)
if err != nil {
return nil, fmt.Errorf("%s: %w", err, ErrInvalidLookback)
return nil, fmt.Errorf("%w: %w", err, ErrInvalidLookback)
}

opts = append(opts, loki.TimeRange(from, 0))
Expand All @@ -110,7 +110,7 @@ func (t AlertGraphite) toOptions() (alert.Option, error) {
if t.Lookback != "" {
from, err := time.ParseDuration(t.Lookback)
if err != nil {
return nil, fmt.Errorf("%s: %w", err, ErrInvalidLookback)
return nil, fmt.Errorf("%w: %w", err, ErrInvalidLookback)
}

opts = append(opts, graphite.TimeRange(from, 0))
Expand Down Expand Up @@ -181,7 +181,7 @@ func (t AlertStackdriver) targetOptions() ([]stackdriver.Option, error) {
if t.Lookback != "" {
from, err := time.ParseDuration(t.Lookback)
if err != nil {
return nil, fmt.Errorf("%s: %w", err, ErrInvalidLookback)
return nil, fmt.Errorf("%w: %w", err, ErrInvalidLookback)
}

opts = append(opts, stackdriver.TimeRange(from, 0))
Expand Down
2 changes: 2 additions & 0 deletions decoder/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ rows:
}

func dashboardFromFixtures(t *testing.T, path string) string {
t.Helper()

req := require.New(t)

payload, err := os.ReadFile(path)
Expand Down
3 changes: 1 addition & 2 deletions decoder/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package decoder
import (
"testing"

"github.com/K-Phoen/grabana/target/influxdb"

"github.com/K-Phoen/grabana/target/graphite"
"github.com/K-Phoen/grabana/target/influxdb"
"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/stretchr/testify/require"
Expand Down
5 changes: 2 additions & 3 deletions decoder/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package decoder
import (
"testing"

"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"

"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/timeseries"
"github.com/K-Phoen/grabana/timeseries/axis"
"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"
)

func TestTimeSeriesCanBeDecoded(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Folder struct {
// FindOrCreateFolder returns the folder by its name or creates it if it doesn't exist.
func (client *Client) FindOrCreateFolder(ctx context.Context, name string) (*Folder, error) {
folder, err := client.GetFolderByTitle(ctx, name)
if err != nil && err != ErrFolderNotFound {
if err != nil && !errors.Is(err, ErrFolderNotFound) {
return nil, fmt.Errorf("could not find or create folder: %w", err)
}
if folder == nil {
Expand Down
3 changes: 1 addition & 2 deletions timeseries/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package timeseries
import (
"fmt"

"github.com/K-Phoen/sdk"

"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/errors"
"github.com/K-Phoen/grabana/links"
"github.com/K-Phoen/grabana/scheme"
"github.com/K-Phoen/grabana/timeseries/axis"
"github.com/K-Phoen/grabana/timeseries/fields"
"github.com/K-Phoen/grabana/timeseries/threshold"
"github.com/K-Phoen/sdk"
)

// Option represents an option that can be used to configure a graph panel.
Expand Down
3 changes: 1 addition & 2 deletions timeseries/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/K-Phoen/grabana/errors"
"github.com/K-Phoen/grabana/links"
"github.com/K-Phoen/grabana/scheme"
Expand All @@ -14,6 +12,7 @@ import (
"github.com/K-Phoen/grabana/timeseries/fields"
"github.com/K-Phoen/grabana/timeseries/threshold"
"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"
)

func TestNewTimeSeriesPanelsCanBeCreated(t *testing.T) {
Expand Down

0 comments on commit 1ba965e

Please sign in to comment.