Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): switch to golangci-lint and fix lints #417

Merged
merged 8 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true
cache: false # https://github.com/golangci/golangci-lint-action/issues/807

- name: Lint
uses: golangci/[email protected]
with:
version: latest

- name: Build
run: go build -v .
Expand Down Expand Up @@ -75,37 +80,3 @@ jobs:

- name: Generate Coverage Report
uses: codecov/[email protected]

fmt:
name: Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true

- name: Check formatting
run: |
# install goimports from another directory to not touch go.mod
pushd ../
go install golang.org/x/tools/cmd/[email protected]
popd

goimports -l -w .

if ! git diff --quiet; then
echo Running goimports has caused changes, please run go fmt
exit 1
fi

go mod tidy

if ! git diff --quiet; then
echo 'go mod tidy' has caused changes, please run go mod tidy
exit 1
fi
43 changes: 43 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: '(.+)_test\.go'
linters:
- errcheck
# disabling both of these for the SDKv2-based code as it's idomatic for the SDK
- path: honeycombio/*
text: "Error return value of `d.Set` is not checked"
- path: honeycombio/*
text: "type assertion must be checked"

linters-settings:
goimports:
local-prefixes: github.com/honeycombio/terraform-provider-honeycombio

linters:
disable-all: true
enable:
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- goimports
- gosimple
- ineffassign
- makezero
- misspell
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
- vet

run:
# Prevent false positive timeouts in CI
timeout: 5m
tests: true
allow-parallel-runners: true
2 changes: 1 addition & 1 deletion client/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Board struct {
Name string `json:"name"`
// Description of the board.
Description string `json:"description,omitempty"`
// The number of columns to be layed out when displaying the board.
// The number of columns to be laid out when displaying the board.
// Defaults to "multi".
//
// n.b. 'list' style boards cannot specify a column layout
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *Client) IsClassic(ctx context.Context) bool {
//
// The response is parsed in responseBody, if responseBody is not nil.
//
// Attemps to return a DetailedError if the response status code is not 2xx,
// Attempts to return a DetailedError if the response status code is not 2xx,
// but can return a generic error.
func (c *Client) Do(ctx context.Context, method, path string, requestBody, responseBody interface{}) error {
var body io.Reader
Expand Down
3 changes: 2 additions & 1 deletion client/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"testing"

"github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/stretchr/testify/assert"

"github.com/honeycombio/terraform-provider-honeycombio/client"
)

func TestDatasets(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions client/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (s *markers) Get(ctx context.Context, dataset string, id string) (*Marker,
return &m, nil
}
}
return nil, &DetailedError{
return nil, DetailedError{
Status: http.StatusNotFound,
Message: "Marker Setting Not Found.",
Message: "Marker Not Found.",
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/marker_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *markerSettings) Get(ctx context.Context, dataset string, id string) (*M
return &m, nil
}
}
return nil, &DetailedError{
return nil, DetailedError{
Status: http.StatusNotFound,
Message: "Marker Setting Not Found.",
}
Expand Down
11 changes: 5 additions & 6 deletions client/marker_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

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

"github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
Expand All @@ -29,10 +30,7 @@ func TestMarkerSettings(t *testing.T) {
t.Run("Create", func(t *testing.T) {

m, err = c.MarkerSettings.Create(ctx, dataset, currentMarkerSetting)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

assert.NotNil(t, m.ID)
assert.Equal(t, currentMarkerSetting.Type, m.Type)
Expand Down Expand Up @@ -63,7 +61,6 @@ func TestMarkerSettings(t *testing.T) {
})

t.Run("Update", func(t *testing.T) {

result, err := c.MarkerSettings.Update(ctx, dataset, m)

assert.NoError(t, err)
Expand All @@ -79,7 +76,9 @@ func TestMarkerSettings(t *testing.T) {
t.Run("Fail to Get deleted Marker Setting", func(t *testing.T) {
_, err := c.MarkerSettings.Get(ctx, dataset, m.ID)

var de client.DetailedError
assert.Error(t, err)
assert.True(t, err.(*client.DetailedError).IsNotFound())
assert.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})
}
4 changes: 3 additions & 1 deletion client/marker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func TestMarkers(t *testing.T) {
t.Run("Fail to Get deleted Marker", func(t *testing.T) {
_, err := c.Markers.Get(ctx, dataset, m.ID)

var de client.DetailedError
assert.Error(t, err)
assert.True(t, err.(*client.DetailedError).IsNotFound())
assert.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})
}
3 changes: 2 additions & 1 deletion client/query_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"testing"

"github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/honeycombio/terraform-provider-honeycombio/client"
)

func TestQueryAnnotations(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion client/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"testing"

"github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/honeycombio/terraform-provider-honeycombio/client"
)

func TestQueries(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (t *Trigger) MarshalJSON() ([]byte, error) {
EvaluationScheduleType: t.EvaluationScheduleType,
EvaluationSchedule: t.EvaluationSchedule,
}
return json.Marshal(&struct{ *ATrigger }{ATrigger: (*ATrigger)(a)})
return json.Marshal(&struct{ *ATrigger }{ATrigger: a})
}

return json.Marshal(&struct{ *ATrigger }{ATrigger: (*ATrigger)(t)})
Expand Down
1 change: 1 addition & 0 deletions honeycombio/data_source_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
)

Expand Down
1 change: 1 addition & 0 deletions honeycombio/data_source_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/hashcode"
)
Expand Down
1 change: 1 addition & 0 deletions honeycombio/data_source_datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/hashcode"
)
Expand Down
2 changes: 1 addition & 1 deletion honeycombio/data_source_datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAccDataSourceHoneycombioDataset_basic(t *testing.T) {
),
},
{
Config: testAccDataSourceDatasetConfig([]string{"starts_with = \"" + string(dataset[0:2]) + "\""}),
Config: testAccDataSourceDatasetConfig([]string{"starts_with = \"" + dataset[0:2] + "\""}),
Check: resource.ComposeTestCheckFunc(
testCheckOutputContains("names", dataset),
),
Expand Down
1 change: 1 addition & 0 deletions honeycombio/data_source_query_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/honeycombio/internal/verify"
)
Expand Down
5 changes: 1 addition & 4 deletions honeycombio/data_source_query_specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ func extractCalculations(d *schema.ResourceData) ([]honeycombio.CalculationSpec,
// none have been provided. As this can potentially cause an infinite diff
// we'll set the default here if we haven't parsed any
if len(calculations) == 0 {
calculations = append(calculations, honeycombio.CalculationSpec{
Op: honeycombio.CalculationOpCount,
})
calculations = []honeycombio.CalculationSpec{{Op: honeycombio.CalculationOpCount}}
}

return calculations, nil
Expand Down Expand Up @@ -390,7 +388,6 @@ func extractFilter(d *schema.ResourceData, index int) (honeycombio.FilterSpec, e
return filter, fmt.Errorf(multipleValuesError)
}
filter.Value = vb
valueSet = true
}

if filter.Op == honeycombio.FilterOpIn || filter.Op == honeycombio.FilterOpNotIn {
Expand Down
3 changes: 2 additions & 1 deletion honeycombio/data_source_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
)
Expand Down Expand Up @@ -161,7 +162,7 @@ func dataSourceHoneycombioRecipientRead(ctx context.Context, d *schema.ResourceD
return diag.Errorf("your recipient query returned no results.")
}
if len(filteredRcpts) > 1 {
return diag.Errorf("your recipient query returned more than one result. Please try a more specific search critera.")
return diag.Errorf("your recipient query returned more than one result. Please try a more specific search criteria.")
}
rcpt := filteredRcpts[0]
d.SetId(rcpt.ID)
Expand Down
4 changes: 2 additions & 2 deletions honeycombio/data_source_recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
},
{
Config: testAccRecipientWithFilterRegex("email", "address", "^acctest*"),
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search critera."),
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search criteria."),
},
{
Config: testAccRecipientWithFilterRegex("pagerduty", "integration_name", "^.*Important Service$"),
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search critera."),
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search criteria."),
},
},
})
Expand Down
1 change: 1 addition & 0 deletions honeycombio/data_source_recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/hashcode"
Expand Down
6 changes: 3 additions & 3 deletions honeycombio/internal/verify/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func SuppressEquivJSONDiffs(_, orig, new string, d *schema.ResourceData) bool {
func SuppressEquivJSONDiffs(_, j1, j2 string, d *schema.ResourceData) bool {
oldBuf := bytes.NewBufferString("")
if err := json.Compact(oldBuf, []byte(orig)); err != nil {
if err := json.Compact(oldBuf, []byte(j1)); err != nil {
return false
}

newBuf := bytes.NewBufferString("")
if err := json.Compact(newBuf, []byte(new)); err != nil {
if err := json.Compact(newBuf, []byte(j2)); err != nil {
return false
}

Expand Down
7 changes: 4 additions & 3 deletions honeycombio/internal/verify/query_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/honeycombio/terraform-provider-honeycombio/client"
)

func SupressEquivQuerySpecDiff(_, orig, new string, _ *schema.ResourceData) bool {
func SupressEquivQuerySpecDiff(_, q1, q2 string, _ *schema.ResourceData) bool {
var qs1, qs2 client.QuerySpec

if err := json.Unmarshal([]byte(orig), &qs1); err != nil {
if err := json.Unmarshal([]byte(q1), &qs1); err != nil {
return false
}
if err := json.Unmarshal([]byte(new), &qs2); err != nil {
if err := json.Unmarshal([]byte(q2), &qs2); err != nil {
return false
}
return qs1.EquivalentTo(qs2)
Expand Down
2 changes: 2 additions & 0 deletions honeycombio/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/log"
)
Expand Down Expand Up @@ -69,6 +70,7 @@ func Provider(version string) *schema.Provider {
apiKey := os.Getenv(honeycombio.DefaultAPIKeyEnv)
if apiKey == "" {
// fall through to legacy env var
//nolint:staticcheck
apiKey = os.Getenv(honeycombio.LegacyAPIKeyEnv)
}
if v, ok := d.GetOk("api_key"); ok {
Expand Down
Loading